enable & disable services in linux

How to Enable & Disable Services in Linux

Linux allows you to add, enable & disable services to automate your tasks & processes. Sometimes you may need to enable or disable services in Linux, sometimes you may need to run them automatically on boot. In this article, we will look at how to enable & disable services in Linux.


How to Enable & Disable Services in Linux

There are a couple of commonly used utilities to manage services in Linux – systemd & upstrat init. We will look at how to enable & disable services using each of these tools. We will enable/disable apache2 server in Linux using these utilities.


1. Using Systemd init

Latest versions of Linux contain this tool, instead of upstart init. So this is the recommended way to manage services on your system.

Enable service

Here is the syntax to enable service using systemd.

$ sudo systemctl enable service-name

Here is an example command to enable apache2 service using systemd.

$ sudo systemctl enable apache2

Disable Service

Here is the syntax to disable service using systemd.

$ sudo systemctl disable service-name

Here is an example command to disable apache2 service using systemd.

$ sudo systemctl disable apache2

Start service

Here is the syntax to start service using systemd.

$ sudo systemctl start service-name

Here is an example command to start apache2 service using systemd.

$ sudo systemctl start apache2

Restart service

Here is the syntax to restart service using systemd.

$ sudo systemctl restart service-name

Here is an example command to restart apache2 service using systemd.

$ sudo systemctl restart apache2

Stop service

Here is the syntax to stop service using systemd.

$ sudo systemctl stop service-name

Here is an example command to stop apache2 service using systemd.

$ sudo systemctl stop apache2

Get status of service

Here is the syntax to get status service using systemd.

$ sudo systemctl status service-name

Here is an example command to get status apache2 service using systemd.

$ sudo systemctl status apache2


2. Using Upstart Init

Enable service

Here is the syntax to enable service using upstart init

$ sudo init enable service-name
OR
$ sudo service enable service-name

Here is an example command to enable apache2 service using init.

$ sudo init enable apache2
OR
$ sudo service enable apache2

Disable service

Here is the syntax to disable service using init.

$ sudo init disable service-name
OR
$ sudo service disable service-name

Here is an example command to disable apache2 service using init.

$ sudo init disable apache2
OR
$ sudo service disable apache2

Start service

Here is the syntax to start service using init.

$ sudo init start service-name
OR
$ sudo service start service-name

Here is an example command to start apache2 service using init.

$ sudo init start apache2
OR
$ sudo service start apache2

Restart Service

Here is the syntax to restart service using init.

$ sudo init restart service-name
OR
$ sudo service restart service-name

Here is an example command to restart apache2 service using init.

$ sudo init restart apache2
OR
$ sudo service restart apache2

Stop service

Here is the syntax to stop service using init.

$ sudo init stop service-name
OR
$ sudo service stop service-name

Here is an example command to stop apache2 service using init.

$ sudo init stop apache2
OR
$ sudo service stop apache2

Get status

Here is the syntax to get status service using init.

$ sudo init status service-name
OR
$ sudo service status service-name

Here is an example command to get status apache2 service using init.

$ sudo init status apache2
OR
$ sudo service status apache2

As you can see it is very easy to enable/disable/start/stop/restart services in Linux using systemd or upstart init tools. They both have very similar syntaxes. You can use either of them according to your requirement. Older versions of Linux had upstart init, which was phased out in favor of systemd init. So it is advisable to use systemd init to manage your processes.

Leave a Reply

Your email address will not be published. Required fields are marked *