forge
Explore
Log in

Don't you dare go Hollow

the unit ships with the release: deploy/iz.service is staged beside the binary and every deploy installs it as the user unit, reloads, enables and restarts — a freshly provisioned box needs only the SSH user, the deploy directory and linger, and a unit that vanished with a reinstall no longer fails the swap with 'Unit not found'

Browse files at this commit

3502c7fe982b736ac439c04debdedb052f9ad705Ahmet Kaan GümüşParent: f36493f
.github/workflows/main.ymlmodified+8 -0
@@ -99,6 +99,7 @@ jobs:
99 # embedded in the binary it produced.99 # embedded in the binary it produced.
100 topcoat asset bundle --package iz-web --profile "$PROFILE" --out stage/assets100 topcoat asset bundle --package iz-web --profile "$PROFILE" --out stage/assets
101 cp "target/$TARGET/$PROFILE/iz-web" stage/iz-web101 cp "target/$TARGET/$PROFILE/iz-web" stage/iz-web
102+ cp deploy/iz.service stage/iz.service
102 strip stage/iz-web103 strip stage/iz-web
103 ls -l stage stage/assets104 ls -l stage stage/assets
104 105
@@ -167,6 +168,13 @@ jobs:
167 mv -- "$deploy_path/current" "$deploy_path/current.previous"168 mv -- "$deploy_path/current" "$deploy_path/current.previous"
168 fi169 fi
169 mv -- "$deploy_path/current.new" "$deploy_path/current"170 mv -- "$deploy_path/current.new" "$deploy_path/current"
171+ # The unit ships with the release: a freshly provisioned box has
172+ # no unit until the first deploy writes it, and a changed unit
173+ # lands with the code that needs it. Enabling is idempotent.
174+ mkdir -p -- "$HOME/.config/systemd/user"
175+ install -m 644 -- "$deploy_path/current/iz.service" "$HOME/.config/systemd/user/$service.service"
176+ systemctl --user daemon-reload
177+ systemctl --user enable -- "$service"
170 systemctl --user restart "$service"178 systemctl --user restart "$service"
171 # The unit is Type=simple, so a restart returns before the new179 # The unit is Type=simple, so a restart returns before the new
172 # process has bound its port — and before an old one has let go180 # process has bound its port — and before an old one has let go
deploy/iz.serviceadded+20 -0
@@ -0,0 +1,20 @@
1+# The systemd user unit iz runs under on the server. The deploy workflow
2+# installs this file as ~/.config/systemd/user/iz.service on every release,
3+# reloads the manager, enables the unit and restarts it, so a freshly
4+# provisioned box needs nothing but the SSH user, the deploy directory and
5+# `loginctl enable-linger` (once, so the unit outlives the login).
6+#
7+# The working directory is the deploy path itself, not the release: the
8+# binary reads config/iz.toml, the database and the key relative to it,
9+# and only current/ is swapped by a deploy.
10+[Unit]
11+Description=iz
12+After=network-online.target
13+
14+[Service]
15+WorkingDirectory=%h/iz
16+ExecStart=%h/iz/current/iz-web
17+Restart=on-failure
18+
19+[Install]
20+WantedBy=default.target