olly - Fotolia
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.
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).
[[email protected] ~]# 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..."
├─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: AH00558: httpd: Could not reliably determine the se...age
Dec 17 06:06:21 localhost.localdomain systemd: 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, includingBeginning the Linux Command Line,Beginning Ubuntu LTS Server Administration andPro Ubuntu Server Administration.
Gain more Linux expertise with vi/vim commands, and shake off these unhelpful myths.