How to Use Linux List Services to Effectively Manage Running Services in 2024

An operating system requires programs that run in the background called services. In a Linux system, these services are called daemons. They are managed using an init system like systemd.

System administrators must understand how to use Linux list services to efficiently manage and troubleshoot their servers. It helps ensure their virtual private server (VPS) hosting performs optimally and securely.

This article will explain how to use different init system commands in Linux to list services. You will also learn how to manage the services and other best practices for effective Linux system administration.

How to Use Linux List Services

This section will explain different methods to list running services in Linux.

To run Linux commands in a remote server, connect using an SSH client or Terminal and log in as a root user.

Pro Tip

Hostinger VPS users can connect to their remote server and execute commands directly in hPanel using the browser terminal.

How to List Linux Services with Systemctl

Most modern Linux systems use systemd an init system and service manager for controlling daemons. It is a drop-in replacement for older distributions’ init processes.

Systemd has the systemctl command, which lets users manage their system and service configurations. For example, use it to list all unit files in your Linux server:

sudo systemctl list-unit-files --type service --all
The systemctl command listing all unit files

Terminal will list unit files with the service type in a tabular format, including their state and vendor preset.

Service state is the systemd units’ operational status. The most common ones are:

  • Enabled – active services running in the background.
  • Disabled – disabled services that users can enable directly using the start command.
  • Masked – stopped services that can only be started by removing the masked property.
  • Static – services that only run when another program or unit requires them.
  • Failed – inactive services that can’t load or operate properly.

Meanwhile, the vendor preset is a service’s default configuration, which determines whether it starts during the boot time or not. You can also use the systemctl list-units command to list properly loaded services:

sudo systemctl list-units --type service --all

A unit includes all processes in systemd, including system services, devices, and mounts. Use the –type flag to list only the service unit type.

Pro Tip

Unlike list-units, the systemctl list-unit-files command lists installed unit files or each systemd process’s configuration. Since it shows all services regardless of their startup condition, listing unit files is more suitable for checking the installed daemons.

You can combine systemctl with the grep command or –state option to filter a specific Linux service status. Here are the service filtering techniques:

sudo systemctl list-unit-files --type service | grep status
sudo systemctl list-unit-files --type service –-state=status
The systemctl command returning only enabled services

Don’t forget to replace status with your current unit file state. For example, use enabled to only list running services that are loaded properly. You can also filter units, but the status may differ:

sudo systemctl list-units --type service –-state=status
The systemctl command returns units with enabled status

You can print only the last few lines by combining systemctl with the tail command. For example, run the following to output the last 10 enabled services:

sudo systemctl list-unit-files --type service –-state=enabled | tail

How to List Services on Linux Using the Service Command

Older Linux operating systems use a different service manager called System V. To manage services in this init system, use the service command.

For example, run the following to list all daemons:

service --status-all
The service command listing all system services and their statuses

The command will also show the services’ statuses using symbols. The symbols may differ depending on the Linux distribution. These are the most common ones:

  • [+] – an active service.
  • [-] – inactive or disabled services.
  • [?] – the service’s status is unknown.

Use the grep command to filter running services based on their status. For example, here’s the command to list running services:

sudo service --status-all | grep "+"

Replace the + symbol to list unknown or inactive units. Note that services with unknown status may also be included when you filter running or disabled services.

You can determine the status of a specific service using its name:

sudo service service-name status

Pro Tip

Several distributions with systemd, like Debian 8.0, may also provide SysV as an alternative. This means you can list services using systemctl and service.

How to List Linux Services With Service Management Tools

Some Linux distributions and versions use alternate service management tools besides systemd and System V. A popular example is Upstart, included in Ubuntu 14.04, Fedora 9, Red Hat Linux Enterprise 6, and its derivatives.

To list all services with Upstart, use the initctl command:

sudo initctl list
The initctl command listing system services and their statuses

Terminal will list running instances with their identification ID and current status. Common service statuses in Upstart include:

  • Running – loaded services that are currently running.
  • Stopped – disabled services due to user command or by design.
  • Killed – unintentionally stopped services due to a process interruption or termination signal.
  • Starting – services that are about to run.
  • Waiting – instances that are waiting for a trigger event to start.

You can use grep to filter the service based on their status. The syntax is similar to the service or systemctl command:

initctl list | grep running

Other Linux distributions – including Gentoo, Funtoo, Alpine, and Hyperbola – use the OpenRC service manager.

To list services in an OpenRC system, use the rc-status command:

rc-status
The rc-status command listing system services and their statuses

Depending on your distribution, the output may differ slightly. Commonly, it will show the system’s current runlevel and each service’s status, such as:

  • Started – currently running, active services.
  • Stopped – intentionally terminated services.
  • Crashed – loaded services that encountered an error and have stopped.
  • Failed – services that couldn’t start.
  • Inactive – inactive services at the current runlevel.

Add the grep command to filter services based on their status. To check service status at another system runlevel, change the default one using this command:

rc runlevel

How to Manage Linux Services

Managing Linux services is crucial for your system performance, security, and functionality.

For example, terminating unnecessarily resource-intensive services can minimize hardware usage and optimize your system performance.

Another crucial management task is restarting services. It allows you to clear the loaded services in the system memory and ensure updates are applied properly.

Service management commands differ depending on the init system. We will use systemctl for this tutorial as it is more commonly used in modern Linux distributions.

To start or stop Linux services with systemctl, run one of the following.

