Tuesday, 3 September 2019

How To Use Systemctl to Manage Systemd Services and Units

Starting and Stopping Services

sudo systemctl start application.service                   or
sudo systemctl start application

Restarting and Reloading

sudo systemctl restart application.service

if application has ability to reload its configuration files:

sudo systemctl reload application.service

universal command (if you don't know is there in application ability to reload):

sudo systemctl reload-or-restart application.service

Enabling and Disabling Services

systemctl enable application.service

systemctl disable application.service

Change the “runlevels”/targets after booting

systemctl isolate multi-user.target

Change the boot “runlevels”/targets

Runlevels - Targets

0          -  poweroff.target
1          -  rescue.target
2, 3, 4  -  multi-user.target
5          -  graphical.target 
6          -  reboot.target  

Make “multi-user.target” the default “runlevel”

systemctl enable multi-user.target
systemctl set-default multi-user.target

Checking the Status of Services

systemctl status application.service

systemctl is-active application.service

systemctl is-enabled application.service

systemctl is-failed application.service

System State Overview

Listing Current Units
systemctl list-units


systemctl list-units --all

Use the --state= flag to indicate the LOAD, ACTIVE, or SUB states

systemctl list-units --all --state=inactive

systemctl list-units --type=service

Listing All Unit Files

systemctl list-unit-files

Displaying Dependencies

systemctl list-dependencies sshd.service

Checking Unit Properties

systemctl show sshd.service


systemctl rescue                      - put system into single-user mode

systemctl halt                          - will halt the system - meaning the system will       shutdown and at the end stop at a screen with the last message beeing something like "System halted".

systemctl poweroff                 -  will power off the system - meaning the system  will shutdown and at the end power off (sends an ACPI command to the board, then to the PSU, to cut the power)

systemctl reboot                      - reboot the system

No comments: