Since CentOS7, command
service has been changed to
systemctl. For a while I was very repel to it cause I was new and not used to it at all. Though that
service is still usable in CentOS7 but after I thought, what the hell, why not learn and get used to something new? Therefore, this article is produced as reference, for me and anyone else who is also struggling to learn and unfamiliar with
systemctl like me.
Before we start, please note that systemctl not only can manage service but also path, slice, snapshot, socket, swap, target and timer. And they are called
Gathering systemd information
First of all, we can use help to list all the usages.
1 systemctl -h
It is important to know/list out all the installed unit files.
1 systemctl list-unit-files
static means it can’t be start or stop like a
service. static unit files are mostly a “one time job” or is depended by other unit files.
Unit files name can be added for particular query.
1 systemctl list-unit-files sshd.service
Listing out the status of all the unit files.
1 systemctl list-units
Listing out the status of a particular unit file.
1 systemctl list-units sshd.service
Both systemctl list-units and systemctl list-unit-files can be appended with –type for particular type of unit file.
1 2 systemctl list-units --type=target systemctl list-unit-files --type=path
Among all the unit file types, socket has it’s own command to list out.
1 systemctl list-sockets
Show a unit’s dependencies.
1 systemctl list-dependencies crond.service
Working with services
Commands to start, stop and showing status.
1 2 3 systemctl stop crond systemctl status crond systemctl start crond
Commands to reload, restart.
1 2 systemctl reload crond systemctl restart crond
Commands to enable and disable service at system start up.
1 2 systemctl disable crond systemctl enable crond
From the image we learn that to start or stop a service is actually just putting or removing a symlink of the unit file at
A quick peep of
Checkout the current runlevel where
multi-user.target equals to runlevel init 3.
1 systemctl get-default
Commands to change runlevel.
1 systemctl set-default graphical.target
We can tell from the message that the runlevel is also a symlink linked to default.target.
Viewing log messages
Lastly, command to view all service logs.
To view log of particular service.
1 journalctl -u crond.services
To view the real time log. The image shows the real time log pop out when I try to login the demo server.
1 journalctl -f