cron job to detect "stop" state, restart if needed

Forum for questions and support relating to the 1.30.x releases only.
Locked
brushpoper
Posts: 4
Joined: Sat Jul 15, 2017 7:53 pm

cron job to detect "stop" state, restart if needed

Post 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.
rockedge
Posts: 1198
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: cron job to detect "stop" state, restart if needed

Post 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.
brushpoper
Posts: 4
Joined: Sat Jul 15, 2017 7:53 pm

Re: cron job to detect "stop" state, restart if needed

Post 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%
User avatar
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

Post 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
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/
brushpoper
Posts: 4
Joined: Sat Jul 15, 2017 7:53 pm

Re: cron job to detect "stop" state, restart if needed

Post 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?
User avatar
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

Post 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
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/
User avatar
iconnor
Posts: 3269
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: cron job to detect "stop" state, restart if needed

Post 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.
hokedigital
Posts: 5
Joined: Tue Jul 18, 2017 12:16 am

Re: cron job to detect "stop" state, restart if needed

Post by hokedigital »

is there documentation on Monit
truxntrax
Posts: 3
Joined: Fri Jul 21, 2017 12:39 pm

Re: cron job to detect "stop" state, restart if needed

Post 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
User avatar
iconnor
Posts: 3269
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: cron job to detect "stop" state, restart if needed

Post 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
truxntrax
Posts: 3
Joined: Fri Jul 21, 2017 12:39 pm

Re: cron job to detect "stop" state, restart if needed

Post 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
truxntrax
Posts: 3
Joined: Fri Jul 21, 2017 12:39 pm

Re: cron job to detect "stop" state, restart if needed

Post by truxntrax »

After a server reboot this is now functioning.

Thanks for your quick and accurate help.

John
Locked