On Linux systems, you can use different commands to start, stop, and restart services, depending on which system and service manager you are using. Here are some common service managers and their corresponding commands:
Use systemctl (Systemd). Systemd is the initialization system and service manager used by most modern Linux distributions such as CentOS 7 and above, Ubuntu 16.04 and above, Fedora, etc.
Start the service:
sudo systemctl start service_name.service
Replace service_name with the name of the service you want to start.
Stop service:
sudo systemctl stop service_name.service
To restart the service:
sudo systemctl restart service_name.service
View service status:
sudo systemctl status service_name.service
Make the service run automatically at startup:
sudo systemctl enable service_name.service
Prevent the service from running automatically at startup:
sudo systemctl disable service_name.service
Using service (System V init)
In some older Linux distributions, such as CentOS 6 and below, the service command is used to manage services.
Start the service:
sudo service service_name start
Stop service:
sudo service service_name stop
To restart the service:
sudo service service_name restart
View service status:
sudo service service_name status
Use invoke-rc.d
invoke-rc.d is another command for managing services on older Debian and Ubuntu systems.
Start the service:
sudo invoke-rc.d service_name start
Stop service:
sudo invoke-rc.d service_name stop
To restart the service:
sudo invoke-rc.d service_name restart
When executing these commands, you may need to have root privileges or elevate privileges using sudo. Be sure to replace service_name with the actual service name you want to manage. Some services may require specific configurations or dependencies to start properly, so make sure all the necessary configurations are set up correctly before starting the service.
Using these commands, you can control the start, stop, and restart of services in most Linux distributions.