UPS POWEROUT event to trigger Zoneminder

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

UPS POWEROUT event to trigger Zoneminder

Post by Sigge »

I have a APCUPS connected to my ZM installation. The apcupsd daemon generates events like powerout and onbattery. The apsupsd then executes custom bash scripts with the same name in a certain folder. I made two script, powerout and mainsback.

Powerout will trigger a recording on all monitors. Mainsback will stop it. How will Zoneminder handle a shutdown when in the middle of an ongoing alarm/recording? Should I add a script that stops Zoneminder at the "failing" event that precedes shutdown when the battery is empty?

Thanks
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: UPS POWEROUT event to trigger Zoneminder

Post by knight-of-ni »

What kind of a shutdown do you mean? A normal or abnormal shutdown?
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: 2880
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: UPS POWEROUT event to trigger Zoneminder

Post by iconnor »

A shutdown event should send sigterm to all processes, which should tell ZM to shutdown fairly nicely. You do need to give it some time to do so though, maybe up to 10 seconds.

If the machine just powers off you will have incomplete event records, incomplete files on disk, disk corruption, db corruption and a general mess.
bbunge
Posts: 2930
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: UPS POWEROUT event to trigger Zoneminder

Post by bbunge »

apcupsd on Ubuntu will do a system shutdown when the battery runs out. I have had this happen several times and had no file or database corruption. Since you are changing the run state of Zoneminder when the UPS goes on battery, when the server restarts the Zoneminder run state will be as it was when Zoneminder shut down. Therefore, you may want to look into a script to run before the battery shuts the server down and set the Zoneminder run state back to your "normal." Include sufficient tome delay in the server shutdown to allow Zoneminder to change run state.
mikb
Posts: 585
Joined: Mon Mar 25, 2013 12:34 pm

Re: UPS POWEROUT event to trigger Zoneminder

Post by mikb »

bbunge wrote: Fri Jul 31, 2020 6:00 pm apcupsd on Ubuntu will do a system shutdown when the battery runs out.
Hopefully before the battery runs out ...

But seriously -- I'm always nervous of the idea of waiting until the UPS decides "that's it, we're on fumes! Time to think about shutting down!" -- because sometimes the delay between hitting "Battery Low" and discovering "There Is No Battery" is too short to compl

:D
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: UPS POWEROUT event to trigger Zoneminder

Post by knight-of-ni »

I typically configure nut to shutdown the pc when the battery reaches the 30-40% range, rather than the default. That way there is not only enough juice to run during the shutdown period, but there is also a little left to shutdown a second time, should the power go on briefly and then back off again.
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: 2880
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: UPS POWEROUT event to trigger Zoneminder

Post by iconnor »

Yeah so many cheap UPS's will not turn on unless there is enough juice in the battery. So when power comes back... your machines don't. Not useful.
mikb
Posts: 585
Joined: Mon Mar 25, 2013 12:34 pm

Re: UPS POWEROUT event to trigger Zoneminder

Post by mikb »

iconnor wrote: Sun Aug 02, 2020 2:48 pm Yeah so many cheap UPS's will not turn on unless there is enough juice in the battery. So when power comes back... your machines don't. Not useful.
It depends what you want to happen (and the consequences of that desire!)

"Not turning on because: Battery dead" is a good feature IMO. A lot of APC ones do that (play dead if the battery is faulty/missing/flat).

You probably don't want to see what happens when power fails, battery runs flat, computer shuts down cleanly (Good!), followed by: power restores, computer starts up, battery doesn't get a chance to charge, power goes back out and UPS drops the computer on its face. (Bad!) -- now you've just had an uncontrolled power loss.

I realize that 100% uptime is necessary in some situations, so this won't apply, but my UPS's/PCs do NOT power on after an outage. If the battery gets to the stage that a shutdown happens, they stay down. Sure, power restoring will charge the battery straight away, which is great. But the PCs are not going back on until I'm there to a) watch them start up and make sure it all works right, and b) put in passwords needed to get it all started.

It is most likely that when the PC comes back up that it will say "<device> has gone <x> days without checking, fsck forced" and that can take quite some time. I don't want the power going back out during that :)
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: UPS POWEROUT event to trigger Zoneminder

Post by Sigge »

Thanks for all the input!

So, it seems like a good idea to issue a zmtrigger |off| at low battery event.

I am still testing and playing around with this. I am considering adding a fail safe |on+3600| at the power loss event. Would that be a problem if a |off| command comes before failsafe 3600?

Also, I noted thar alarm comments/reasons seems to gets applied to unrelated motion detected events coming later. Could be because I am not stopping with a full sentence? "1|off" instead of a full 1|off||| etc...

Also, I have a temperature sensor sending a |show|.....25.0 C to all my monitors. Would the |show| command interfere with the |on| and |off| triggers?

Thanks,
Post Reply