From c54aa25f3460e0d08ac4f66621e639a2b46ccc6d Mon Sep 17 00:00:00 2001 From: Michel Jonathan Schmitz Date: Tue, 3 Nov 2020 12:53:37 +0100 Subject: [PATCH] feat: add systemd service examples --- config/RECIPIENTS | 1 + systemd/stapps-proxy.service | 23 +++++++++++++++++++++++ systemd/stapps-unit-status-mail.sh | 22 ++++++++++++++++++++++ systemd/stapps-unit-status-mail@.service | 7 +++++++ 4 files changed, 53 insertions(+) create mode 100644 config/RECIPIENTS create mode 100644 systemd/stapps-proxy.service create mode 100755 systemd/stapps-unit-status-mail.sh create mode 100644 systemd/stapps-unit-status-mail@.service diff --git a/config/RECIPIENTS b/config/RECIPIENTS new file mode 100644 index 00000000..e680ab4c --- /dev/null +++ b/config/RECIPIENTS @@ -0,0 +1 @@ +your.mail@address.heres \ No newline at end of file diff --git a/systemd/stapps-proxy.service b/systemd/stapps-proxy.service new file mode 100644 index 00000000..36d0b008 --- /dev/null +++ b/systemd/stapps-proxy.service @@ -0,0 +1,23 @@ +[Unit] +Description=@openstapps/proxy +Documentation=https://gitlab.com/openstapps/proxy +After=network-online.target +Requires=network-online.target +OnFailure=stapps-unit-status-mail@%n.service + +[Service] +ExecStart=/usr/bin/env docker run --rm --net="host" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /opt/stapps-compose/proxy/ssl/chain.crt:/etc/nginx/certs/ssl.crt \ + -v /opt/stapps-compose/proxy/ssl/private.key:/etc/nginx/certs/ssl.key \ + -v /opt/stapps-compose/proxy/static:/static \ + registry.gitlab.com/openstapps/proxy/master +StartLimitBurst=2 +StartLimitIntervalSec=100s +Restart=always +RestartSec=20s +WorkingDirectory=/opt/stapps-compose/proxy +User=root + +[Install] +WantedBy=multi-user.target diff --git a/systemd/stapps-unit-status-mail.sh b/systemd/stapps-unit-status-mail.sh new file mode 100755 index 00000000..645f4390 --- /dev/null +++ b/systemd/stapps-unit-status-mail.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +MAILTO=`cat ../config/RECIPIENTS` +UNIT=$1 + +EXTRA="" +for e in "${@:2}"; do + EXTRA+="$e"$'\n' +done + +UNITSTATUS=$(systemctl status --lines=50 $UNIT) + +ssmtp $MAILTO <