Systemd is a popular init system that serves as a management tool for various systems within the Linux operating environment. Through systemd, we can perform essential administrative and maintenance functions, like managing system resources, controlling startup options, logging, and journaling. At the same time, systemctl is a command used to manage systemd services, which are currently standard on Linux.
Lennart Poettering is the person behind the development of systemd, a software engineer who now works at Microsoft. Lennart Poettering previously also created controversial programs, namely Avahi and PulseAudio.
Conventions
# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user
The init system is the first process after the Linux Kernel comes into action in the boot process. It initializes various device management, logging, and networking service. ‘service’ is a legacy command that is used in older versions of Linux/Unix systems. The tool is used to start, stop, and manage system services. It is still available in many modern systems, but most Linux distributions use systemctl
now.
Systemd is indeed controversial for several reasons. Firstly, many people think that systemd doesn’t respect the Unix philosophy. The claim is that systemd is too complex and monolithic, making troubleshooting harder. Secondly, some criticisms of systemd state that systemd is not only an init system but also takes over many functions. For example, systemd tries to manage network, cron, fstab, syslog, etc. This means that systemd is not a program with a singular use but has multiple functions. Finally, systemd is criticized as its logging file isn’t text-based like Unix and Linux logs in common. Instead, it’s a binary log file.
Among the criticisms of systemd mentioned above, some are simply invalid. For example, systemd is not considered modular. Lennart Poettering answers such criticisms on his blog page entitled The Biggest Myths.
Most major Linux distributions like Ubuntu, AlmaLinux, and Gentoo now use systemd as their default init system. Debian was late implementing systemd in their release because many developers rejected it. As a result, several Debian developers who rejected systemd created a new Debian-based distribution, Debian without systemd, called Devuan. Devuan is Debian that still uses sysvinit.
After several years, most would agree that systemd is now a modern system — the opposite of sysvinit. Sysvinit should have disappeared from the init world because managing services through scripts is not easy and complex. Ubuntu once made a replacement for Sysvinit with Upstart but then abandoned it and switched to systemd. Systemd uses a configuration file called a unit. Creating a unit file is also easy because of its ini-style configuration.
systemd Commands
The following are several commands you can use to manage your services using systemd.
To restart a service, use systemctl restart. For example, restart nginx.
# systemctl restart nginx
To start, stop, and reload, replace restart with start, stop, or reload.
Systemctl can also start/stop/restart several services using a single command, for example:
# systemctl restart nginx mysql postfix
To enable service at start-up, use the following command:
# systemctl enable nginx
Alternatively, if instead, you wish to enable the service at start-up and start it right now, you would use:
# systemctl enable --now nginx
To disable service at start-up type
# systemctl disable apache2
If you need to see the systemd file of a service, you can type the following as an example:
# systemctl cat nginx
To restart the server, you should use:
# systemctl reboot
Shutting down the server is using the following command:
# systemctl poweroff
If you wish to view live logs, use:
# journalctl -f
For viewing logs of a service, you can use the following:
# journalctl -u mysql
You can use a command similar to the one below when looking for a specific date range. In this case, we view logs from August 29th to August 31st:
# journalctl --since "2024-08-29" --until "2024-08-31"
Finally, to view the most recent logs, you can use the following command:
# journalctl --since "3 hours ago"
As with the service command, systemctl is a very versatile command. It lets you enable, reload, start, stop, and check the status of services running on your Linux machine. Systemctl serves as an easy-to-use and powerful interface for configuring files in systemd. For example, it only takes one or two commands to disable a service at boot using systemctl.
Service and systemctl mainly have the same purpose. Many of the similarities between the two are intentionally inserted to allow users to make a smoother transition to systemctl. However, there are differences between the two to be aware of when starting work with the initialization system in Linux.
The most significant difference between service and systemctl is that they belong to different initialization systems. Service belongs to the classic Linux initialization process of SysVinit (System V Init). Systemctl belongs to systemd, the successor to SysVinit, and the modern initialization process is used on many Linux systems. Because service and systemctl are part of different initialization processes. They operate on initialization system files in different directories. Service works with the initialization system files found in /etc/init.d. Meanwhile, systemctl works with the initialization system files found in /lib/systemd.
Systemd starts services in parallel rather than serially, so its boot-up time is faster than SysVinit. It also offers slightly more sophisticated control of system daemons via a command-line interface (CLI).
Conclusion
That’s it all! You no longer need to ask what is systemctl and you now know how to use it.
If you have an active service with us, you don’t have to spend your precious time or stress about systemctl. You can contact our expert administrators through chat or by ticket. Our technical support department is available 24×7 and will take care of your request immediately.
If you liked this what is systemctl and how to use it post, please share it with your friends. Thanks.