Part 2 – Service management, Systemd

Last time we were just getting to know the main Linux interface, the console. Today we are going to get our hands on service management.
Let’s start with the basics. What the hell is a service in the context of Linux? A service is an application ( In some cases a set of applications. ) that is running in the background carrying out its tasks.

It can be a server ( Apache ), an ssh service ( OpenSSH ), or the network manager that is controlling your notebook’s wifi ( Very imaginatively named NetworkManager. )
These are usually tasks that need to be running in the background constantly for understandable reasons. Why I’m telling you this? Because in Linux you can easily control these services via the console. And unlike windows, you do not have to reboot the whole system if a service fails/freezes or needs to be restarted.

There are two major systems that allow you to control services in Linux. The SysV-Init and Systemd.

 

A little history:

SysV-Init is the older one, and it’s really not a complex system, it just runs the given script under /etc/init.d. There were debates why any distribution should allow Systemd to take over the SysV-Init system. While all the SysV-Init people understood that the old system needed to be replaced, many noted correctly that Systemd is more than just a replacement, it’s a complete software suite that takes over several elements of the system and that is going against Linux philosophy. (Every system should be modular and for one purpose only.) More on that in a different article.

 

 

Since most Linux distributions nowadays use systemd, we will be looking at that one. And while I understand those who object to it, it is a better system in my opinion and today it is more widely used. First, let’s see what kind of services systemd sees in our system.

command: systemctl status

 

As you can see this command lists all the registered services in the system regardless of its state.
State? Let me elaborate. All services have a given state. These can be: enabled, disabled, active, failed. The first two needs some explanation. An enabled service means that it will be started on boot up. Disabled means it won’t be started at boot up.

 


You can filter the services that are active. And you can also ask for a list of services that are not loaded or failed to load along with running services. This can be seen below:

Command: systemctl list-units –all –state=inactive

To list active services only just use the command : systemctl list-units.

 

 

You can get detailed information about a specific service. I demonstrated this with the NetworkManager service.

Command: systemctl status servicename

 

 

You also can check for a given service dependency. This is useful if a service failed to start. You might want to check if it was because a given dependency also failed to load.

Command: systemctl list-dependencies servicename

 

 

Now we know how to check service states. But how do we set the states? Easy.
Each service has to be set individually thought.

The commands to those can be found in the list below:

systemctl enable servicename

systemctl disable servicename

systemctl start servicename

systemctl stop servicename

systemctl restart servicename

All of them are self-explanatory.
I hope you guys found this article helpful! With this knowledge, you should be able to handle most service related problems you come across. If you have any questions feel free to contact us.

Take care!
HostMyGuild

Author HostMyGuild
Published
Categories Hosting Linux VPS
Views 95

Comments

No Comments

Leave a Reply