Understanding Systemd and How to Use It: Part 2

In part one, you learned a little about what systemd is and which Linux distributions plan to use it. In part 2, you will learn how to use systemd to start and stop services. We will use Red Hat Enterprise Linux, CentOS and Fedora in the explanation, but most of it will apply to other distributions that use systemd as well.

With the old init system, you could use the “service” command to start and stop services. For example, to restart Apache, you would type from the command line:

service httpd restart

The more direct way of doing it was to find the actual init script in /etc/rc.d/init.d and restart it using that script. The service command has now been replaced by the systemctl command. For now, you can still use the “service” command, and the OS will just remind you that it is no longer the standard way.

[root@serverschool ~]# service sshd restart

Redirecting to /bin/systemctl restart sshd.service

Service scripts now have the “.service” extension, and you can use them by executing the systemctl command:

systemctl restart httpd.service

The important thing to note is that the action is now listed before the script. You would type “start httpd.service” rather than typing “httpd start”.

For more information about the systemctl command, see this documentation.