Files
motion/motion.service.in
Tim Small 9db8e03b03 systemd unit file enhancements and cleanup (#907)
* Remove unused PIDFile setting

Since the default config doesn't create a PID file, and they're not
needed for systemd unit files which aren't forking (this unit file
runs motion as a 'simple' service), this setting can be removed in the
default config.

* Add comment about the systemd unit file, including license info.

* Expand description, add man page reference.

* systemd: read /etc/default/motion for compatibility with init script.

Allow the user to specify environment variables to be inherited by
motion when started via native systemd service.  Noop if file does not
exist.  Useful to pass env files to scripts etc. which are called by
motion (e.g. with on_event_start etc.).

* Comment discarding of stderr.

* Add reload functionality to systemd unit file.

* Add restart behaviour to systemd unit file.

* Set motion to run as user "motion" for consistency with init scripts

* Honor start_motion_daemon setting in /etc/default/motion

For existing installations which have disabled auto-start of the daemon
by setting start_motion_daemon != yes in /etc/default/motion, check this
variable as a prerequisite for systemd to start motion.

* systemd: Document some security related options, don't enable by default.
2019-08-11 20:48:54 -06:00

70 lines
2.6 KiB
SYSTEMD

#
# This systemd unit file is part of the motion project:
#
# https://motion-project.github.io/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
#
[Unit]
Description=Motion - monitor live video, trigger responses, record video/stills.
Documentation=man:motion(1)
After=local-fs.target network.target
[Service]
User=motion
EnvironmentFile=-/etc/default/motion
# The the sleep on the following line is needed with systemd version
# 232, otherwise the error message that we echo doesn't hit 'systemctl
# status'.
ExecStart=/bin/sh -c '([ -r "/etc/default/motion" ] && [ "x$start_motion_daemon" != "xyes" ]) && echo "Not starting motion because start_motion_daemon=$start_motion_daemon - check /etc/default/motion" && sleep 1 && exit 78 ; exec @BIN_PATH@/motion -n'
Type=simple
# Set StandardError=journal to use journald to log messages from motion.
# See also the "log_file" config file option in motion(1) and
# systemd.service(5).
StandardError=null
ExecReload=@KILL@ -HUP $MAINPID
Restart=on-failure
RestartSec=5
# Don't restart if unconfigured / misconfigured e.g. daemon disabled
# in defaults file. See also /usr/include/sysexits.h or sysexits(3)
RestartPreventExitStatus=78
# To tune restart behaviour, see systemd.unit(5) and use
# "systemctl edit motion" to change the following settings:
#StartLimitBurst=
#StartLimitIntervalSec=
#StartLimitAction=
#FailureAction=
# The following can be used to increase the security of the
# installation, by mitigating risk from attacks on motion and the
# binaries, libraries and scripts which it relies on. They are disabled
# by default in case they break existing installations, e.g. those which
# call site-local scripts which would inherit the same restrictions.
#
# See systemd.exec(5) and
# http://0pointer.net/public/systemd-nluug-2014.pdf for more details
# of these and other related options.
#
# Use "systemctl edit motion" to change these settings.
#PrivateTmp=true
#NoNewPrivileges=yes
#PrivateNetwork=yes
#ProtectHome=yes
#DeviceAllow=/dev/video0
#MountFlags=slave
#SystemCallFilter=
[Install]
WantedBy=multi-user.target