Systemd service files and readme

This commit is contained in:
Daniel Karzel 2021-02-22 20:21:52 +11:00
parent 61a8282be1
commit 915026eb4d
7 changed files with 100 additions and 0 deletions

25
docs/setup/asb/README.md Normal file
View File

@ -0,0 +1,25 @@
# Setting up the ASB
Setup guidelines for the automated swap backend.
## systemd services
We configure two pathes for starting the asb through systemd.
Upon system startup we first start the monero wallet RPC and then start the asb using two services:
```
start-monero-wallet-rpc.service
|-> start-asb.service
```
We trigger re-building the asb from source every 24 hours through the `pull-and-build-asb` timer and service.
The watcher-service `watch-asb-binary-change.path ` monitors the asb binary changing, and if changed triggers `restart-asb.service` that will restart `start-asb.service`:
```
pull-and-build-asb.timer
|-> pull-and-build-asb.service
|-> watch-asb-binary-change.path
|-> restart-asb.service
|-> start-asb.service
```

View File

@ -0,0 +1,18 @@
[Unit]
Description=Pull and build ASB from source
After=start-asb.service
Wants=pull-and-build-asb.timer
[Service]
Type=oneshot
WorkingDirectory=/var/external/asb/xmr-btc-swap
ExecStartPre=git pull
ExecStart=/home/asb/.cargo/bin/cargo build --release --bin asb
ExecStopPost=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/log_pull-build_stdout.log
StandardError=append:/var/external/asb/run/logs/log_pull-build_stderr.log
User=asb
Group=asb
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,10 @@
[Unit]
Description=Logs some system statistics to the systemd journal
Requires=pull-and-build-asb.service
[Timer]
OnCalendar=*-*-* 16:00:00
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,11 @@
[Unit]
Description=Restart ASB service
After=watch-asb-binary-change.path
[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

@ -0,0 +1,16 @@
[Unit]
Description=Run the automated swap backend
After=start-monero-wallet-rpc.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/log_stdout.log
StandardError=append:/var/external/asb/run/logs/log_stderr.log
Restart=on-failure
User=asb
Group=asb
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,14 @@
[Unit]
Description=monero-wallet-rpc for the automated swap backend (asb)
After=network.target
[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'
Restart=always
User=asb
Group=asb
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,6 @@
[Path]
Unit=restart-asb.service
PathChanged=/var/external/asb/xmr-btc-swap/target/release/asb
[Install]
WantedBy=multi-user.target