Managing Services in Linux using Systemd
Services also called daemons are programs, software or scripts that run behind the scene without any trigger, interaction or control by the users. They perform predefined tasks and provide support for starting, running and stopping processes, servers and other services. Even though these services lack an interface, they are highly essential for the secure and smooth performance of functions in the operating system.
There are many command line tools which can be used to manage these services. These tools perform similar functions in their collective nature but sometimes, their functions can be distinctive, serving a peculiar need. Again, some of the tools like upstart, SysV init, and chkconfig is not effective in some distros while some like systemd, service and systemctl are effective in every distribution. This article is focused on service management using systems.
Systemd
A system is a set of tools for many activities, but its main job is to initialize, control, and monitor system services during the boot process and at runtime. With the help of the system, system users can easily and effectively establish and manage services in the operating system.
Systemd is stored by default in the /user/bin and /etc directory.
Working with systemd
- To see if systemd is currently enabled in your Linux and if the processes it is managed,
$ ps -ef | grep systemd
- Analyzing boot time with systemd (how long it takes your system to go through the boot process)
$ systemd-analyze
- To see the processes that take the longest time to start up
$ systemd-analyze blame
systemctl
This is one of the utilities of systemd which manages both system, system configurations, service controls, and management in Linux. There are more than 20 use cases for the systemctl. This article shall explore a few of them.
I have an apache2 web server configured in my Linux.
- To check if the server is currently running
$ systemctl status apache2
- To get my server running (this command will start the server. With my localhost, I can view my website from the browser). This command is temporal, a turn-off on your system will automatically shut the server down. This will require authentication.
$ systemctl start apache2
- To stop apache2 from running
$ systemctl stop apache2
- To make a service run automatically from system boot. As with the start, this will need authentication to get apache enabled. $ systemctl enable apache2
- To disable apache2 from starting on boot.
$ systemctl disable apache2
- To check if apache2 is configured to start each time my system boots
systemctl is-enabled apache2
- To see all the service unit - loaded, inactive, running and
$ systemctl list-units –type=service –all