# systemctl — Control systemd Services and Units

> Practical guide to systemctl — start, stop, enable and inspect services, manage units, targets and timers, and control system state.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/systemctl/

<!-- PROSE:intro -->
systemctl is the central tool for controlling the systemd init and service manager – from individual services to the entire system state. You start, stop and reload services, enable them for automatic startup, check their status, and work with units, targets, timers and logs. This guide walks you through the commands you actually reach for in everyday server work, from a quick `restart` to boot analysis with `systemd-analyze`.
<!-- PROSE:intro:end -->

## Service Control

`systemctl start <service>` — Start a service immediately.

```bash
systemctl start nginx
```

`systemctl stop <service>` — Stop a running service.

```bash
systemctl stop nginx
```

`systemctl restart <service>` — Stop and then start a service. Causes a brief downtime.

```bash
systemctl restart nginx
```

`systemctl reload <service>` — Reload configuration without stopping the service (zero downtime, if supported).

```bash
systemctl reload nginx
```

`systemctl reload-or-restart <service>` — Reload if the service supports it, otherwise restart.

```bash
systemctl reload-or-restart php-fpm
```

`systemctl try-restart <service>` — Restart a service only if it is currently running.

```bash
systemctl try-restart nginx
```

`systemctl kill <service>` — Send a signal to a service's processes. Default signal is SIGTERM.

```bash
systemctl kill nginx
```

`systemctl kill -s SIGKILL <service>` — Force kill a service by sending SIGKILL to all its processes.

```bash
systemctl kill -s SIGKILL stuck-service
```

## Enable & Disable (Boot Behavior)

`systemctl enable <service>` — Enable a service to start automatically at boot.

```bash
systemctl enable nginx
```

`systemctl disable <service>` — Disable a service from starting at boot.

```bash
systemctl disable nginx
```

`systemctl enable --now <service>` — Enable at boot and start immediately in one command.

```bash
systemctl enable --now nginx
```

`systemctl disable --now <service>` — Disable at boot and stop immediately in one command.

```bash
systemctl disable --now nginx
```

`systemctl is-enabled <service>` — Check if a service is enabled for automatic start at boot.

```bash
systemctl is-enabled nginx
```

`systemctl reenable <service>` — Disable and re-enable a service. Useful after changing the [Install] section.

```bash
systemctl reenable nginx
```

`systemctl mask <service>` — Completely prevent a service from being started (even manually). Links unit to /dev/null.

```bash
systemctl mask bluetooth
```

`systemctl unmask <service>` — Remove the mask and allow the service to be started again.

```bash
systemctl unmask bluetooth
```

## Service Status & Inspection

`systemctl status <service>` — Show detailed status including state, PID, memory usage, and recent log lines.

```bash
systemctl status nginx
```

`systemctl is-active <service>` — Check if a service is currently running. Returns active or inactive.

```bash
systemctl is-active nginx
```

`systemctl is-failed <service>` — Check if a service has failed.

```bash
systemctl is-failed nginx
```

`systemctl show <service>` — Show all properties of a service in key=value format.

```bash
systemctl show nginx
```

`systemctl show <service> -p <property>` — Show a specific property of a service.

```bash
systemctl show nginx -p MainPID
```

`systemctl show <service> -p ActiveState,SubState` — Show multiple specific properties at once.

```bash
systemctl show nginx -p ActiveState,SubState,MainPID
```

`systemctl cat <service>` — Display the full unit file content of a service.

```bash
systemctl cat nginx
```

`systemctl help <service>` — Open the man page associated with a service (if available).

```bash
systemctl help sshd
```

## Listing Units

`systemctl list-units` — List all loaded and active units.

```bash
systemctl list-units
```

`systemctl list-units --type=service` — List only service units.

```bash
systemctl list-units --type=service
```

`systemctl list-units --state=running` — List only currently running units.

```bash
systemctl list-units --state=running
```

`systemctl list-units --state=failed` — List all units that have failed.

```bash
systemctl list-units --state=failed
```

`systemctl list-units --all` — List all units including inactive ones.

```bash
systemctl list-units --all
```

`systemctl list-unit-files` — List all installed unit files with their enabled/disabled state.

```bash
systemctl list-unit-files
```

