Restarting Services From the Command Line

One of the more common tasks that needs to be done on live servers is restarting services(such as Apache, mail, ftp, and DNS). A few of the reasons for services needing to be restarted can vary from the service crashing, the load on the server being too high, or a restart to make a configuration change take affect.

There are two different ways that can be used to interact with services in a Linux environment:

The first is to use the service command to issue commands to the service you wish to work with. For example: service httpd restart This will issue a restart command to Apache.

The second would be to directly interact with the init script on the server. An example of this would be, /etc/init.d/httpd restart This will issue a restart command to Apache.

As demonstrated above, both commands will result in the same action and since both commands will yield the same result, usage comes down to personal preference.

Each service typically at the least has stop, start, restart, and status usage flags. However, some services have other usage flags that can be used to determine more information about how the service is currently performing. One example of this would be the configtest usage flag for Apache. Using this flag it is possible to test the current configuration for any errors. Using this flag it is possible to verify any changes made to the Apache configuration will cause Apache not to start without having to restart Apache.

Below are some examples of various common services and their usage flags:

Apache

One of the primary reasons Apache may need to be restarted would be after changes have been made to the configuration file in order to optimize performance. More information on optimizing Apache is located here.