diff --git a/docs/setup/asb/README.md b/docs/setup/asb/README.md new file mode 100644 index 00000000..43ce1ac7 --- /dev/null +++ b/docs/setup/asb/README.md @@ -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 +``` diff --git a/docs/setup/asb/systemd/pull-and-build-asb.service b/docs/setup/asb/systemd/pull-and-build-asb.service new file mode 100644 index 00000000..86ba605a --- /dev/null +++ b/docs/setup/asb/systemd/pull-and-build-asb.service @@ -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 diff --git a/docs/setup/asb/systemd/pull-and-build-asb.timer b/docs/setup/asb/systemd/pull-and-build-asb.timer new file mode 100644 index 00000000..c9b67eca --- /dev/null +++ b/docs/setup/asb/systemd/pull-and-build-asb.timer @@ -0,0 +1,10 @@ +[Unit] +Description=triggers the service that pulls and builds asb +Requires=pull-and-build-asb.service + +[Timer] +OnCalendar=*-*-* 16:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/docs/setup/asb/systemd/restart-asb.service b/docs/setup/asb/systemd/restart-asb.service new file mode 100644 index 00000000..95f93d9d --- /dev/null +++ b/docs/setup/asb/systemd/restart-asb.service @@ -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 diff --git a/docs/setup/asb/systemd/start-asb.service b/docs/setup/asb/systemd/start-asb.service new file mode 100644 index 00000000..e43c3396 --- /dev/null +++ b/docs/setup/asb/systemd/start-asb.service @@ -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 diff --git a/docs/setup/asb/systemd/start-monero-wallet-rpc.service b/docs/setup/asb/systemd/start-monero-wallet-rpc.service new file mode 100644 index 00000000..d78e732a --- /dev/null +++ b/docs/setup/asb/systemd/start-monero-wallet-rpc.service @@ -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 diff --git a/docs/setup/asb/systemd/watch-asb-binary-change.path b/docs/setup/asb/systemd/watch-asb-binary-change.path new file mode 100644 index 00000000..c159ba60 --- /dev/null +++ b/docs/setup/asb/systemd/watch-asb-binary-change.path @@ -0,0 +1,6 @@ +[Path] +Unit=restart-asb.service +PathChanged=/var/external/asb/xmr-btc-swap/target/release/asb + +[Install] +WantedBy=multi-user.target