Exercise 2: Why a Migration Script Needs Type=oneshot + RemainAfterExit=yes — Possible Solution ==================================================================== Explanation: Per the chapter's own compare-table, Type=simple considers a service "started" the moment its ExecStart= process forks -- and, critically, systemd expects that process to keep RUNNING as the actual service. A database migration script is fundamentally different in shape: it's meant to run once, perform its work, and then EXIT -- there is no long-running process for systemd to keep tracking as "the service" after the migration finishes. If this were configured as Type=simple, the moment the script legitimately finished and exited (having successfully done its job), systemd would interpret that exit as the service having stopped/failed, which is a fundamentally wrong reading of what actually happened -- the script SUCCEEDED, it didn't crash. Type=oneshot is built exactly for this shape of task -- per the chapter's own description, it's "a command that runs once and exits, not a long-running daemon at all." Systemd correctly expects the process to exit as the normal, successful completion of the unit's job, rather than treating that exit as a failure needing a restart. RemainAfterExit=yes is the necessary companion setting because, without it, systemctl status would report the migration unit as inactive the instant the script finishes -- even though it succeeded -- making it hard to tell at a glance whether the migration ever actually ran successfully. With RemainAfterExit=yes, per the chapter's own description, the unit continues to be reported as "active" after the one-time command completes, giving a clear, persistent signal that the migration has been run. WHY THIS WORKS AS AN ANSWER ------------------------------ This explains why Type=simple's own definition of "started" is fundamentally the wrong model for a run-once-and-exit script, and separately explains what RemainAfterExit=yes specifically adds on top of Type=oneshot, rather than treating the two settings as a single, unexplained combination.