`systemctl list-unit-files --type=service` — List only service unit files with their state.

```bash
systemctl list-unit-files --type=service
```

`systemctl list-unit-files --state=enabled` — List only enabled unit files.

```bash
systemctl list-unit-files --state=enabled
```

## Dependencies & Order

`systemctl list-dependencies <service>` — Show a tree of units that a service depends on.

```bash
systemctl list-dependencies nginx
```

`systemctl list-dependencies <service> --reverse` — Show which units depend on (require) this service.

```bash
systemctl list-dependencies nginx --reverse
```

`systemctl list-dependencies <service> --before` — Show units that this service starts before.

```bash
systemctl list-dependencies nginx --before
```

`systemctl list-dependencies <service> --after` — Show units that this service starts after.

```bash
systemctl list-dependencies nginx --after
```

## Unit File Management

`systemctl edit <service>` — Create a drop-in override file for a service (opens editor). Changes survive package updates.

```bash
systemctl edit nginx
```

`systemctl edit --full <service>` — Edit the full unit file directly (not a drop-in). Overrides will NOT survive package updates.

```bash
systemctl edit --full nginx
```

`systemctl daemon-reload` — Reload systemd manager configuration after modifying unit files. Required after any manual edit.

```bash
systemctl daemon-reload
```

`systemctl revert <service>` — Remove all local customizations (drop-ins) and revert to the vendor unit file.

```bash
systemctl revert nginx
```

`systemd-analyze verify <unit_file>` — Check a unit file for syntax errors and common issues.

```bash
systemd-analyze verify /etc/systemd/system/my-app.service
```

## Timers (Cron Replacement)

`systemctl list-timers` — List all active timers with their next and last trigger times.

```bash
systemctl list-timers
```

`systemctl list-timers --all` — List all timers including inactive ones.

```bash
systemctl list-timers --all
```

`systemctl start <timer>` — Start a timer immediately.

```bash
systemctl start backup.timer
```

`systemctl enable --now <timer>` — Enable a timer to persist across reboots and start it now.

```bash
systemctl enable --now backup.timer
```

`systemctl status <timer>` — Show timer status including next scheduled run.

```bash
systemctl status backup.timer
```

`systemd-analyze calendar '<expression>'` — Test and parse a calendar expression to see when it would trigger.

```bash
systemd-analyze calendar 'Mon..Fri *-*-* 06:00:00'
```

`systemd-run --on-calendar='<expression>' <command>` — Create a transient timer that runs a command on a schedule.

```bash
systemd-run --on-calendar='*-*-* 02:00:00' /usr/local/bin/backup.sh
```

`systemd-run --on-active=<time> <command>` — Create a transient timer that runs once after a delay.

```bash
systemd-run --on-active=30m /usr/local/bin/cleanup.sh
```

## Journalctl (Logs)

`journalctl -u <service>` — Show all log entries for a specific service.

```bash
journalctl -u nginx
```

`journalctl -u <service> -f` — Follow (tail) live log output for a service.

```bash
journalctl -u nginx -f
```

`journalctl -u <service> -n <lines>` — Show only the last N log lines for a service.

```bash
journalctl -u nginx -n 50
```

`journalctl -u <service> --since '<time>'` — Show logs since a specific time.

```bash
journalctl -u nginx --since '1 hour ago'
```

`journalctl -u <service> --since '<start>' --until '<end>'` — Show logs within a time range.

```bash
journalctl -u nginx --since '2024-01-01' --until '2024-01-02'
```

`journalctl -u <service> -p <priority>` — Filter logs by priority: emerg, alert, crit, err, warning, notice, info, debug.

```bash
journalctl -u nginx -p err
```

`journalctl -u <service> -o json-pretty` — Output logs in pretty-printed JSON format.

```bash
journalctl -u nginx -o json-pretty
```

`journalctl -u <service> --no-pager` — Output logs without using a pager (useful for piping).

```bash
journalctl -u nginx --no-pager | grep error
```

`journalctl -b` — Show all logs from the current boot.

```bash
journalctl -b
```

`journalctl -b -1` — Show logs from the previous boot.

```bash
journalctl -b -1
```

`journalctl --list-boots` — List all recorded boot sessions.

```bash
journalctl --list-boots
```

