Different distributions have different methods for managing services. Even within the same distribution, different versions may have different service management techniques. For example, RHEL 6 and RHEL7 use different commands to manage services.
Check out how to manage and restart Linux services in the following article by Mytour.
Stopping Services on Linux
Use the commands below to stop services on Linux. Note the corresponding commands for different distributions:
# service
# systemctl stop
# stop
Here
Newer versions have implemented systemctl to replace the service command. Even when using the service command in RHEL7, it also calls systemctl.
In the output above, you can see the systemctl command being executed within the service command. Additionally, note that it adds .service to the service_name provided to the service command.
Old service commands like RHEL6 and below print OK (indicating success) or FAILED (indicating failure) statuses for start, stop, or restart operations. The systemctl command does not print any output on the console.
Running Services on Linux
To run services on Linux, you use the following commands:
# service
# systemctl start
# start
Restarting Services on Linux
Use the following commands:
# service
# systemctl restart
# restart
These commands will stop the services and then restart them on Linux from scratch. Essentially, these commands are a combination of stopping and starting services on Linux.
Most commands will reload the edited configuration and restart the service on Linux. However, it can be done without reloading supporting services. This can be achieved by using the reload option instead of restart.
Checking the status of services on Linux
Checking the service status informs you whether the service is currently running or not. Different distributions provide different details about services in the status output. Below are a few examples for your reference.
Checking the status of services lets you know if the service is currently running. Different distros provide different details about services in the status output. Below are some examples for your reference.
- Checking service status information on Ubuntu:
Use the following command:
# service cron status
â cron.service - Regular background program processing daemon
Loaded: /lib/systemd/system/cron.service (enabled; vendor preset: enabled)
Active: Active (running) since Friday 2017-03-10 17:53:23 UTC; 2 seconds ago
Docs: man:cron(8)
Main PID: 3506 (cron)
Tasks: 1
Memory Usage: 280.0K
CPU Usage: 1ms
CGroup: /system.slice/cron.service
ââ3506 /usr/sbin/cron -f
Mar 10 17:53:23 ip-172-31-19-90 systemd[1]: Started Regular background program processing daemon.
Mar 10 17:53:23 ip-172-31-19-90 cron[3506]: (CRON) INFO (pidfile fd = 3)
Mar 10 17:53:23 ip-172-31-19-90 cron[3506]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
The command above will display detailed service status information, man page, PID, CPU, MEM, and recent events from the log.
- Checking service status information on RHEL6:
# service crond status
crond (pid 1474) is running...
The command above will display the PID and status of the service.
- Checking service status information on RHEL7:
# systemctl status crond.service
â crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2017-03-10 13:04:58 EST; 1min 2s ago
Main PID: 499 (crond)
CGroup: /system.slice/crond.service
ââ499 /usr/sbin/crond -n
Mar 10 13:04:58 ip-172-31-24-59.ap-south-1.compute.internal systemd[1]: Started Command Scheduler.
Mar 10 13:04:58 ip-172-31-24-59.ap-south-1.compute.internal systemd[1]: Starting Command Scheduler...
Mar 10 13:04:58 ip-172-31-24-59.ap-south-1.compute.internal crond[499]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 85% if used.)
Mar 10 13:04:59 - System Alert!
Unravel the hidden metrics Ubuntu conceals, from CPU usage to memory consumption, with this command.
Discover All System Services
To inspect all running services and their statuses on your system, employ the following commands:
# Check all services status (for RHEL6 and older, Ubuntu, CentOS, Debian, Fedora).
# List all units using systemctl (for RHEL7).
This command will provide you with a comprehensive list of all services and their statuses along with additional details.
Here's how you manage and restart services on Linux. If you're new to this operating system, learn how to create a Linux bootable USB in Windows using Universal USB Installer. If you have any questions, feel free to leave them in the comments below, and Mytour will address them as soon as possible.
For Windows users, optimizing your computer's performance can involve disabling unnecessary services. For detailed steps, refer to how to disable unnecessary services in Windows here.