From 0191ce9f70c5eeb5f2f92b61441867832c3c87a6 Mon Sep 17 00:00:00 2001 From: lqdev Date: Sat, 3 Feb 2024 20:03:58 +0100 Subject: [PATCH] rework server-side daemon to be reloadable via ssh --- admin/client_edit.bash | 9 --------- admin/client_push.bash | 19 ------------------- admin/client_sync.bash | 3 --- admin/daemon.bash | 27 +++++++++++++++++++++++++++ admin/daemon/common.bash | 3 +++ admin/daemon/reload.bash | 5 +++++ admin/deploy.bash | 3 +++ admin/server_sync.fish | 8 -------- 8 files changed, 38 insertions(+), 39 deletions(-) delete mode 100644 admin/client_edit.bash delete mode 100644 admin/client_push.bash delete mode 100644 admin/client_sync.bash create mode 100644 admin/daemon.bash create mode 100644 admin/daemon/common.bash create mode 100644 admin/daemon/reload.bash create mode 100644 admin/deploy.bash delete mode 100644 admin/server_sync.fish diff --git a/admin/client_edit.bash b/admin/client_edit.bash deleted file mode 100644 index b54836d..0000000 --- a/admin/client_edit.bash +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -cd "$TREEHOUSE_PATH" - -echo -echo "* Running editor" -"$EDITOR" content/index.tree - -bash admin/client_push.bash diff --git a/admin/client_push.bash b/admin/client_push.bash deleted file mode 100644 index 3a84f60..0000000 --- a/admin/client_push.bash +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -cd "$TREEHOUSE_PATH" - -echo -echo "* Fixing the tree" -cargo run -p treehouse fix-all --apply - -echo -echo "* Committing changes" -git add \ - content static template \ - treehouse.toml -git commit -git push - -echo -echo "* Uploading to server" -bash admin/client_sync.bash diff --git a/admin/client_sync.bash b/admin/client_sync.bash deleted file mode 100644 index c7abb93..0000000 --- a/admin/client_sync.bash +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -ssh "$TREEHOUSE_SERVER" -p "$TREEHOUSE_SERVER_PORT" 'fish' '$TREEHOUSE_PATH/admin/server_sync.fish' diff --git a/admin/daemon.bash b/admin/daemon.bash new file mode 100644 index 0000000..7bb987e --- /dev/null +++ b/admin/daemon.bash @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +source "${BASH_SOURCE%/*}/daemon/common.bash" +build_log="/tmp/treehouse_build.log" + +trap 'kill 0' EXIT + +rm -f $reload_fifo +mkfifo $reload_fifo + +reload() { + # This just kind of assumes regeneration doesn't take too long. + kill "$treehouse_pid" + cargo run --release -- serve --port 8082 > "$build_log" & + treehouse_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..3580e68 --- /dev/null +++ b/admin/daemon/common.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +reload_fifo="/tmp/treehouse_reload.fifo" diff --git a/admin/daemon/reload.bash b/admin/daemon/reload.bash new file mode 100644 index 0000000..d89f142 --- /dev/null +++ b/admin/daemon/reload.bash @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +source "${BASH_SOURCE%/*}/common.bash" + +echo "reload" > "$reload_fifo" diff --git a/admin/deploy.bash b/admin/deploy.bash new file mode 100644 index 0000000..2b47194 --- /dev/null +++ b/admin/deploy.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ssh "$TREEHOUSE_SERVER" -p "$TREEHOUSE_SERVER_PORT" "bash" "~/repo/admin/daemon/reload.bash" diff --git a/admin/server_sync.fish b/admin/server_sync.fish deleted file mode 100644 index ca825e5..0000000 --- a/admin/server_sync.fish +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env fish - -# This script runs on the server. - -cd $TREEHOUSE_PATH - -git pull -cargo run --release -p treehouse generate