====== Ubuntu - Services - Cheatsheet ======
===== Service-related commands =====
| ^systemd^SysVinit^
|Start a service|systemctl start service_name.service|service service_name start|
|Stop a service|systemctl stop service_name.service|service service_name stop|
|Restart a service |systemctl restart service_name.service|service service_name restart|
|Reload a service |systemctl reload service_name.service|service service_name reload|
|Service status|systemctl status service_name.service|service service_name status|
|Restart a service if already running|systemctl condrestart service_name.service|service service_name condrestart|
|Enable service at startup|systemctl enable service_name.service|chkconfig service_name on|
|Disable service at startup|systemctl disable service_name.service|chkconfig service_name off|
|Check if a service is enabled at startup|systemctl is-enabled service_name.service|chkconfig service_name|
|Create a new service file or modify configuration|systemctl daemon-reload service_name.service|chkconfig service_name --add|
**NOTE**: New versions of systemd support **systemctl start service_name** etc.
----
===== Runlevels =====
| ^systemd^SysVinit^
|System halt|runlevel0.target,poweroff.target|0|
|Single user mode|runlevel1.target,rescue.target|1, s, single|
|Multi user|runlevel2.target, multi-user.target|2|
|Multi user with network|runlevel3.target, multi-user.target|3|
|Experimental|runlevel4.target, multi-user.target|4|
|Multi user with network and GUI|runlevel5.target, graphical.target|5|
|Reboot|runlevel5.target, reboot.target|6|
|Emergency shell|emergency.target|emergency|
|Change to multi-user runlevel|systemctl isolate multi-user.target|telinit 3|
|Set multi-user level for next boot|ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target|sed s/^id:.*:initdefault:/id:3:initdefault:/|
|Check current runlevel|systemctl get-default|runlevel|
|Change default runlevel|systemctl set-default multi-user.target|sed s/^id:.*:initdefault:/id:3:initdefault:/|
----
===== Miscellaneous Commands =====
| ^systemd^SysVinit^
|System halt|systemctl halt|halt|
|Power off the system|systemctl poweroff|poweroff|
|Restart the system|systemctl reboot|reboot|
|Suspend the system|systemctl suspend|pm-suspend|
|Hibernate|systemctl hibernate|pm-hibernate|
|Follow the system log file|journalctl -f|tail -f /var/log/messages or tail -f /var/log/syslog|
----
====== Systemd New Commands ======
|Execute a systemd command on a remote host|systemctl service_name.service start -H user@host|
|Check boot time|systemd-analyze or systemd-analyze time|
|Kill all processes related to a service|systemctl kill service|
|Get logs for events for today|journalctl --since=today|
|Hostname and other host-related info|hostnamectl|
|Date and time of system with timezone and other info|timedatectl|
----
===== Other commands =====
systemctl mask system_name.service
Masking a service prevents the service from being started manually or automatically.
For this example, systemctl is creating a symlink from /etc/systemd/system/service_name.service to /dev/null.
Targets in /etc/systemd override those provided by packages in /lib/systemd.
systemd recognizes the symlink and will not start the service.