From 384e64009e1ff101df5c3a451e24ebe49ff99dc7 Mon Sep 17 00:00:00 2001 From: liquidev Date: Fri, 23 Aug 2024 22:37:49 +0200 Subject: [PATCH] add admin scripts over from treehouse would be nice to rewrite these as a standalone utility that integrates with Nix someday i guess --- admin/README.md | 12 ++++++++++++ admin/daemon.bash | 28 ++++++++++++++++++++++++++++ admin/daemon/common.bash | 4 ++++ admin/daemon/deploy.bash | 11 +++++++++++ admin/daemon/reload.bash | 6 ++++++ admin/deploy.bash | 3 +++ 6 files changed, 64 insertions(+) create mode 100644 admin/README.md create mode 100755 admin/daemon.bash create mode 100644 admin/daemon/common.bash create mode 100644 admin/daemon/deploy.bash create mode 100644 admin/daemon/reload.bash create mode 100755 admin/deploy.bash diff --git a/admin/README.md b/admin/README.md new file mode 100644 index 0000000..93b23a4 --- /dev/null +++ b/admin/README.md @@ -0,0 +1,12 @@ +# `admin` + +Bunch of scripts I use to administrate the rkgk instance at . +The full setup is: + +- A systemd service runs `daemon.bash` in a separate user. + - This script builds and runs the server. + - It also listens for `reload` commands being sent through a FIFO, which can be used to make the server rebuild and rerun. +- The `reload` command is sent by the `deploy.bash` script which runs on my own machine rather than the server. + - This script causes a `git pull` and a `reload` command to be run. + +This is more or less the same setup as . diff --git a/admin/daemon.bash b/admin/daemon.bash new file mode 100755 index 0000000..a5ceb59 --- /dev/null +++ b/admin/daemon.bash @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +source "${BASH_SOURCE%/*}/daemon/common.bash" + +echo "PATH: $PATH" + +trap 'trap - SIGTERM && kill 0' SIGTERM SIGINT EXIT + +rm -f $reload_fifo +mkfifo $reload_fifo + +reload() { + # This just kind of assumes recompilation doesn't take too long. + kill "$rkgk_pid" + cargo run --release -- serve --port 8083 > "$build_log" 2>&1 & + rkgk_pid="$!" +} + +reload + +while true; do + read command < "$reload_fifo" + case "$command" in + reload) + echo "Reloading" + reload;; + esac +done diff --git a/admin/daemon/common.bash b/admin/daemon/common.bash new file mode 100644 index 0000000..c96781b --- /dev/null +++ b/admin/daemon/common.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +reload_fifo="/tmp/rkgk_reload.fifo" +build_log="/tmp/rkgk_build.log" diff --git a/admin/daemon/deploy.bash b/admin/daemon/deploy.bash new file mode 100644 index 0000000..fee15c0 --- /dev/null +++ b/admin/daemon/deploy.bash @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +cd ~/repo + +source "${BASH_SOURCE%/*}/common.bash" + +git pull +bash "${BASH_SOURCE%/*}/reload.bash" + +echo "^C to exit build log ($build_log)" +tail --retry -f "$build_log" diff --git a/admin/daemon/reload.bash b/admin/daemon/reload.bash new file mode 100644 index 0000000..958a518 --- /dev/null +++ b/admin/daemon/reload.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +source "${BASH_SOURCE%/*}/common.bash" + +echo "Reloading" +echo "reload" > "$reload_fifo" diff --git a/admin/deploy.bash b/admin/deploy.bash new file mode 100755 index 0000000..fdb68c4 --- /dev/null +++ b/admin/deploy.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ssh "$RKGK_SERVER" -p "$RKGK_SERVER_PORT" "bash" "~/repo/admin/daemon/deploy.bash"