diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15af889..3693286 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,6 +99,7 @@ jobs: # embedded in the binary it produced. topcoat asset bundle --package iz-web --profile "$PROFILE" --out stage/assets cp "target/$TARGET/$PROFILE/iz-web" stage/iz-web + cp deploy/iz.service stage/iz.service strip stage/iz-web ls -l stage stage/assets @@ -167,6 +168,13 @@ jobs: mv -- "$deploy_path/current" "$deploy_path/current.previous" fi mv -- "$deploy_path/current.new" "$deploy_path/current" + # The unit ships with the release: a freshly provisioned box has + # no unit until the first deploy writes it, and a changed unit + # lands with the code that needs it. Enabling is idempotent. + mkdir -p -- "$HOME/.config/systemd/user" + install -m 644 -- "$deploy_path/current/iz.service" "$HOME/.config/systemd/user/$service.service" + systemctl --user daemon-reload + systemctl --user enable -- "$service" systemctl --user restart "$service" # The unit is Type=simple, so a restart returns before the new # process has bound its port — and before an old one has let go diff --git a/deploy/iz.service b/deploy/iz.service new file mode 100644 index 0000000..e974f45 --- /dev/null +++ b/deploy/iz.service @@ -0,0 +1,20 @@ +# The systemd user unit iz runs under on the server. The deploy workflow +# installs this file as ~/.config/systemd/user/iz.service on every release, +# reloads the manager, enables the unit and restarts it, so a freshly +# provisioned box needs nothing but the SSH user, the deploy directory and +# `loginctl enable-linger` (once, so the unit outlives the login). +# +# The working directory is the deploy path itself, not the release: the +# binary reads config/iz.toml, the database and the key relative to it, +# and only current/ is swapped by a deploy. +[Unit] +Description=iz +After=network-online.target + +[Service] +WorkingDirectory=%h/iz +ExecStart=%h/iz/current/iz-web +Restart=on-failure + +[Install] +WantedBy=default.target