Starting, Stopping, and Reloading Services

Linux-based dedicated servers typically run two primary types of programs: those which require user interaction and those which perform tasks in the background without user intervention. Those programs that run in the background are commonly called “services” or “daemons”.

Servers usually require numerous services to run the background, such as the web server, mail server, database server, DNS system, firewall, and possibly many others. Because of this, it is important to know how to manage services, including how to start, stop, restart, and check their status.

The available methods for starting and stopping services may vary according to Linux distributions. On the most popular server distributions, Red Hat Enterprise Linux and CentOS, there are two commonly-used ways for starting and stopping them. The first is to call the programs directly:

/etc/init.d/service-name start

The other method is to use the “service” command, which will usually work for anything found in the “/etc/init.d” directory. Therefore, if you wanted to start the same service using this method, you would type as root:

service service-name start

To stop a service, type:

service service-name stop
/etc/init.d/service-name stop

To check the status of a service (i.e. see if it is currently running):

service service-name status
/etc/init.d/service-name status

To restart a service, type:

service service-name restart
/etc/init.d/service-name restart

Some services may have additional command settings available. To find out which ones are available, type the command without anything after it. For example:

service rsync

Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}

Once a service that was not running starts, it will continue to run as long as the service stays on. If you reboot, only services that have beenĀ configured to start at boot will run initially.