0

First of all. I don't know anything about bash scripting. second this is a very big problem on my side, and I don't have any idea what to do.

Currently, I have this website. which was written in php. and uses mail server and push notification which are all runned as daemon using supervisord. My site is running well but from time to time, my mail server and push notification doens't work because the supervisord stopped working; I had to restart it manually to make it working again.

I was thinking, what could I do to have it auto start. then an idea popped up. to restart the service via bash script and cron jobs. I know it was kinda dumb.

I created a bash script . just a simple one.

#!/bin/bash
# A simple script 
echo " -- Restarting Supervisord --"
sudo service supervisor stop
sudo service supervisor start
echo "Done!" 

when I run this manually via

./supervisord_restart.sh 

this was the output I've got

 -- Restarting Supervisord --
Job for supervisor.service failed. See "systemctl status supervisor.service" and "journalctl -xe" for details.
Done!

allso I don't konw if this is right in cronjob

0   0,12    *   *   *   /supervisord_restart.sh

by the way if I am doing right. I need my bash script to check if suprevisord is running then execute the commands.

  • My suggestion is that you should familiarise yourself with the components in question (cron, bash scripting) and their implementation, then re-attempt this - or better yet, have someone qualified to do so perform this task for you if at all possible. – BE77Y Jun 11 '15 at 9:35
  • yah. you're are right. I guess. I just manually monitor this for now, and search more if this is possible – user293637 Jun 11 '15 at 9:38
2

First of all: you should investigate the "real" problem with supervisord instead of restarting the service every night.

That being said, try to use /etc/init.d/supervisor stop / start or restart. Many times cron has problems using service. You also have to create the cron as the user supervisord runs on, or as root via sudo crontab -e. Also always use complete paths in cron, so not /supervisord_restart.sh but /usr/local/bin/supervisord_restart.sh or similar.

(And: what Linux distro are you running)

2

Assuming your service has a status command, you can do something as simple as in the cron job:

0 0,12 * * * service whatever status >/dev/null || service whatever restart

That way, you first run the status check, discard verbose output, and then verify that exit code is not 0 (which would be good), in which case - restart.

Indeed, with a lightweight check like that, you can run the cron job more often.

If you get 'command not found' errors from the cron job, it may not be in the default PATH, so prepend the calls with /usr/sbin/ or /sbin/ or wherever it is on your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.