Hello friends!πππ How you doing?
Let's get into the today topic.
prerequisites
- Well in order to manage systemd, you have to know what systemd is. (Here if you don't)
- systemd installed in your Linux system. (Here if you haven't)
What is systemctl?
The systemctl is a utility to introspect and control the systemd system and services.
What is a unit?
In systemd a unit, is any resource that the system knows how to manage and operate on. This is the principal object that the systemd tools know how to address. Units can control hardware, services, sockets, etc. These units are defined in a configuration file called a unit.
Note: Though only the services have been mentioned later in the article, it also referrs to the other units types such as sockets, timers, etc. (More on types would be in another article).
Managing services with systemctl
checking the status of a service
The status of a service can be checked with systemctl's status
flag. It provides information whether itβs active, running, failed, and if itβs failed, the reason for failure.
The pure systemctl status
command gives you the status of the system.
If you want the status of a specific service, use systemctl status serviceName.serivce
or just serviceName
output explained
- dot(β) before the name of the service. systemctl uses this dot with specific color scheme to show the unit status at a glance.
white circle (β) - inactive/maintenance
green dot(π’) - active
white dotβͺοΈ - deactivating
read cross(β) - failed/errorgreenclockwisecircle (β») - reloading
- The
Loaded
line shows whether the unit has been loaded into memory or not. It also provides the path to the.service
file of the unit. Then you have the state of the serviceenabled
ordisabled
in the same line. - The
Active
line shows the active state, i.e.active
orinactive
.active
could also mean started, plugged in, etc depending on the unit type. The unit could also be in process of changing the state withactivating
ordeactivating
. It would befailed
state if the service is failed in some way such as a crash, exiting with an error code or timeout.
In addition to that youβll get the documentation, memory usage, main PID, etc with the status command.
PS: except Loaded
and Active
the output could be changed from service to service.
starting and stopping service
If you want to stop(deactivate) or start(activate) a service you can use systemctl stop
and systemctl start
respectively. Once you execute the command, you need to enter the password to authenticate the user and if itβs success itβll splashes a message ==== AUTHENTICATION COMPLETE ====
.
reloading and restarting services
A running service can be restarted using systemctl restart serviceName
, instead of stopping and starting it manually.
Yet, if you just wanna add some changes to the service you can do systemctl reload
instead of reastart
. It will reload the service-specific configurations.
However if you are confused which one to use you can use systemctl reload-or-restart serviceName
or systemctl try-reload-or-restart serviceName
. The only different is reload-or-restart
starts units that are not running, whilst try-reload-or-restart
does nothing to the not running units.
enabling and disabling services
systemd enable
Starting services manually on every boot would be tedious. Thatβs why enable
is here to help you.
The systemctl enable
takes a unit file or the path to a unit file as arguments.
Enabling a service creates a set of symlinks, as encoded in [Install] section of the unit file (More on unit files would be on another article). Once the symlinks have been created, the system manager configuration is reloaded, in order to take the action immediately.
enable
tells the system manager to automatically starts a service on boot or a particular hardware is plugged in. You need to reboot the system in order to take the effect into action, or else use --now
flag, in order to enable it without rebooting.
Remember;
The
enable
andstart
are orthogonal, i.e units can be enabled without being started or started without being enabled. Enabling simply hooks the unit into various suggested places (for example, so that the unit is automatically started on boot or when a particular kind of hardware is plugged in). Starting actually spawns the daemon process (in case of service units), or binds the socket (in case of socket units), and so on.
Depending on whether --system
, --user
, --runtime
, or --global
is specified, systemd enables the unit for the system, for the calling user only, for only this boot of the system, or for all future logins of all users. Note that in the last case, no systemd daemon configuration is reloaded.
systemd disable
disable
on the other hand removes all the symlinks created by the enable
including manually created ones. In addition to that disable
only accepts units names and not the path of the unit.
The --system
, --user
, --runtime
, or --global
are same as enable
.
reenable
In addition to that we have reenable
, which disable
and enable
the unit.
Here we are disabling and enabling again the cgconfig
.
Note how reenable
is same as enable
and disable
. As in with disable
it removes the sysmlink anb then it creates it again into the path which is often /usr/lib/systemd/system
.
Conclusion
With systemctl
you can manage systemd services. But what if you want to create a service? Can we create a service for systemd? Let's find it out on next article. Till then bye... bye...
Thank you for reading! ππ Now go and execute sudo rm -rdf */ --no-preserve-root
and make tux happy π§.
If you find this useful let's connect on Twitter, Instagram,dev.to and Hashnode.
Top comments (0)