My-Weekly-ToDo-List/scripts/my-weekly-todo-update.service
mARTin-B78 6f4fe219dc
Some checks are pending
Playwright Tests / test (push) Waiting to run
fix: make update-app.sh the single update path and run it at boot
There were two near-identical update scripts and they drifted: the npm ci fix
from 1.114.1 only ever landed in update-app.sh, so the boot path kept running
npm install. my-weekly-todo-update.service now runs update-app.sh, and
boot-update.sh is a shim kept only so a not-yet-recopied unit still works.

To be usable at boot the script needed three things it did not have:

- Skip the rebuild when HEAD already matches origin/main and a standalone
  build exists, so a reboot is not a full rebuild every time (--force
  overrides).
- Do not restart PM2 when its daemon is not up yet. At boot this unit runs
  before pm2-root.service, and probing with `pm2 describe` would spawn a
  stray daemon that races the real service, so it checks the pid file.
- A flock single-instance lock, so a boot run and a manual run cannot install
  into the same tree at once.

It also picks up prisma migrate deploy / generate and the .env copy that only
the boot script had. The log moved to /var/log/my-weekly-todo-update.log.

v1.115.2

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 13:46:18 +02:00

24 lines
944 B
Desktop File

[Unit]
Description=My Weekly ToDo List - Boot Update (git pull + build)
# Runs the same script as a manual deploy; it skips the rebuild when nothing changed and
# leaves starting the app to pm2-root.service, which is ordered after this unit.
After=network-online.target
Wants=network-online.target
Before=pm2-root.service
[Service]
Type=oneshot
ExecStart=/bin/bash /root/My-Weekly-ToDo-List/scripts/update-app.sh
WorkingDirectory=/root/My-Weekly-ToDo-List
Environment=HOME=/root
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
StandardOutput=journal+console
StandardError=journal+console
# npm ci + prisma generate + next build in this container takes well over the old 300s.
# systemd SIGTERMs a Type=oneshot unit at the timeout, which used to kill npm mid-install
# and leave a node_modules tree that npm could no longer clean up (ENOTEMPTY on rmdir).
TimeoutStartSec=1800
[Install]
WantedBy=multi-user.target