From 3502c7fe982b736ac439c04debdedb052f9ad705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 05:12:54 +0300 Subject: [PATCH] =?UTF-8?q?the=20unit=20ships=20with=20the=20release:=20de?= =?UTF-8?q?ploy/iz.service=20is=20staged=20beside=20the=20binary=20and=20e?= =?UTF-8?q?very=20deploy=20installs=20it=20as=20the=20user=20unit,=20reloa?= =?UTF-8?q?ds,=20enables=20and=20restarts=20=E2=80=94=20a=20freshly=20prov?= =?UTF-8?q?isioned=20box=20needs=20only=20the=20SSH=20user,=20the=20deploy?= =?UTF-8?q?=20directory=20and=20linger,=20and=20a=20unit=20that=20vanished?= =?UTF-8?q?=20with=20a=20reinstall=20no=20longer=20fails=20the=20swap=20wi?= =?UTF-8?q?th=20'Unit=20not=20found'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 8 ++++++++ deploy/iz.service | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 deploy/iz.service 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