systemctl commands: start, stop, restart, enable, status
The systemctl commands you use most, what each really does, and the difference between restart, reload, enable and daemon-reload.
systemctl controls services on Linux systems that use systemd. Most confusion comes from a few pairs: start and enable, restart and reload, daemon-reload and reload. Each pair does something different.
The commands you need most
- Put sudo in front when you manage system services.
- Replace myapp with your service name (the .service ending is optional).
- Check with status after every change.
- Read the log with journalctl -u myapp -n 50 if it fails.
Commands you can copy
sudo systemctl start myappsudo systemctl stop myappsudo systemctl restart myappsudo systemctl reload myappsystemctl status myappsudo systemctl enable myappsudo systemctl enable --now myappsudo systemctl disable myappsudo systemctl daemon-reloadsystemctl list-units --failedsystemctl is-active myappWhat each command really does
- start vs enable
- start runs it now. enable creates the links so it starts at boot, but does not start it. enable --now does both. disable undoes enable but does not stop it; add --now to stop it too.
- restart vs reload
- restart stops then starts the service, and starts it if it was not running. reload asks the service to reread its own configuration, such as nginx rereading nginx.conf. It does not reload the systemd unit file.
- daemon-reload
- Run it after you edit a .service file. It reruns generators, reloads all unit files and rebuilds the dependency tree. It does not reload any service’s own configuration. Our systemd service generator builds the file.
- mask
- systemctl mask myapp links the unit to /dev/null so nothing, even a manual start, can run it. Undo it with unmask. It fails if a unit file already exists in /etc/systemd/system.
- Exit codes in scripts
- is-active exits 0 if at least one named unit is active. is-enabled exits 0 for enabled, static, alias and indirect, above 0 for disabled and masked, and 4 for not found.
- User services
- Add --user to talk to your own service manager instead of the system one. No sudo is needed.
- It fails to start
- Run systemctl status myapp and journalctl -u myapp -n 50. Common causes are a wrong path in ExecStart (status 203/EXEC) or a missing user (217/USER); the systemd service generator page lists these.
Questions about systemctl commands
- What is the difference between systemctl restart and reload?
- Restart stops and starts the process. Reload asks it to reread its config without stopping, if the service supports it. Not every service does.
- Does systemctl enable start the service?
- No. It only sets it to start at boot. Use enable --now to also start it.
- Why does my edited service file have no effect?
- systemd needs sudo systemctl daemon-reload after you change a unit file, then a restart of the service.
- How do I see why a service failed?
- systemctl status shows the last log lines, and journalctl -u name shows more.
Config generators for this
- systemd service fileRun your app in the background and start it automatically at boot.