Send emails OnFailure through dedicated service

The unit-status-email@.service allows being triggered through multiple services with @.
Note that everything after the @ is passed to the unit-status-email@.service as parameter.
We pass the complete service name OnFailure using %n.
The parameter can then be accessed by %i within the unit-status-email@.service.
Hence, to pass the service name to our email script for processing we use %i within unit-status-email@.service.
This commit is contained in:
Daniel Karzel 2021-02-24 12:12:38 +11:00
commit fbd0eb7548
5 changed files with 11 additions and 5 deletions

View File

@ -1,13 +1,13 @@
[Unit]
Description=Pull and build ASB from source
Wants=pull-and-build-asb.timer
OnFailure=unit-status-email@%n.service
[Service]
Type=oneshot
WorkingDirectory=/var/external/asb/xmr-btc-swap
ExecStartPre=git pull
ExecStart=/home/asb/.cargo/bin/cargo build --release --bin asb
ExecStopPost=/bin/sh -c 'if [ "$$EXIT_STATUS" -ne 0 ]; then /usr/local/bin/systemd-email.sh daniel@coblox.tech %n; fi'
StandardOutput=append:/var/external/asb/run/logs/pull-and-build.log
StandardError=append:/var/external/asb/run/logs/pull-and-build.log
User=asb

View File

@ -1,11 +1,11 @@
[Unit]
Description=Restart ASB service
After=watch-asb-binary-change.path
OnFailure=unit-status-email@%n.service
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart start-asb.service
ExecStopPost=/bin/sh -c 'if [ "$$EXIT_STATUS" -ne 0 ]; then /usr/local/bin/systemd-email.sh daniel@coblox.tech %n; fi'
[Install]
WantedBy=multi-user.target

View File

@ -1,11 +1,11 @@
[Unit]
Description=Run the automated swap backend
After=start-monero-wallet-rpc.service
OnFailure=unit-status-email@%n.service
[Service]
WorkingDirectory=/var/external/asb/xmr-btc-swap
ExecStart=/home/asb/.cargo/bin/cargo run --release --bin asb -- --config /var/external/asb/run/asb-config/config.toml start
ExecStopPost=/bin/sh -c 'if [ "$$EXIT_STATUS" -ne 0 ]; then /usr/local/bin/systemd-email.sh daniel@coblox.tech %n; fi'
StandardOutput=append:/var/external/asb/run/logs/start-asb.log
StandardError=append:/var/external/asb/run/logs/start-asb.log
Restart=on-failure

View File

@ -1,11 +1,11 @@
[Unit]
Description=monero-wallet-rpc for the automated swap backend (asb)
After=network.target
OnFailure=unit-status-email@%n.service
[Service]
ExecStart=/var/external/asb/monero/bin/monero-wallet-rpc --stagenet --daemon-host stagenet.community.xmr.to --rpc-bind-port 38083 --disable-rpc-login --wallet-dir /var/external/asb/monero/data/stagenet/asb-wallets
ExecStartPost=/bin/bash -c "i=1; while [ $i -ne 0 ]; do tail -n1 /var/external/asb/monero/bin/monero-wallet-rpc.log | grep 'Starting wallet RPC server'; i=$?; sleep 5; done"
ExecStopPost=/bin/sh -c 'if [ "$$EXIT_STATUS" -ne 0 ]; then /usr/local/bin/systemd-email.sh daniel@coblox.tech %n; fi'
ExecStartPost=/usr/bin/bash -c "i=1; while [ $i -ne 0 ]; do tail -n1 /var/external/asb/monero/bin/monero-wallet-rpc.log | grep 'Starting wallet RPC server'; i=$?; sleep 5; done"
Restart=always
User=asb
Group=asb

View File

@ -0,0 +1,6 @@
[Unit]
Description=%i email notification
[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c '/usr/local/bin/systemd-email.sh daniel@coblox.tech %i'