0
#!/bin/bash
PID=$(pidof daemon)
kill $PID
while ps -e | grep "[d]aemon" >> /dev/null; 
do
sleep 30
done
sh -c /root/daemon

This script is set on a cronjob to kill and restart this program. It does that but then after the script should exit, it keeps respawning, making it very difficult to keep the daemon manually. It should restart the program in a subshell and the script should die.

italiano40
  • 103
  • 3

2 Answers2

1

I think the issue is in your cron

* 3,7,10,14,18,23 * * * /root/restartdaemon.sh

The first * is minutes which means run the script at 3:00 then again at 3:01, 3:02 and so on

Try

0 3,7,10,14,18,23 * * * /root/restartdaemon.sh

That will run it at 3:00 then again at 7:00 and so on.

Mike
  • 22,310
  • 7
  • 56
  • 79
  • I am using webmin to create the cronjob, could their be an issue with webmin? Cause if their is I would like to report it to them. – italiano40 Sep 02 '14 at 02:34
  • If you post a screenshot of the cron screen i can maybe figure it out – Mike Sep 02 '14 at 02:36
0

Okay, I think the real problem is that when you execute "sh -c /root/daemon" your script won't return until that command returns.

If you really are trying to launch /root/daemon and then have your restartdaemon.sh script return, you should do something like:

sh -c /root/daemon &

That way your restart script will immediately return, rather than waiting for the /root/daemon command to return.

Of course, that would imply that when your next cron job killed the daemon, it should "return" and then your script would exit, so it doesn't explain why you have thousands still running in memory, but at least this is a start :)

Jon Marnock
  • 264
  • 4
  • 12
  • I am going to try that as well. This is what I am getting right now... 14043 root 00:00 CRON 14045 root 00:00 /bin/sh -c /root/restart.sh 14048 root 00:00 /bin/bash /root/restart.sh 14127 root 00:05 sh -c /root/daemon 14128 root 00:05 /root/daemon – italiano40 Sep 02 '14 at 04:09