`journalctl --disk-usage` — Show how much disk space the journal logs consume.

```bash
journalctl --disk-usage
```

`journalctl --vacuum-size=<size>` — Reduce journal log storage to a maximum size.

```bash
journalctl --vacuum-size=500M
```

`journalctl --vacuum-time=<time>` — Remove journal entries older than the specified time.

```bash
journalctl --vacuum-time=30d
```

## System State & Targets

`systemctl get-default` — Show the default boot target (e.g. graphical.target, multi-user.target).

```bash
systemctl get-default
```

`systemctl set-default <target>` — Set the default boot target.

```bash
systemctl set-default multi-user.target
```

`systemctl isolate <target>` — Switch to a different target immediately (like changing runlevel).

```bash
systemctl isolate multi-user.target
```

`systemctl list-units --type=target` — List all active targets.

```bash
systemctl list-units --type=target
```

`systemctl reboot` — Reboot the system.

```bash
systemctl reboot
```

`systemctl poweroff` — Shut down and power off the system.

```bash
systemctl poweroff
```

`systemctl suspend` — Suspend the system to RAM.

```bash
systemctl suspend
```

`systemctl hibernate` — Hibernate the system to disk.

```bash
systemctl hibernate
```

## Analyze & Performance

`systemd-analyze` — Show how long the system boot took (kernel + userspace).

```bash
systemd-analyze
```

`systemd-analyze blame` — List all services by startup time, slowest first.

```bash
systemd-analyze blame
```

`systemd-analyze critical-chain` — Show the critical chain of units that delayed the boot the most.

```bash
systemd-analyze critical-chain
```

`systemd-analyze critical-chain <service>` — Show the critical chain for a specific service.

```bash
systemd-analyze critical-chain nginx.service
```

`systemd-analyze plot > boot.svg` — Generate an SVG chart of the boot process for visual analysis.

```bash
systemd-analyze plot > boot.svg
```

`systemd-analyze security <service>` — Analyze the security and sandboxing settings of a service.

```bash
systemd-analyze security nginx
```

## User Services

`systemctl --user start <service>` — Start a user-level service (no root required).

```bash
systemctl --user start my-app
```

`systemctl --user enable --now <service>` — Enable and start a user-level service.

```bash
systemctl --user enable --now my-app
```

`systemctl --user status <service>` — Show the status of a user-level service.

```bash
systemctl --user status my-app
```

`systemctl --user list-units --type=service` — List all user-level services.

```bash
systemctl --user list-units --type=service
```

`systemctl --user daemon-reload` — Reload user-level systemd configuration after editing unit files.

```bash
systemctl --user daemon-reload
```

`loginctl enable-linger <user>` — Allow user services to run even when the user is not logged in.

```bash
loginctl enable-linger deploy
```

<!-- PROSE:outro -->
## Conclusion

systemctl bundles the entire service control of systemd into one consistent command – for everyday work, `start`, `stop`, `restart`, `reload` and `status` already take you a long way. The key distinction is between `enable`/`disable` (autostart at boot) and `start`/`stop` (immediate effect right now); `enable --now` combines both in a single step. After any change to unit files, run `systemctl daemon-reload`, and `list-units --failed` quickly shows you what is broken. Be careful with critical services: a `stop`, `disable` or `mask` on `sshd` or the network can cut off access or the next boot on a remote server. `reboot`, `poweroff` and `isolate` also reach deep into the system – and most write actions require `sudo`. Your own user services you manage entirely without root via `systemctl --user`.

## Further Reading

- [systemctl manual page](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html) – the official systemctl reference covering every subcommand and option
- [Arch Wiki: systemd](https://wiki.archlinux.org/title/Systemd) – comprehensive guide to systemd, units and timers
<!-- PROSE:outro:end -->

## Related Commands

- [journalctl](https://www.jpkc.com/db/en/cheatsheets/shell-system/journalctl/) – query logs from systemd services and the journal
- [loginctl](https://www.jpkc.com/db/en/cheatsheets/shell-system/loginctl/) – manage user sessions and logins via systemd-logind
- [hostnamectl](https://www.jpkc.com/db/en/cheatsheets/shell-system/hostnamectl/) – query and set the hostname and system information via systemd

