User Tools

Site Tools


ubuntu:services:cheatsheet

Ubuntu - Services - Cheatsheet

systemdSysVinit
Start a servicesystemctl start service_name.serviceservice service_name start
Stop a servicesystemctl stop service_name.serviceservice service_name stop
Restart a service systemctl restart service_name.serviceservice service_name restart
Reload a service systemctl reload service_name.serviceservice service_name reload
Service statussystemctl status service_name.serviceservice service_name status
Restart a service if already runningsystemctl condrestart service_name.serviceservice service_name condrestart
Enable service at startupsystemctl enable service_name.servicechkconfig service_name on
Disable service at startupsystemctl disable service_name.servicechkconfig service_name off
Check if a service is enabled at startupsystemctl is-enabled service_name.servicechkconfig service_name
Create a new service file or modify configurationsystemctl daemon-reload service_name.servicechkconfig service_name --add

NOTE: New versions of systemd support systemctl start service_name etc.


Runlevels

systemdSysVinit
System haltrunlevel0.target,poweroff.target0
Single user moderunlevel1.target,rescue.target1, s, single
Multi userrunlevel2.target, multi-user.target2
Multi user with networkrunlevel3.target, multi-user.target3
Experimentalrunlevel4.target, multi-user.target4
Multi user with network and GUIrunlevel5.target, graphical.target5
Rebootrunlevel5.target, reboot.target6
Emergency shellemergency.targetemergency
Change to multi-user runlevelsystemctl isolate multi-user.targettelinit 3
Set multi-user level for next bootln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.targetsed s/^id:.*:initdefault:/id:3:initdefault:/
Check current runlevelsystemctl get-defaultrunlevel
Change default runlevelsystemctl set-default multi-user.targetsed s/^id:.*:initdefault:/id:3:initdefault:/

Miscellaneous Commands

systemdSysVinit
System haltsystemctl halthalt
Power off the systemsystemctl poweroffpoweroff
Restart the systemsystemctl rebootreboot
Suspend the systemsystemctl suspendpm-suspend
Hibernatesystemctl hibernatepm-hibernate
Follow the system log filejournalctl -ftail -f /var/log/messages or tail -f /var/log/syslog

Systemd New Commands

Execute a systemd command on a remote hostsystemctl service_name.service start -H user@host
Check boot timesystemd-analyze or systemd-analyze time
Kill all processes related to a servicesystemctl kill service
Get logs for events for todayjournalctl --since=today
Hostname and other host-related infohostnamectl
Date and time of system with timezone and other infotimedatectl

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.

ubuntu/services/cheatsheet.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki