Start/stop or enable/disable services
Activates a service immediately:
# systemctl start foo.service
Deactivates a service immediately:
# systemctl stop foo.service
Restarts a service:
# systemctl restart foo.service
Shows status of a service including whether it is running or not:
# systemctl status foo.service
Enables a service to be started on bootup:
# systemctl enable foo.service
Disables a service to not start during bootup:
# systemctl disable foo.service
Check whether a service is already enabled or not:
# systemctl is-enabled foo.service; echo $?
0 indicates that it is enabled. 1 indicates that it is disabled
How do I change the runlevel?
systemd has the concept of targets which is a more flexible replacement for runlevels in sysvinit.
Run level 3 is emulated by multi-user.target. Run level 5 is emulated by graphical.target. runlevel3.target is a symbolic link to multi-user.target and runlevel5.target is a symbolic link to graphical.target.
You can switch to ‘runlevel 3′ by running
# systemctl isolate multi-user.target (or) systemctl isolate runlevel3.target
You can switch to ‘runlevel 5′ by running
# systemctl isolate graphical.target (or) systemctl isolate runlevel5.target
How do I change the default runlevel?
systemd uses symlinks to point to the default runlevel. You have to delete the existing symlink first before creating a new one
# rm /etc/systemd/system/default.target
Switch to runlevel 3 by default
# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
Switch to runlevel 5 by default
# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
systemd does not use /etc/inittab file.
List the current run level
runlevel command still works with systemd. You can continue using that however runlevels is a legacy concept in systemd and is emulated via ‘targets’ and multiple targets can be active at the same time. So the equivalent in systemd terms is
# systemctl list-units --type=target
Powering off the machine
You can use
Some more possibilities are:
shutdown -P now
halt used to work the same as
poweroff in previous Fedora releases, but systemd distinguishes between the two, so
halt without parameters now does exactly what it says – it merely stops the system without turning it off.
Service vs. systemd
# service NetworkManager stop
# systemctl stop NetworkManager.service
Chkconfig vs. systemd
# chkconfig NetworkManager off
# systemctl disable NetworkManager.service
systemd has a built-in readahead implementation is not enabled on upgrades. It should improve bootup speed but your mileage may vary depending on your hardware. To enable readahead:
# systemctl enable systemd-readahead-collect.service
# systemctl enable systemd-readahead-replay.service
|service foobar start
||systemctl start foobar.service
||Used to start a service (not reboot persistent)
|service foobar stop
||systemctl stop foobar.service
||Used to stop a service (not reboot persistent)
|service foobar restart
||systemctl restart foobar.service
||Used to stop and then start a service
|service foobar reload
||systemctl reload foobar.service
||When supported, reloads the config file without interrupting pending operations.
|service foobar condrestart
||systemctl condrestart foobar.service
||Restarts if the service is already running.
|service foobar status
||systemctl status foobar.service
||Tells whether a service is currently running.
||ls /lib/systemd/system/*.service /etc/systemd/system/*.service
||Used to list the services that can be started or stopped
|chkconfig foobar on
||systemctl enable foobar.service
||Turn the service on, for start at next boot, or other trigger.
|chkconfig foobar off
||systemctl disable foobar.service
||Turn the service off for the next reboot, or any other trigger.
||systemctl is-enabled foobar.service
||Used to check whether a service is configured to start or not in the current environment.
|chkconfig foobar –list
||Used to list what levels this service is configured on or off
|chkconfig foobar –add
||Not needed, no equivalent.
Linux readahead: less tricks for more