Get started Bring yourself up to speed with our introductory content.

Master Linux service management on System V and systemd

Managing services on Linux is an essential task for administrators. Learn to work with either System V or systemd.

If you're a Windows administrator with a few Linux servers, or a new administrator starting out on Linux, you need...

to learn how to start, stop and check services. Recent changes have made Linux service management more complicated.

Several items used on Linux were invented in the old days of Unix. One of these is the System V procedure for starting services, which has been the dominant Linux service management method until recently.

In System V, as well as in Upstart service management (a recent enhancement of System V), services are managed through init scripts. These complicated shell scripts are in the directory /etc/init.d and are used for starting, stopping and monitoring service availability.

To manage services in System V, use the service command followed by the name of the service and the action you want to perform on it. For example, service httpd status allows you to monitor current availability of the httpd Web server. This approach works well on most Linux distributions that were not released in the last year.

System V uses runlevels to determine which services start when a server boots. A runlevel is the state in which a server starts, indicated with a number. Runlevel 5 typically enters a full graphical mode, while runlevel 3 only offers a text-based shell.

To add services to a runlevel, use chkconfig, followed by the name of the service and on or off, as in chkconfig httpd on. A service normally knows in which runlevel it should start, so it's unnecessary to add more.

Systemd

In the last year, most Linux server OSes switched to systemd. Systemd is a smarter way to start services, because the service starts automatically when it is needed. To manage services in systemd, use systemctl, followed by the action you want to perform on the service, then the name of the service. An example of a systemctl command is systemctl status httpd (see the output in listing 1).

Listing 1. An example of Linux service availability monitored with systemctl. Note: Some lines are ellipsized, use -l to show in full.

[root@localhost ~]# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: active (running) since Wed 2014-12-17 06:06:21 EST; 3s ago
Main PID: 63117 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─63117 /usr/sbin/httpd -DFOREGROUND
├─63118 /usr/sbin/httpd -DFOREGROUND
├─63119 /usr/sbin/httpd -DFOREGROUND
├─63120 /usr/sbin/httpd -DFOREGROUND
├─63121 /usr/sbin/httpd -DFOREGROUND
└─63122 /usr/sbin/httpd -DFOREGROUND
Dec 17 06:06:21 localhost.localdomain httpd[63117]: AH00558: httpd: Could not reliably determine the se...age
Dec 17 06:06:21 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

As systemd directly connects to logging service journald, systemctl displays more detailed information about the current service status. Where service httpd status only shows if the service is or is not running, systemctl status httpd provides information about the actual state of the service.

Using systemctl to start and stop services is simple. For example, use systemctl start httpd to start the httpd service, or systemctl stop httpd to stop it.

Systemd eliminates runlevels. To administer services, tell the server if the service should or should not be available via systemctl enable servicename or systemctl disable servicename commands. For example, if your Web server needs to be available after a server reboot, use systemctl enable httpd.

About the author:
Sander van Vugt is an independent trainer and consultant based in the Netherlands. He is an expert in Linux high availability, virtualization and performance. He has authored many books on Linux topics, including
Beginning the Linux Command Line,Beginning Ubuntu LTS Server Administration andPro Ubuntu Server Administration.

Next Steps

Linux beginners: Start with the basics of distributions and management, then master essential commands.

Gain more Linux expertise with vi/vim commands, and shake off these unhelpful myths.

This was last published in February 2015

Dig Deeper on Linux servers

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

6 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What distribution of Linux OS do you use on data center servers?
Cancel
CentOS 7
Cancel
Currently there is no best Linux distribution business serves. Rather, they are compartmentalized to fit your company’s needs. Linux OS comes with a good maintenance lifetime that provides patches and updates of the product as they get to the market. Therefore, it is best to consider the support for applications, hardware and troubleshooting that comes with the Linux distribution of your choice. Nonetheless, you can look into free Linux distributions too.
Cancel
CentOS 6, Debian Wheezy and CentOS 7
Cancel
Debian, Open Suse and fredora server
Cancel
I think Upstart still uses the same service manager, systemed. This may be short-lived, as systemd is likely to prevail over Upstart without init daemon.
Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchEnterpriseLinux

SearchServerVirtualization

SearchCloudComputing

Close