Page 1 of 1
cron job to detect "stop" state, restart if needed
Posted: Sat Jul 15, 2017 8:01 pm
by brushpoper
I am trying to figure out how to create a crontab to detect if my zoneminder is in the stop state and if it is to restart it.. I know I will need to investigate to find out why it is suddenly stopping, usually in the middle of the night while I am sleeping..lol
I run a small motel so I need the cameras up as much as possible, especially at night,... I created a bash file that is supposed to check the state and restart ZM, but I do not think it is checking the actual "start" or "stop" state. and then a crontab to run the bash file. Something is not working correctly
I am really new to creating crontabs, or bashfiles so any and all help would be appreciated.
Re: cron job to detect "stop" state, restart if needed
Posted: Sat Jul 15, 2017 8:47 pm
by rockedge
is zoneminder stopping in the night because /dev/shm is 100%? Check on the upper right hand side of the ZM web console for the /dev/shm value. There was a version 1.30.1 I think that had a bug that caused ZM to stop if a camera lost signal, restarted and ZM started a new instance of zmc for the camera, but the original one is still running....this would keep happening until the RAM was all used up and ZM crashed. What do your logs say?
Anyway I wouldn't bother to check if ZM is stopped, just have the cron job restart ZM periodically regardless if it is stopped or not. This method sounds simpler to do.
Re: cron job to detect "stop" state, restart if needed
Posted: Sat Jul 15, 2017 9:07 pm
by brushpoper
thanks.. already started a cron job to restart every 15 min. I will check my logs for multiple instances for the same camera... watching the /dev/shm value, it is usually only around 8-10%
Re: cron job to detect "stop" state, restart if needed
Posted: Sun Jul 16, 2017 2:52 am
by knight-of-ni
systemd has the capability to auto restart any service which has failed.
Just put "restart=always" in your zoneminder service file. Might as well put that line in mysql service as well.
you will need to issue a systemctl daemon-reload command after you make the change.
See the systemd documentation:
https://www.freedesktop.org/software/sy ... rvice.html
Re: cron job to detect "stop" state, restart if needed
Posted: Sun Jul 16, 2017 3:54 am
by brushpoper
i did not think that the stop state in zm was a service??? because in reality isn't zm still running but in a stopped state?
Re: cron job to detect "stop" state, restart if needed
Posted: Sun Jul 16, 2017 12:34 pm
by knight-of-ni
If zoneminder says it is stopped from the web console then the zoneminder service is not running
If zoneminder says it is running (or is in any other state other than stopped) then the zoneminder service is running
Re: cron job to detect "stop" state, restart if needed
Posted: Sun Jul 16, 2017 3:04 pm
by iconnor
systemd restart=always can still fail.
I highly recommend using the very useful program called monit. You can use it to monitor other things easily as well.
Re: cron job to detect "stop" state, restart if needed
Posted: Tue Jul 18, 2017 10:46 am
by hokedigital
is there documentation on Monit
Re: cron job to detect "stop" state, restart if needed
Posted: Fri Jul 21, 2017 12:47 pm
by truxntrax
Hi,
Similar issue here. I have decided that monit is the right way to restart the process...
Can anyone assist with the correct service that I should define in my monit configuration file? I have:
check process zmpkg.pl with pidfile /var/run/zm.pid start program = "/etc/init.d/zoneminder start" stop program = "/etc/init.d/zoneminder stop"
I get the following error:
There is no service named "zmpkg.pl"
I have tried with ZMA, zmc, zoneminder, zm...
Any help very much appreciated!
John
Re: cron job to detect "stop" state, restart if needed
Posted: Fri Jul 21, 2017 1:24 pm
by iconnor
For ubuntu/debian, the following should work
check process zmdc.pl with pidfile /run/zm/zm.pid
if failed unixsocket /run/zm/zmdc.sock then restart
group zm
start program = "/bin/systemctl start zoneminder"
stop program = "/bin/systemctl stop zoneminder"
#if 4 restarts within 20 cycles then timeout
Re: cron job to detect "stop" state, restart if needed
Posted: Fri Jul 21, 2017 1:55 pm
by truxntrax
Hi,
Many thanks for this. You correctly inferred I am using Ubuntu (16.X)- thanks.
I tried the configuration entry as you advised. Unfortunately it didn't work. Again I get the service error:
no service named "zmdc.pl"
Any other thoughts?
Thanks
John
Re: cron job to detect "stop" state, restart if needed
Posted: Fri Jul 21, 2017 5:27 pm
by truxntrax
After a server reboot this is now functioning.
Thanks for your quick and accurate help.
John