LZLZL/AI toolchain/Cloud · Persistence
FREEMedium · Practice D · Cloudservices

Run it as a service,
so it restarts itself

2026-08-21 · But restarting itself is not the same as being fixed

A process you started by hand in a terminal dies when you close the terminal. Keeping it alive means handing it to the system's service manager. Here is how — plus one discipline that outranks the technique: automatic restarts hide problems.

In this pagewhat service-ising buys you, two routes, the traps, restart discipline. Not in this pagemy service names, unit files or log paths. All placeholders.

1What it actually buys

BenefitWithout it
Start at bootAfter a reboot (provider maintenance, kernel update) your thing never came back, and nobody told you
Restart on crashOne transient crash equals permanent stop
Logs with a homeOutput scattered in a terminal, gone when closed; nothing to investigate later
One way to start/stop/checkEvery service with its own startup ritual; in three months you will not remember any of them

The first is the most underrated: a cloud machine will reboot. Not "might" — host maintenance, kernel patches, your own slip. It happens a few times a year.

2Two routes

The tool's own install commandWriting your own unit
Howe.g. hermes gateway install (add --system for boot start)Hand-write a unit file
UpsideIt knows what it needs — paths, variables, orderingFull control
DownsideYou do not know what it wrote for youEasy to miss the environment (below)
AdviceUse it if it existsWhen there is none, or you need different behaviour
⚠ The trap the docs name: do not stack another process manager

Hermes's documentation warns explicitly: do not add a drop-in like ExecStopPost=/bin/kill -9 — it causes an infinite restart loop.

The general lesson: a service that manages its own process should not be wrapped in process management of yours. The classic symptom of two layers fighting is "it keeps restarting and the logs never explain why" — because nothing survives long enough to write it.

⚠ A service's environment is not your terminal's

Same phenomenon as the scheduler trap: services start in a minimal environment — short PATH, none of your shell config, and a working directory that is not the one you assumed.

Symptom: works fine by hand, "command not found" or "config not found" as a service. Same fixes: absolute paths, set variables explicitly, set the working directory explicitly.

3User scope or system scope

UserSystem
PrivilegeThat user's, smallerLarger
Boot start⚠ Usually needs an extra switch, otherwise it waits for that user to log inStarts at boot
AdviceDefault to this — least privilegeWhen boot start or a low port is genuinely required
⚠ The "waits for login" trap

A user service by default starts only after that user logs in. Reboot the machine and the service is not up — but SSH in to check and there it is, running (because you just logged in). The illusion passes casual verification easily.

Verify properly: reboot, do not log in, and confirm from outside that the service responds.

4The one that matters most: restarting is not fixing

Auto-restart disguises "permanently broken" as "permanently running"

A service crashing every 30 seconds and being restarted every 30 seconds reads as "active" from outside. You might not notice for months.

And in those months? Possibly dropping whatever it was processing on each restart, possibly repeating actions that should have happened once, possibly burning money on retries.

Two disciplines:
monitor the restart count itself — not "is it alive" but "how many times did it restart today";
set a restart ceiling: after N consecutive failures in a short window, stop trying and let it stay down. A service that is clearly dead beats one that is pretending to be alive.

5Logs: do not let them grow unbounded

DoWhy
Send to the system log, or a fixed fileThere has to be one definite place to look
Set rotation and size capsOtherwise the disk fills eventually (page 19)
Never log secretsLogs usually have looser permissions and get backed up. Common leak path
The tool's own commands Hermes: hermes gateway install (user scope), sudo hermes gateway install --system (system scope, boot start), hermes gateway start / stop / status; launchd plist on macOS. The docs explicitly warn against adding ExecStopPost=/bin/kill -9-style drop-ins (infinite restarts). Official docs, checked 2026-08-21.
Nature of this page User/system scope, restart ceilings and log discipline are general operations practice; exact commands vary by init system and distribution. No copy-paste unit file is given — those break on one wrong line and every environment differs.
Not in this page My service names, unit files, log paths or restart policies. All placeholders.

RelatedRead next

D · Cloud
Key isolation, monitoring, backups, switching off
C · Always-on
Schedules and hooks: acting while you are away
D · Cloud
The first hour: the order does not reverse
C · Always-on
Telegram: lock down who, then discuss what
An educational and engineering record — not a review or endorsement of any third-party product. Commands, config keys, prices and terms are per each vendor's official docs; this page states when it was checked and all of them can change without notice — verify before you copy anything. Self-hosting is your own responsibility: keys, accounts and data are on you.