need to restart if the service is down
Hello friends.....
I have a application using node.js, port number is 3001 and 3007, some time application going to down,in this time
lsof -i:3001 result is blank becouse service is not running ,so
i have go to application folder and run this command - nohup node test_app.js & .
So i create a bash script that will be check port or application working or not if down will run starting command, and added in crontab with run every minute, but its not working correctly ,
#!/bin/bash
#service=node
if (( $(lsof -i:3007 | wc -l) > 0 ))
then
nohup node test_app.js &
else
echo "$service is running!!!"
fi
Please advice me how can i do this, is this possible any other way like install monitoring tool, i search some monitoring tooles like monits but its very confusing me, so plz help, plz share your experience .
-
You can get better insight here [url=http://superuser.com/questions/683325/linux-to-monitor-a-service-and-restart-if-stopped]shell - Linux : To monitor a Service and restart if stopped? - Super User 0 -
]You can get better insight here [url=http://superuser.com/questions/683325/linux-to-monitor-a-service-and-restart-if-stopped]shell - Linux : To monitor a Service and restart if stopped? - Super User
Thanks for reply , I just try this command as per following site #!/bin/bash #service monitoring /bin/netstat -tulpn | awk '{print $4}' | awk -F: '{print $4}' | grep ^3007$ > /dev/null 2>/dev/null a=$(echo $?) if test $a -ne 0 then echo "node.js service down" nohup node test_app.js & > /dev/null 2>/dev/null else sleep 0 fi so its correctly start application and give a massage that is " node.js service down ", so now application is running, then again i run the script so the same massage replicating, its means application runing or down script working same . so can we use same script for if the application is running we no need to get any massage and no need to run nohup node test_app.js &. (restarting command). Plz advice me..0 -
]so now application is running, then again i run the script so the same massage replicating , its means application runing or down script working same .
Hello :) Could you elaborate further on this statement? For instance, is the application running successfully or is it still failing? Thank you.0 -
]Hello :) Could you elaborate further on this statement? For instance, is the application running successfully or is it still failing? Thank you.
If the application running or down the script output getting same, like if the node.js application running and we are try to run the script, so that time script output should be " its working fine " . no need to try restart or start again, but its application running or down the script try to start or restart application.0 -
You may want to consult with a developer or system administrator to assist you with your custom script if it's not accurately detecting if the service is running. Thank you. 0 -
]You may want to consult with a developer or system administrator to assist you with your custom script if it's not accurately detecting if the service is running. Thank you.
Michael, This is normal web site, am using bash script for start a service if it down, that service port 3007, but my bash script every time given same result, even service is working bash script will try to restart, that is my problem. also i noted last day i upgrade whm, after this user all crones not working, then i restart crone service and copy all crone jobs from user to root, but i think particular crone not working . 00 3 * * * /bin/sh /path/mysql_backup.sh 00 7 * * * /bin/sh /path/rtm.sh 05 7 * * * /bin/sh /path/rtm2.sh 02 * * * * /bin/sh /path/test.sh If any one have any idea about this plz help me .0
Please sign in to leave a comment.
Comments
6 comments