How to Get the Current Status of a Running Service on the Terminal in Ubuntu
This is an article about understanding how to check and manage the status of services running on your Linux system, particularly when using the Ubuntu distribution. In this piece, we will focus on the command-line methods available for checking service statuses directly from the terminal. This guide assumes you have a basic familiarity with Linux commands and directory structures.
In this article, you will find information about:
- The importance of monitoring services in an Ubuntu system.
- A brief overview of how services are managed in modern Linux distributions like Ubuntu.
- Command-line tools such as systemctl and their usage for checking service status.
- Specific examples with step-by-step instructions on how to monitor common services, including Apache (web server), MySQL/MariaDB (database management systems), and SSH (secure shell) services.
Read this article to find out about the various methods you can use to check if your Ubuntu system’s services are running correctly from the terminal interface. Whether you’re a beginner or an experienced Linux user, knowing how to manage service statuses is essential for maintaining the health of your system and troubleshooting issues efficiently.
Importance of Monitoring Services in an Ubuntu System
Ubuntu, like other modern Linux distributions, relies heavily on systemd as its init system and service manager. It allows users to start, stop, restart, enable/disable services at boot time, and check their statuses easily. Ensuring that essential services are running correctly is crucial for maintaining the stability and security of your Ubuntu machine.
Monitoring service status helps in several ways:
- Troubleshooting: If a web server or database crashes unexpectedly, checking its status can help identify issues quickly.
- Maintenance: Regular checks ensure that all necessary background processes are functioning as intended.
- Security: Keeping track of services running on your system aids in identifying potential security risks, such as unmonitored open ports and unnecessary service installations.
Overview of Service Management Tools in Ubuntu
Ubuntu uses systemd for managing its services. One of the most important tools provided by systemd is the systemctl command, which allows users to manage units (services, sockets, devices, mount points, automount points, swap files, timers) and query system state.
In modern Linux distributions like Ubuntu 16.04 LTS onwards, systemd has replaced traditional init systems such as SysVinit or Upstart. This transition brought with it a new way of managing services via the command line:
- Enabling Services: Use systemctl enable <service-name> to configure a service to start automatically at boot.
- Starting and Stopping Services: Commands like systemctl start <service-name> initiate a service, while systemctl stop <service-name> halts it.
- Restarting Services: The command systemctl restart <service-name> is useful when you need to reload configuration changes without interrupting service operation.
Using Systemctl to Check Service Status
To check the status of any given service in Ubuntu, the most straightforward tool is systemctl. Here’s how to use it effectively:
Step 1: Open a Terminal
Open your terminal application or log into your Ubuntu system via SSH. You will need sufficient permissions (typically root or sudo access) to view detailed service statuses.
Step 2: Use Systemctl Command
The primary command used here is systemctl. To check the status of any given service, use:
Replace <service-name> with the name of the service you wish to monitor. Common examples include “apache2” (Apache web server), “mysql” or “mariadb” (database servers), and “ssh” (secure shell daemon).
Step 3: Interpret Output
After running the command, systemctl will return a detailed status report of your specified service. Look for lines indicating:
- Active: Whether the service is active (running) or inactive.
- Loaded: If the service has been loaded successfully and its configuration files are available.
For example:
This output tells you that the Apache HTTP Server is currently running and has been loaded properly.
Detailed Examples
Example 1: Checking Status of Apache Web Server
To monitor your web server, type:
Look for lines indicating whether Apache (httpd) is active and running. If there are any issues, they will be listed here first.
Example 2: Verifying MySQL or MariaDB Database Service
For database management services like MySQL/MariaDB:
or if you’re using MariaDB specifically,
The output should confirm whether your DBMS is active and running.
Example 3: Checking SSH Daemon Status
To ensure that remote access via Secure Shell remains enabled, run:
or for the newer naming convention used in some systems,
Conclusion
Understanding how to manage and monitor services using systemctl commands is fundamental when administering an Ubuntu server or desktop environment. Regular checks ensure your system operates smoothly, and quick troubleshooting is made possible through these simple terminal operations.
By following the steps outlined in this article, you can efficiently check on essential service statuses directly from the command line, making it a vital skill for both novice and experienced Linux users alike.
Last Modified: 24/05/2019 - 02:28:38