rework server-side daemon to be reloadable via ssh

This commit is contained in:
liquidex 2024-02-03 20:03:58 +01:00
parent 5f86f4cee7
commit 0191ce9f70
8 changed files with 38 additions and 39 deletions

View file

@ -1,9 +0,0 @@
#!/usr/bin/env bash
cd "$TREEHOUSE_PATH"
echo
echo "* Running editor"
"$EDITOR" content/index.tree
bash admin/client_push.bash

View file

@ -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

View file

@ -1,3 +0,0 @@
#!/usr/bin/env bash
ssh "$TREEHOUSE_SERVER" -p "$TREEHOUSE_SERVER_PORT" 'fish' '$TREEHOUSE_PATH/admin/server_sync.fish'

27
admin/daemon.bash Normal file
View file

@ -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

3
admin/daemon/common.bash Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
reload_fifo="/tmp/treehouse_reload.fifo"

5
admin/daemon/reload.bash Normal file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
source "${BASH_SOURCE%/*}/common.bash"
echo "reload" > "$reload_fifo"

3
admin/deploy.bash Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
ssh "$TREEHOUSE_SERVER" -p "$TREEHOUSE_SERVER_PORT" "bash" "~/repo/admin/daemon/reload.bash"

View file

@ -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