sudo systemctl start service-name
sudo systemctl stop service-name

Replace service-name with the actual name of your service.

To run masked services, remove the property first using the unmask command.

For managing startup services, use the following:

sudo systemctl enable service-name
sudo systemctl disable service-name
Terminal's output after enabling a service with systemctl

Before enabling and disabling running services, check whether other daemons or applications depend on them. Disabling a dependency may cause a service to crash, resulting in system instability. To check service dependencies, use the following command:

sudo systemctl list-dependencies service-name
A list of SSHD service dependencies

You can also list reverse dependency – services that depend on the one you are checking. Here’s the command:

sudo systemctl list-dependencies --reverse service-name
A list of SSHD service reverse dependencies

To modify a service’s configuration, use the grep, awk, and sed commands. grep locates the pattern in the configuration file that needs modification. Meanwhile, awk retrieves the value, and sed replaces the target string with the new value.

Pro Tip

Unsure how to write a command for your needs? Use Hostinger’s GPT-powered Kodee AI assistant to easily generate code, commands, and instructions to manage your server.

Another method to manage Linux services in a VPS is to use a hosting control panel, which offers a visual interface. Graphical service management is suitable for beginners because it’s simpler than using a command-line interface.

Hostinger offers various control panels, including Virtualmin, Webmin, and Plesk. Note that the available templates differ depending on your VPS plans’ virtualization.

Hostinger VPS users can easily install the control panel by choosing a template via the Operating System menu in the VPS management area. To learn more, check out our guide on changing your VPS operating system.

Warning! Back up your VPS files before switching to another template. This process will wipe your data.

Linux Service Management Best Practices

In this section, we will explain several Linux service management best practices to help you maintain your system’s performance and security efficiently.

Review the Configuration of Each Service on a Regular Basis

An update may change a service’s default configuration, impacting how it behaves and affecting system performance. Some service options may also be deprecated due to updates.

Regularly checking each service configuration helps you change obsolete settings to ensure the service works properly and meets current security standards.

Moreover, regular checkups help determine which service to tweak when implementing new changes to your server or hosted applications. It ensures the current service configuration meets the new system requirements.

Remove or Disable Services That Are No Longer Required

Unnecessary running services can waste resources and slow down your website. Disabling them lets you allocate resources more efficiently, resulting in a more consistent server performance.

In addition, they may also expose your server to cyber attacks. Aside from opening extra ports, they may be outdated and contain unpatched security flaws.

Other than minimizing the cyber attack surface, disabling or removing services simplifies security audits and troubleshooting because there will be fewer instances to analyze.

Finally, it also reduces service conflict errors and potential misconfigurations.

Warning! Don't remove or disable services without understanding the consequences. Always test it in a development environment first to avoid breaking the production server.

Maintain Detailed Documentation for Each Service

A Linux VPS can have up to hundreds of active services. Hence, maintaining detailed documentation is crucial for server management. You must track information about each service’s name, purpose, configuration options, and dependencies.

For a team, documentation helps onboard new members, allowing them to easily understand the system’s setup. It also lets them accurately replicate the current production environment when setting up a new VPS or local staging area.

Documentation also simplifies server backup and restore, as you can track which services to install and their configurations. Moreover, it is useful for troubleshooting purposes as you can check which services are modified.

To create documentation, use the > director to output the systemctl command results in a file. For example, use the following command to create a file containing a service list:

sudo systemctl list-unit-files --type service --all > service_list.txt

Understand the Dependencies Between Services

Before disabling or modifying a service, you must understand its dependencies and which daemons rely on it. This helps prevent other services from crashing, which may cause chain reactions that compromise your system’s stability.

For instance, your hosted web application depends on the PHP-FPM service, which relies on the Apache httpd daemon. If you disable Apache httpd, PHP-FPM will crash, and the web application will stop working.

Since multiple services may rely on one daemon, tracking the root cause can be difficult. We recommend mapping a service’s dependency before disabling it for easier debugging.

Monitor the Health and Performance of Services

Monitoring a service’s health and performance helps you identify issues before they cause performance decline and downtime. It also gives you important data for service logs and diagnostics.

In addition, Linux service monitoring helps determine whether new system changes or updates negatively affect performance. To check service status, use the following systemctl command:

sudo systemctl status service-name

Replace service-name with the name of the service. Terminal will show its description, load state, process ID, hardware usage, and service logs.

The systemctl command returns the status of a service

We recommend complementing it with other tools for a more in-depth and accurate analysis. Popular options for such tools include Prometheus with Grafana and New Relic.

Conclusion

Services or daemons are Linux programs that run in the background. System administrators must understand how to manage services to maintain their server’s functionality and performance.

The commands to list services differ depending on the Linux init system. Systemd service listing uses systemctl, while System V utilizes service. Moreover, service control tools like Upstart and OpenRC use initctl and rc-status, respectively.

In addition to listing, these commands are useful for boot-time service control and managing instances. Users can also check service status by combining them with the grep command.

To improve server security and performance, regularly check your service configuration files and disable unnecessary ones. Before doing so, always check their dependencies and create documentation to avoid errors and simplify the restoration process.

Author
The author

Aris Sentika

Aris is a Content Writer specializing in Linux and WordPress development. He has a passion for networking, front-end web development, and server administration. By combining his IT and writing experience, Aris creates content that helps people easily understand complex technical topics to start their online journey. Follow him on LinkedIn.