Page 1 of 1

Auto restart cron job?

Posted: Wed May 05, 2021 7:04 am
by Drink
Hey LL,

Great that others can restart it now.
Poor lazy being bugged all the time on discord ;p

Could this now be done with a server side check tho?
Make it check every say 5 or 10minutes.

Code: Select all

#Process Name
process = 'server'

#Check running process/daemons
if ps ax | grep -v grep | grep $process
then
    echo "$process Health check OK!"
else
    echo "$process not found, restarting..."
/usr/local/bin/v2server/server  #launch command or link to script to do the tasks the cgi does

fi

Posted: Wed May 05, 2021 3:12 pm
by Lordlava
Curious and a great idea.

Two potential problems I see with an auto restart.

1) If I deliberately bring the game down for any reason (e.g. doing a data conversion etc...) I would need to remember to turn off this feature.

2) If the server crashes then the auto restart will not work. If needs to be a "foo" restart which writes to the terminal. In theory I have changed the server code to write to both the terminal and the log but it is not 100% reliable (not sure if this is an Apache only issue of something more fundamental as I have not really investigated the alternatives).

There is so much about Linux I have forgotten, or maybe never really knew.
I would need to look up how to do a 5 minute check.
Also I would need to somehow notify me that a crash and restart occurred.


What do you think?

Posted: Wed May 05, 2021 7:28 pm
by Drink
https://ostechnix.com/a-beginners-guide-to-cron-jobs

They have a builder tool to make it super ez.
Can have it run on restart too.
*/5 * * * * <command> <<5 minute check.
@restart <command> <<If server crashes/restarts it will run on reboot.

#1 is valid :P it would keep bring it up lol

#2 can make it run any command in the job.

Depending on how u get notified atm, could include in the script to send an email or log fails to a file.
few diff tools u can install on linux box's
ssmtp lets u put it in the script, so if it hits the else it would run something like

sendmail Lordlava@gmail.com < Emailmessage.txt