Managing services on a Linux server is essential for any DevOps/System administrators job requirements. Sometimes we want to shutdown a service permanently; Like Apache, or MySQL. We do not want it restarted automatically when we reboot the server. Or we want to make a service automatically enabled. Using systemctl makes the job a lot easier.
The standard way to do that is using systemd process. Which is now available on most Linux distros. On Ubuntu 15.x on wards, including 16.04 and above versions, this can be easily accomplished using systemctl command line tool provided through systemd.
Here are some helpful commands to help you through systemctl. All the following commands must be run either as sudo or root.
To check the status if the service is enabled or disabled
systemctl is-enabled SERVICE
systemctl is-enabled apache2
If the apache2 service is enabled, we may get a response similar to the following:
Executing /lib/systemd/systemd-sysv-install is-enabled apache2
If the service is disabled, then we will get a response back saying it is “disabled”.
If you want to check if the service is currently active or inactive:
systemctl is-active service
And if we want to check the status of the service, if it is currently running:
systemctl status service
If we want to see all the information related to a service, regardless of it being active/inactive.
systemctl show service
Disabling/Stopping a Service
systemctl disable SERVICE
For example of mysql. The service Mysql will be disabled and will not start even on reboot.
systemctl disable mysql
If we simply want to stop a service. The service will start again after reboot with the following command:
systemctl stop SERVICE
Enabling a Service
systemctl enable SERVICE
For example of apache2. The service Apache will be enabled and will automatically start on reboot.
systemctl enable apache2
If we want to start the service, we type the following commend. Once we reboot, the service will not be automatically started.
systemctl start SERVICE
If we want to restart the service for any reason without needing to shut it down
systemctl restart SERVICE
If we want to reload the config files without actually interrupting the service processes, the we run the following command.
systemctl reload SERVICE
Techie by day, blogger by night. Love the outdoors, enjoy traveling and building new and interesting things. Follow me if you want to know something.