ZoneMinder/ZoneMinder — pull request #474 by knnniggett (2014-07-12 19:38:30+00:00)
Title: initial support for systemd

*** DO NOT MERGE (yet) ***

DESCRIPTION
systemd replaces traditional init. It is currently in use on Fedora, OpenSUSE, and Mageia. It has just been implemented in the newly release CentOS 7, and as of February, Debian has announced they will be replacing upstart with systemd, which means that Ubuntu will follow. Since it seems nearly all distros are moving to systemd, we should make sure zoneminder integrates well with it.

PROBLEM
One of the "features" of systemd is that it tracks, internally, the PID of the service at the time the service was started. Consequently, if the administrator restarts the service in question using something other than the systemctl tool, then systemd becomes out of sync with the service, and one runs into issues where the service is reported as failed when, in fact, it is running fine (or vice versa). In the case of zoneminder, this problem occurs when zoneminder is stopped or restarted from the web console.

SOLUTION
I have attempted to solve this by adding a wrapper script and a polkit policy file. Instead of calling zmpkg.pl directly, the web console will call zmsystemctl.pl, which in turn calls systemctl to stop/start/restart the service. A polkit policy is required during this process to elevate the webuser account permissions.

TO-DO
This pull request is not quite finished, but the basics are there.

Specifically, here is what still needs to be done:
- Update all packing scripts under the distros folder to include the new files
- polkit policy files are under /misc. Modify autotools & cmake to place the action file into /usr/share/polkit-1/actions and the rule into /usr/share/polkit-1/rules.d
- webuser is hardcoded as apache. Change this to @WEB_USER@
- systemd unit files are currently under each distro. Need to create a generic one and place it under /misc.

Let me know if anyone knows of a better way to implement this.