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.
It is important to know/list out all the installed 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.
systemctl list-unit-files sshd.service
Listing out the status of all the unit files.
Listing out the status of a particular unit file.
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.
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.
Show a unit’s dependencies.
systemctl list-dependencies crond.service
Working with services
Commands to start, stop and showing status.
systemctl stop crond systemctl status crond systemctl start crond
Commands to reload, restart.
systemctl reload crond systemctl restart crond
Commands to enable and disable service at system start up.
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.
Commands to change runlevel.
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.
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.