Check running services on Linux – – Rackspace

Check running services on Linux

When you need to troubleshoot a network service, the first step is to make sure that the service is running

. If the service

has an initialization script (init) installed, you can use the service command to start, stop, and check the health of the service. This command references a service using its init script, which is stored in the /etc/init.d directory for Debian-based® distributions and in the etc/rc.d/init.d directory for Red Hat-based® distributions.

If you do not know the name that the system uses for a service, check any of the above directories by using the ls command followed by the directory name. Some names vary depending on their distribution. For example, Apache® is httpd on CentOS® and apache2 on Ubuntu OS. Note: Many newer Linux distributions use systemd instead of netstat to verify services. ®

® If you use systemd, replace all service <service-name> <status> commands with systemct1 <status> <service-name>. For more information about systemct1 commands, see the Fedora™ SysVinit to Systemd cheat sheet.

Check the status

of the service

A service can have any of the following states

: Start: The service has

  • started
  • . stop: The service

  • has stopped running
  • .

  • Restart: The service is being restarted and will start after the process is complete.

The following example shows how to check the status of httpd on CentOS by using

the service command: $ sudo httpd service httpd status is stopped

Start

the service

If a service is not running, you can use the service command to start it. The following example starts

the httpd service: $ sudo service httpd start Starting httpd: [ OK ] If the application fails to start

, the system reports the error and usually displays a message indicating the cause of the problem.

$ sudo service httpd start Starting httpd: (98)Address already in use: make_sock: Could not bind to address [:: ]:80 (98)Address already in use: make_sock: Could not bind to address 0.0.0.0:80 No listening sockets available, shutting down Unable to open logs [ERROR]

Use netstat to search for port conflicts

In the example above, httpd cannot be started because something is already listening on the port. To find out what you’re listening to, you can run the netstat command.

Run the following command to display a list of listeners and the ports they are using

: # netstat -plnt Active Internet connections (servers only) Proto Recv-Q Send-Q Local Address Foreign Address PID Status/Program Name tcp 0 0 10.176.77.113:3306 0.0.0.0:* LISTEN 28509/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2113/nc tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1115/master tcp 0 0 :::22 :::* LISTEN 1051/sshd The output shows that the nc program (listed in the

Program Name column) is listening on port 80 (listed in the Local Address column). Stopping this program should allow httpd to start.

Note: For more information about the netstat command, see Check Listening Ports with Netstat.

Check the status

of xinetd If the service is

not running, it may be because a superserver is being used as an extended Internet service daemon (xinetd) to start the program when a connection is received. If this is the case, starting the service might have resolved the problem. Run the following command to verify that the issue is resolved:

$ sudo service xinetd status xinetd (pid 8795) is running…

Check

logs

If you cannot start the service, review the logs to see if they contain information about the problem

.

Next steps

Once you are sure that the application is running, check the server resources to see how much the application consumes.

Contact US