diff --git a/Makefile b/Makefile index a81a717..138ace1 100644 --- a/Makefile +++ b/Makefile @@ -44,10 +44,12 @@ install: install -o root -g root tellusagent $(PREFIX) install -o root -g root tellusagent.sh $(PREFIX) install -o root -g root tellusagent.conf $(PREFIX) + install -D -d $(DESTDIR)/lib/systemd/system/ ifeq ($(OS), Linux) -# install -o root -g root tellusagent-init $(PREFIX) -# install -m 644 -o root -g root tellusagent-monit $(PREFIX) -# install -m 644 -o root -g root tellusagent.service $(PREFIX) + install -o root -g root systemd/tellusagent.service $(DESTDIR)/lib/systemd/system/ + install -o root -g root systemd/tellusagent\@.service $(DESTDIR)/lib/systemd/system/ + install -D -d $(DESTDIR)/lib/systemd/system-generators/ + install -o root -g root systemd/tellusagent-generator $(DESTDIR)/lib/systemd/system-generators/ endif ifeq ($(OS), Darwin) # install -m 644 -o root -g root tellusagent.plist $(DESTDIR)/Library/LaunchDaemons diff --git a/systemd/tellusagent-generator b/systemd/tellusagent-generator new file mode 100644 index 0000000..bd38620 --- /dev/null +++ b/systemd/tellusagent-generator @@ -0,0 +1,22 @@ +#!/bin/sh + +# This systemd generator creates dependency symlinks that make all OpenVPN +# tunnels listed in /etc/default/openvpn's AUTOSTART be started/stopped/reloaded +# when openvpn.service is started/stopped/reloaded. + +set -eu + +GENDIR="$1" +WANTDIR="$1/tellusagent.service.wants" +SERVICEFILE="/lib/systemd/system/tellusagent@.service" +CONFIG_DIR=/opt/TellusAgent/ + +mkdir -p "$WANTDIR" + +for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do + NAME=${CONFIG%%.conf} + ln -s "$SERVICEFILE" "$WANTDIR/tellusagent@$NAME.service" +done + +exit 0 + diff --git a/systemd/tellusagent.service b/systemd/tellusagent.service new file mode 100644 index 0000000..9c3ae25 --- /dev/null +++ b/systemd/tellusagent.service @@ -0,0 +1,16 @@ +# This service is actually a systemd target, +# but we are using a service since targets cannot be reloaded. + +[Unit] +Description=TellusAgent service +After=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/true +ExecReload=/bin/true +WorkingDirectory=/opt/TellusAgent/ + +[Install] +WantedBy=multi-user.target diff --git a/systemd/tellusagent@.service b/systemd/tellusagent@.service new file mode 100644 index 0000000..2810e4e --- /dev/null +++ b/systemd/tellusagent@.service @@ -0,0 +1,14 @@ +[Unit] +Description=TellusAgent for %i +PartOf=tellusagent.service +ReloadPropagatedFrom=tellusagent.service + +[Service] +Type=forking +EnvironmentFile=/opt/TellusAgent/%i.conf +ExecStart=/opt/TellusAgent/tellusagent --connect-port ${CONNECT_PORT} --control-port ${CONTROL_PORT} --media-port ${MEDIA_PORT} --server-address ${SERVER_ADDRESS} --service-mode ${SERVICE_MODE} +ExecReload=/bin/kill -HUP $MAINPID +WorkingDirectory=/opt/TellusAgent/ + +[Install] +WantedBy=multi-user.target