When working with services in a distroDepending on the type of system you are using (SysV init, Upstart, systemd,…), the way in which services can be stopped, started, stopped, restarted, etc., could vary. It is a point where many doubt how it is actually done, and the fact that there are several different systems does not help some more inexperienced users, who try to do it with the wrong command.
Therefore, I am going to show a simple tutorial with which it will be clearer to you how you can work in your distro, whatever it is. To do this, the first thing you must be clear about is the type of demon you are using. As I said, not all distros use the same startup system type. In fact, as you know, some have opposed the new systemd and have generated forks or derivatives with the old SysV, as is the case with Devuan compared to Debian ...
How do I know the system my distro uses? Well, you can find out by looking for these routes, and if you have them, you will have that system in your distro:
- To know if you have systemd: find the path / usr / lib / systemd
- To know if you have Upstart: find this other path / usr / share / upstart
- To know if you have SysV init: find the path /etc/init.d
- There othersEven if it is somewhat rarer, in those particular cases, you can do something similar if you suspect that they are not the above.
Another way to make it even easier, because it is the same for everyone, it is to look for info in / proc about the PID = 1, that is, the first process from which the rest hang and which corresponds precisely to this startup daemon. To do this, just run the following command and it will return the name:
sudo stat /proc/1/exe
Now you know what system you have, therefore, let's the commands you can use to manage services:
- SysV init: /etc/init.d/[service_demon_name] [action]
- systemd: systemctl [action] [daemon_name]
- Upstart: service [service_demon_name] [action]
- Others: If you use a different system, you'd better look at the manual. For example, some rare cases on Linux and other Unixes may use the signal from the SIGHUP process to reset a service: kill -HUP $ (cat / var / run / [service-PID])
You should replace [action] for what you need to do. For example, if you need to restart, then use reset, if you want to stop use stop, if you want to start use star, etc. And replace [daemon_name] with the daemon name of the service you want to start. For example:
systemctl reset httpd
I hope you have it clearer now.