Yunohost App Package to Systemd Service Migration Without Downtime
0 reputation · 01 May 2023, 11:07 UTC
0 reputation · 01 May 2023, 11:07 UTC
Yunohost manages applications as Debian-package-like units with install, upgrade, and remove scripts executed via the yunohost app CLI. These scripts typically stop the app's Systemd unit before making changes, creating an inherent service interruption during standard operations.
The platform's backup/restore mechanism (yunohost app backup and yunohost app restore) can copy an app's data and configuration, but restoring to a different instance requires the target app to be stopped during the restore phase. This means even the backup-based migration path involves downtime.
Zero-downtime migration is not built-in and depends on the app's ability to run two versions side-by-side. Manual steps would involve cloning the app instance, updating the reverse-proxy (nginx) configuration to point to the new version, and switching the Systemd service. However, Yunohost's SSOWAT authentication layer and single-instance assumption can cause conflicts with shared resources like database credentials or cron jobs unless the app explicitly supports multi-instance operation.
The yunohost app upgrade --force flag exists but does not guarantee avoiding service stops, leaving downtime behavior to individual app maintainers. Community documentation lacks clear guidance on achieving true zero-downtime migration.
35275 reputation · 01 May 2023, 15:22 UTC
On a stock Yunohost installation the default yunohost app upgrade workflow stops the app’s systemd unit before applying changes. This means a short period of unavailability is unavoidable unless the package itself is written to support a parallel‑instance upgrade pattern.
systemctl stop on the unit that represents the app.nginx -s reload starts new workers with the updated config while old workers finish current requests.To avoid a stop, you would need to run two copies of the application side‑by‑side on different ports, point Nginx to the new upstream, reload Nginx, and then stop the old copy. This blue‑green pattern only works if the app can:
SIGTERM (drain in‑flight requests) and start up without needing data that would be lost during the switch.Because Yunohost’s package templates and the SSOWAT layer are built around a single instance, most applications will not support this pattern out of the box. Adding the necessary hooks would require modifying the package’s install, upgrade, and systemd unit files, and would break the usual backup/restore semantics.
upstream block that can be updated atomically to the new port and reload Nginx.Each of these steps must be tested in a staging environment first. The approach will still involve a brief moment where the old unit is stopped, but the traffic loss can be limited to the reload window.
Does the target application support graceful shutdown (e.g. drains requests on SIGTERM) and share session or state data (database‑backed sessions, Redis, etc.)? If not, the blue‑green pattern will likely cause session loss or data corruption, making a true zero‑downtime migration infeasible.
Use comments to ask for clarification. Post a solution as an answer.
6,130 reputation · 01 May 2023, 13:38 UTC
Yunohost’s app package hooks let you replace the default upgrade script without touching the core template. By defining a templated systemd unit myapp@.service that uses socket activation (ListenStream=/run/myapp.sock) and Type=notify, the upgrade hook can start a second instance (e.g. [contact removed]) on a different socket, reload nginx to point to the new socket, wait for the old instance to finish existing requests, then stop it. This avoids the systemctl stop‑induced downtime while respecting Yunohost’s single‑instance assumption because the two services are distinct instances of the same template.