Enable or Disable systemd Services in Ubuntu
Learn about starting and stopping systemd services in Ubuntu. You'll also learn how to auto-start services after system restarts.
Most of the popular Linux distros including Fedora, Ubuntu, and Arch use systemd as an init service which is used to manage services using the systemctl command.
And in this guide, I will walk you through the following:
- How to enable systemd services (auto start at boot)
- How to disable systemd services
- How to start systemd services (run the service)
- How to stop systemd services
- How to restart systemd services (stop and run the service)
Check the status first
Before you jump on the shown methods to enable or disable the services, it is important to know the current status of the service.
To check the service, you'd have to use the status
flag with the systemctl command as shown here:
systemctl status <service_name>
For example, here, I checked the status of the Apache service:
systemctl status apache2
How to enable systemd services in Ubuntu
To enable a service, all you have to do is execute the systemctl command in the following manner:
systemctl enable <service_name>
Let's say I want to enable apache
service, then, I will be using the following command:
sudo systemctl enable apache2
Now, you can check the status of the service by using the status
flag as shown:
systemctl status <service_name>
As you can see, the service is not active yet as enabling it will start the service when the Ubuntu system reboots next.
But what if you want to start the service imminently? Here's how you do it.
How to start the systemd services in Ubuntu
As I mentioned earlier, even if you want to start the service immediately, you'd have to use the start
flag as shown:
systemctl start <service_name>
For example, if I want to start the apache
, then, I will be using the following:
sudo systemctl start apache2
And now, if you check the status, it will be active and running:
How to disable systemd services in Ubuntu
By disabling the system, you can prevent automatic activation at every boot and to do so, you'd have to use disable
flag with the systemctl command as shown:
sudo systemctl disable <service_name>
For example, here, I have disabled the Apache service:
sudo dystemctl disable apache2
But if you check the status of the service, it would be still running:
Why? Because the changes will be applied after the next boot.
How to stop systemd services in Ubuntu
As I mentioned above, disabling the service won't get you an immediate effect so if you want to stop the service immediately, here's how to do it.
To stop the service, you'd have to use the stop
flag with the systemctl command as shown here:
sudo systemctl stop <service_name>
As I want to stop the Apache service, I will be using the following:
sudo systemctl stop apache2
And now, if you check the status, the service will be stopped:
You can create a systemd service on your own
In case you don't know, you can create a systemd service as per your needs. Want to know how? Here's a detailed guide:
I hope you will find this helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.