Services
are essential background processes that are usually run while booting up and shut down with the Operating Systems. This post will show you two
different ways in which you can manage services in Debian and Debian
based Linux distros like Ubuntu and so on.
systemd vs init
Debian/Ubuntu and many other distributions these days use systemd instead of the good old init.
In systemd, you manage services with systemctl command.
In init, you manage service with the service command.
You maybe noticed that even though your Linux system uses systemd, it is still able to use the service command (intended to be used with init system). This is because service command is actually redirected to systemctl. It’s sort of backward compatibility introduced by systemd because sysadmins were habitual of using the service command.
Method 1: Managing services in Linux with systemd
systemd vs init
Debian/Ubuntu and many other distributions these days use systemd instead of the good old init.
In systemd, you manage services with systemctl command.
In init, you manage service with the service command.
You maybe noticed that even though your Linux system uses systemd, it is still able to use the service command (intended to be used with init system). This is because service command is actually redirected to systemctl. It’s sort of backward compatibility introduced by systemd because sysadmins were habitual of using the service command.
Method 1: Managing services in Linux with systemd
You can use the systemd command to list all the services on your Linux system:
systemctl list-unit-files --type service -all
2. Start a service
To start a service in Linux, you just need to use its name like this:
systemctl start <service-name>
Eg: sudo systemctl start apache2
3. Stop a service
To stop a systemd service, you can use the stop option of systemctl command:
systemctl stop <service-name>
Eg: sudo systemctl stop apache2
4. Restart a service
To restart a service in Linux with systemd, you can use:
systemctl restart <service-name>
Eg: sudo systemctl restart apache2
5. Check the status of a service
You can confirm that you have successfully executed a certain action by printing the service status:
systemctl status <service-name>
Eg: sudo systemctl status apache2
Method 2: Managing services in Linux with init
1. List all services
To list all the Linux services, use
service --status-all
2. Start a service
To start a service in Ubuntu and other distributions, use this command:
service <service-name> start
Eg: sudo service apache2 start
3. Stop a service
Stopping a service is equally easy.
service <service-name> stop
Eg: sudo service apache2 stop
4. Restart a service
If you want to restart a service, the command is:
service <service-name> restart
Eg: sudo service apache2 restart
5. Check the status of a service
Furthermore, to check if your intended result was achieved, you can output the service status:
service <service-name> status
Eg: sudo service apache2 status
Reference: https://itsfoss.com/start-stop-restart-services-linux/