I have this following script running in my centos 7 server. its job is to run for-ever and check if xxx.js is alive, if crashed or killed, it has to restart it.
but since 3 days its failing to start my xxx.js unless i manually login to the server and apply $ ./myloop.sh &
root 23413 0.1 0.1 113252 1640 ? S Nov11 0:59 /bin/bash ./myloop.sh
Can anyone please check what is the BUG causing it to unable to execute the xxx.js when its not running / crashed?
#!/bin/bash
while :
do
# 1
xxx=$(pgrep -f "xxx.js")
if [[ "$xxx" ]]; then
log1="1 - running xxx.js $1 $2"
else
log1="1 - re-launch xxx.js $1 $2"
ps aux | grep "xxx.js" | awk '{print $2}' | xargs kill
sleep 1
nohup node /var/www/html/sip-phone/xx/xxx.js &
fi
tt=$(date +"%Y-%m-%d %T")
echo "$tt" "$log1"
sleep 2
done