cron job to detect "stop" state, restart if needed
-
- Posts: 4
- Joined: Sat Jul 15, 2017 7:53 pm
cron job to detect "stop" state, restart if needed
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.
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
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.
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.
-
- Posts: 4
- Joined: Sat Jul 15, 2017 7:53 pm
Re: cron job to detect "stop" state, restart if needed
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%
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: cron job to detect "stop" state, restart if needed
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
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
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
-
- Posts: 4
- Joined: Sat Jul 15, 2017 7:53 pm
Re: cron job to detect "stop" state, restart if needed
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?
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: cron job to detect "stop" state, restart if needed
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
If zoneminder says it is running (or is in any other state other than stopped) then the zoneminder service is running
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: cron job to detect "stop" state, restart if needed
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.
I highly recommend using the very useful program called monit. You can use it to monitor other things easily as well.
-
- Posts: 5
- Joined: Tue Jul 18, 2017 12:16 am
Re: cron job to detect "stop" state, restart if needed
is there documentation on Monit
Re: cron job to detect "stop" state, restart if needed
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
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
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
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
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
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
After a server reboot this is now functioning.
Thanks for your quick and accurate help.
John
Thanks for your quick and accurate help.
John