cheat.sheets:systemctl
# systemctl
# Control the systemd system and service manager
# Show only a given value from one of the `show` keys. In this example, the
# value for the `ActiveState` key for the UFW service will be shown, and only
# it; ideal for scripting.
#
# Using the `--value` flag causes only the value to be displayed.
systemctl show -p ActiveState --value ufw
# Start, stop, or restart a given service(s).
systemctl [start|stop|restart] [SERVICE]
# Check if a given service(s) is active. If it is, 'active' will display. An
# exit status of 0 will be given if it's active, and non-zero otherwise. Use
# the `-q` or `--quiet` flag to rely only on the exit status.
systemctl is-active ufw
# Check if a given service(s) has failed. If it is, 'failed' will display. An
# exit status of 0 will be given if it has failed, and non-zero otherwise. Use
# the `-q` or `--quiet` flag to rely only on the exit status.
systemctl is-active ufw
# Check if a given service(s) is enabled. If it is, 'enabled' will display. An
# exit status of 0 will be given if it's enabled, and non-zero otherwise. Use
# the `-q` or `--quiet` flag to rely only on the exit status.
systemctl is-enabled ufw
# List all failed services.
systemctl --failed
# Shut the system down. Use `suspend` to suspend, `halt` to halt, and `reboot`
# to instead of reboot the machine.
systemctl poweroff
# Enable or disable a given service(s).
systemctl [enable|disable] [SERVICE]
# Show the current status of a given service(s).
systemctl status [SERVICE]
cheat:systemctl
# To see running processes:
systemctl
# To check the status of a service:
systemctl status foo.service
# To start/restart/stop a service:
systemctl start/restart/stop foo.service
# To reload a service's configuration:
systemctl reload foo.service
# To edit a service's configuration:
systemctl edit foo.service
# To reload systemd manager configuration:
systemctl daemon-reload
# To enable a service to startup on boot:
systemctl enable foo.service
# To disable a service to startup on boot:
systemctl disable foo.service
# To start/restart/stop per-user service:
systemctl --user start/restart/stop emacs.service
# To see all active units, add --all for everything:
systemctl list-units
# To see all service units:
systemctl list-units -at service
# To see filtered units (all running service):
systemctl list-units -t service --state running
# To see all service files, see which are enabled or disabled:
systemctl list-unit-files -at service
# To list all units with specific status, inactive, active, enabled, running, exited:
systemctl list-units --all --state=inactive
# To use systemctl to list all unit files:
systemctl list-unit-files
# To see log items from the most recent boot:
journalctl -b
# To to see only kernal messages, add -b for at the most recent boot:
journalctl -k
# To get the log entries for a service since boot:
journalctl -b -u foo.service
# To list the dependencies of a service:
# when no service name is specified, lists the dependencies of default.target
# add -all to expand dependencies recursively
systemctl list-dependencies foo.service
# To see low level details of a service settings on the system:
systemctl show foo.service
# To list currently loaded targets:
systemctl list-units --type=target
# To change current target:
systemctl isolate foo.target
# To change default target:
systemctl enable foo.target
tldr:systemctl
# systemctl
# Control the systemd system and service manager.
# More information: <https://www.freedesktop.org/software/systemd/man/systemctl.html>.
# Show all running services:
systemctl status
# List failed units:
systemctl --failed
# Start/Stop/Restart/Reload a service:
systemctl start|stop|restart|reload unit
# Show the status of a unit:
systemctl status unit
# Enable/Disable a unit to be started on bootup:
systemctl enable|disable unit
# Mask/Unmask a unit to prevent enablement and manual activation:
systemctl mask|unmask unit
# Reload systemd, scanning for new or changed units:
systemctl daemon-reload
# Check if a unit is enabled:
systemctl is-enabled unit
$
cheat.sh