Answer the question
In order to leave comments, you need to log in
Unexpected termination of a process started via nohup?
Situation:
There is a web server whose process can spontaneously terminate (error, OutOfMemory, whatever).
In order for the server to rise automatically after a fall, I wrote a special script:
run-loop.sh
while :
do
echo "inifinite loop iteration..."
./start-server.sh
echo "inifinite loop iteration ended, sleeping for some time"
sleep 60
done
nohup ./run-loop.sh > logs/server-out.log &
Answer the question
In order to leave comments, you need to log in
The line about OutOfMemory is a little confusing. Is this just an example, or does it actually happen sometimes? It’s just that on Linux, when it happens, it’s bad, and in order for the system to somehow live, the kernel beats “anyone”, a random process. So, if there is a similar scheme in the fra, maybe for the same reason the shell script itself is killed? In the logs, probably, OOM should be reflected.
But as an option, if the goal is not to figure it out, but simply to solve the problem, as long as it works, you can try without a wrapper. Just run a simple "check-respawn" script by cron, which will check, and if the server is lying (by a lock file, an open port, or even stupidly by ps'u) - run it again. In this case, the script will not die for some unknown reason. Unless cron dies from OOM, but if cron dies, you will already know for sure that the problem is not in the crooked cron code.
You can use monit
Try manually sending a SIGTERM to run-loop.sh, what's the response? In your version, there is a spinner that restarts the process, but there is no control over the work of the spinner itself, well, don’t produce bicycles, everything has been invented a long time ago (see above about monit)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question