The problem usually lies in three lines of systemd configuration, and the evidence may vanish along with the reboot.
Key Takeaways
- start only makes the service run now; enable is what makes it come back after every reboot
- Restart=on-failure cannot save a process that exits with code 0 after an error, and repeated crashes will also trigger the start rate limit
- Under Storage=auto, a machine without a /var/log/journal directory loses all its logs on every reboot
You finish installing the service on the customer's server, type
systemctl start
, see
active (running)
, send the "done" email, and leave. Over the weekend, the customer's ops team patches the OS and reboots the machine. Monday morning, the service isn't running, and
journalctl
contains not a single line explaining what happened.
For a Forward Deployed Engineer (FDE), incidents like this are especially painful. The server isn't yours to manage, no one is on call overnight, and what the customer remembers isn't the model's accuracy but "the vendor's system keeps going down."
There are three easily overlooked causes, all in the systemd configuration. A fourth cause makes the first three hard to diagnose: the logs were never persisted at all.
start and enable are two different things
systemctl
The documentation is explicit: enable and start are independent of each other. A unit can be enabled but not running, or running but never enabled.
systemctl start
only makes the service run now; after the next reboot, systemd has no idea it should bring it back up.
Conversely,
systemctl enable
doesn't run the service either. It only creates symlinks based on the unit's
[Install]
section, and the documentation also states that it does not start the unit at the same time.
WantedBy=multi-user.target
This line makes the target have a
Wants=
-type dependency on your service. The direct consequence: a unit without an
[Install]
section cannot be enabled.
So the command you should type during installation is
systemctl enable --now app.service
: it creates the links for the next boot and immediately runs the service. Then verify with
systemctl is-enabled app
instead of just looking at
status
。
Restart= may not work the way you think
The second cause is the service dying mid-run with nothing to bring it back up. Restart= is off by default,
systemd.service
and the documentation recommends
on-failure
。
Red Hat's guide on service self-healing also treats
on-failure
as the strategy covering the most crash scenarios, including abnormal signals and non-zero exit codes.
But there's a trap here.
on-failure
only restarts when the exit code is non-zero, or when the process exits due to a signal or timeout. Imagine a Python worker that catches all exceptions, logs a "database connection lost" message, and then calls
sys.exit(0)
. From systemd's perspective, this is a clean exit, so the service just stays down.
Restart=always
restarts regardless of whether the exit was clean. The better approach is still to change the code so errors return a non-zero exit code, because under
on-failure
, exit code 0 means the work is done, not that it failed. Only use
always
。
When systemd gives up
The third cause is more subtle. Every restart is subject to the unit's start rate limit, and
RestartSec
has a default delay of only 100ms. A service that crashes on startup (say, due to a bad config file) will quickly exhaust its allowed number of starts.
systemd.unit
The documentation states that once a unit exceeds the burst number of starts within a time interval, it is no longer allowed to start. Red Hat's example configures the service so that two failed restarts within 30 seconds put it into a failed state. At that point
Restart=
no longer has any effect: systemd has stopped trying.
This mechanism can also be used deliberately. For a service deployed at a customer site, a reasonable unit looks like this:
[Unit] Description=客户推理 worker After=network-online.target Wants=network-online.target StartLimitIntervalSec=30 StartLimitBurst=2 [Service] ExecStart=/opt/app/bin/worker Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target
RestartSec=5
This gives transient errors (like a slow-starting database) time to recover on their own. The burst limit makes permanent errors surface as a clear failed state instead of falling into an endless crash loop.
The evidence disappears with the reboot
Back to Monday morning. You type
journalctl -u app -b -1
hoping to see the logs from the service's previous boot, and find nothing. According to the
journald.conf
documentation, under
Storage=auto
, the journal is only written to disk if the
/var/log/journal
directory exists; otherwise the logs are kept in memory only.
Red Hat warns of exactly this consequence: after a reboot the records are deleted, leaving no historical data to analyze. The fix is to create the storage directory and enable persistent mode:
sudo mkdir -p /var/log/journal # 在 /etc/systemd/journald.conf 的 [Journal] 段中设置 # Storage=persistent sudo systemctl restart systemd-journald
Once logs are persistent, three parameters are commonly used for troubleshooting:
-u
filters by a single unit,
-b
limits output to a specific boot, and
-f
follows the output in real time as you restart the service.
Checks to do before you leave
Don't wait for an incident. Each row of the table below is a question you should be able to answer before sending the "done" email.
| Symptom | Likely cause | Check command |
|---|---|---|
| Not running after reboot | Not enabled, or missing [Install] | systemctl is-enabled app |
| Dies mid-run and doesn't recover | Missing Restart=, or exits with code 0 | systemctl status app to see the exit code |
| Enters failed state after a few attempts | Start rate limit triggered | journalctl -u app -b |
| No logs from the previous boot | Journal kept in memory only | ls /var/log/journal |
The most reliable test is still to personally reboot the customer's staging machine while you're on site, then manually kill the process and see whether it recovers. Those five minutes are far cheaper than a phone call on Monday morning.
Common mistakes
One common mistake is setting
Restart=always
on a process with a broken configuration, then being surprised to find it locked in a failed state seconds later. Another is testing only with
start
and never actually rebooting.
The last mistake is more about people: handing the machine over to the customer without a runbook. The handover should include the unit name, the
journalctl
commands to run, and what the failed state means, so the customer's on-call engineer doesn't have to call you.
Turning this skill into an advantage
In an FDE interview, explaining clearly how a service died after a reboot, how you diagnosed it with
journalctl -u ... -b -1
, and how you fixed the unit is far more convincing than a vague line in a skills list.
When writing it on your resume, frame it as an achievement: standardized unit files and persistent journals for customer-site deployments, with a handover runbook included.
This week's exercise: spin up a VM, install a worker that deliberately exits with code 0 on error, install the unit using the template above, and reboot. If you can explain why it didn't recover and point to the log line that proves it, the next time you're on site with a customer, you'll know what to check before you leave.
Was this article helpful?
Thanks for your feedback!