As a systems administrator, you are tasked to handle quite a lot. And that list grows longer and more complicated every day. To make matters worse, things change. I remember, back in the solar day, to starting time or stop a Linux service, I'd take to open a final window, change into the /etc/rc.d/ (or /etc/init.d, depending upon which distribution I was using), locate the service, and the issue the control /etc/rc.d/SERVICE start|stop|restart (Where SERVICE is the name of the service to be started, stopped, or restarted). When working betwixt Redhat and Debian distributions, that had a tendency to become confusing; I'd try to issue /etc/rc.d/service start on one distribution, simply to notice out it should take been /etc/init.d/service start.

That has changed. How a service is stopped, started, and restarted now makes perfect sense. Even amend, information technology has (for the most role) become universal.

Sort of.

How you start|stop|restart a service will depend upon whether your distribution uses systemd or init. Even then, you might be able to control those services via multiple means. Let me explicate.

systemctl vs. service

This is the crux of the consequence. There are two officially adopted methods for controlling services:

  • systemctl
  • service

Which i you lot apply will depend on if your distribution makes utilize of systemd or init. Near modern distributions have made the switch to systemd, so systemctl is the service manager of choice. Even so, old habits dice hard, so many administrators notwithstanding hold onto the aging service command. Fortunately, the developers of systemd fabricated sure to retain service and redirect it to systemctl. To complicate matters more, you might detect a random service you lot've installed that hasn't been updated to either the service or systemctl tools and have to manually start it from with /etc/rc.d (or /etc/init.d).

So it tin can withal be a bit confusing.

But we're looking for all-time practices hither; and for starting|stopping|restarting applications on Linux, best practices begin and end with systemctl.

systemctl usage

The complexity ends here. In fact, the stopping|starting|restarting of services on Linux is now quite elementary. Let's say nosotros're on CentOS and we want to finish the Apache server. To do this nosotros'd open up a last window and result the control:

sudo systemctl stop httpd

The Apache server would stop and you'd be returned to the bash prompt. To get-go the same service, we'd issue the command:

sudo systemctl commencement httpd

The service would commencement and you'd be returned to your bash prompt.

To restart the same service, we'd issue the control:

sudo systemctl restart httpd

The service would restart and you'd be returned to the fustigate prompt.

The above commands can exist run on CentOS, Ubuntu, Redhat, Fedora, Debian, and many more.

service usage

To brand matters interesting, the service control still works — even for those distributions that have migrated to systemd and systemctl. This means those who instinctively type service, when needing to restart a service on Linux, won't receive an "Unknown command" error. In the case of service, the command will redirect to systemctl. In fact, when you run the service command on a systemctl-enabled distribution, you lot will clearly encounter the redirect information (Effigy A).

Figure A

The service command usage is a bit different from systemctl. The service name and start|cease|restart options are switched:

sudo service httpd showtime
​sudo service httpd cease
​sudo service httpd restart

In each case, you will see service redirected to systemctl, simply the service you are attempted to start|stop|restart will succeed in doing and then.

It'due south not that complicated

I've complicated the result by mentioning the one-time methods of starting, stopping, and restarting services in Linux. Truth exist told, the process of controlling services in Linux is not that complex; you lot only have to understand the right command to utilize.

To larn more near what systemctl can practise you for, make sure to issue the command man systemctl and give the homo folio a read.