New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Restarting a script after some time without output
Hello,
I have a piece of software that's on life-support waiting to be replaced by another one I'm finishing writing. I'm experiencing random hangups, where the software will just stop and not do anything, until i ^C it and restart.
Is there a software, or bash script, or whatever, to kill and restart process after x minutes have elapsed with no output?
Comments
If the script crashes perhaps you can use ps as a quick hack:
Put scriptcheck.sh on a cron. Inside restartproc.sh write the logic to (re)start your script.
Hanging != crashing
The script is in execution, but just idling. Waiting forever
Yep... I was just thinking about that. What type of output should the script produce, text, DB etc.?
You could redirect the output of your program to a file, and then write a separate script that would check the size of that file, say every 5 minutes (from crontab), to kill and restart the program if the size didn't change since last time.
I'm wondering if
supervisord
might be useful here - if suitable for the purpose and not overkillhttp://supervisord.org/events.html#event-listeners-and-event-notifications
Right now it just produces useless log for troubleshooting. No need to store anything, just to check that is keeps producing it.
this (linux bash) code snippet may be useful - modified from a stackoverflow answer
In addition to the solution proposed by @uptime you can also check Monit.
https://mmonit.com/monit/documentation/monit.html#Process
Just output something to a tmp file. with second script monitor that file and if it is older than X than consider your main script hasn't spit any output. Something like that:
dog.sh
watchdog.sh
Now CRON that mofo:
This is abstract, but you get it.