Module 12. Service Management

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

MANAGING INSTALLED SERVICES

❖ Services are programs (called daemons) that once started run continuously in the background
and are ready for input or monitor changes in your computer and respond to them. For example
the Apache server has a daemon called httpd (the d is for daemon) that listens on port 80 on
your computer and when it receives a request for a page it sends the appropriate data back to
the client machine.

❖ Many services are required to run all the time however many can be safely turned off for both
security reasons as running unnecessary services opens more doors into your computer, but also
for performance reasons. It may not make much difference but your computer should boot
slightly faster with less services it has to start on boot.

❖ One of the techniques in every Linux administrator’s toolbox to improve security of a box is to
turn off unneeded services.

CHKCONFIG and SERVICE Commands

There are 2 commands used to control services:

❖ service - This controls the starting and stopping of services during a session, these setting are
not saved. If you start Apache this way but it is not set to start on boot using the above method
then it will continue to run but on next boot will not start automatically.

❖ chkconfig - This controls which services are set to start on boot, by their nature these setting are
saved and are applied at next boot. Changing these settings will not start the service
immediately; it will just flag them to be started from the next boot.

The command use for maintaining a service is:

#service <name of the service> status --- To check the status of the service
#service <name of the service> start --- To start the service
#service <name of the service > stop --- To stop a service
#service <name of the service> reload --- To reload the service
#service <name of the service> restart --- To restart the service

The command use for service availability is:

#chkconfig - -list --- To check the availability of service


#chkconfig <service> on --- To make the service available after restart
#chkconfig <service> off --- To make the service unavailable after restart

Yoinsights Technologies Pvt. Ltd. Call Us: +91- 0261-6888890/8140206060


1 www.yoinsights.com; [email protected]
Service Management (systemd) – RHEL 7
Prior to Redhat Enterprise Linux 7 operating system, init was the process which is responsible for
activating the other services in the system. There were daemons and many system V LSB scripts
were started at the boot time. These are mostly likely the shell scripts which resides under the
/etc/init.d directory and called on the different run levels. But this system has lot of limitation which
has been addressed on RHEL 7, with the new init system called “systemd”. In Redhat Enterprise
Linux 7, Systemd owns the process ID 1.

Highlights of systemd:

❖ It supports the Parallelization which increases the system boot time.


❖ Systemd creates the sockets for each daemons and it just needs to connect to the sockets.
❖ Automatic service dependency management which can prevent long time-outs.
❖ A method of tacking related processes together by using Linux control groups.
❖ Still RHEL 7 supports the shell scripts for few legacy services. (/etc/init.d).

Service Management with systemctl:

1. To list all the available services on the system, use the below command.

[root@yoinsights ~]# systemctl --type=service

2. To check the specific service status

[root@yoinsights ~]#systemctl status upower.service


[root@yoinsights ~]#systemctl status sshd.service

3. To list the active state of all loaded units, use the below command.

[root@yoinsights ~]#systemctl list-units --type=service

4. To list the active and inactive state of all loaded units, use the below command.

[root@yoinsights ~]#systemctl list-units --type=service -all

5. The below command will help you that whether the service will be started automatically or not.

[root@yoinsights ~]#systemctl list-unit-files --type=service

Note: Below table shows different status of service.

Yoinsights Technologies Pvt. Ltd. Call Us: +91- 0261-6888890/8140206060


2 www.yoinsights.com; [email protected]
Keyword Description
loaded Unit configuration file has been processed.
active(running) Running with one or more continuing processes
active(exited) Successfully completed a onetime configuration
active (waiting) Running but waiting for an event
inactive Not running
enabled Will be started at boot time
disabled Will not be started at boot time
Cannot be enabled but may be started by an enabled unit
static
automatically

6. You can filter the failed services using the systemctl command with below mentioned options.

[ROOT@YOINSIGHTS ~#systemctl --failed --type=service

7. To list the all sockets units on the system,

[ROOT@YOINSIGHTS ~]#systemctl list-units --type=socket --all

Controlling the services with systemctl:


1. Check the crond service status.

[ROOT@YOINSIGHTS ~]#systemctl status crond.service

2. To stop the service, use systemctl stop command.

[ROOT@YOINSIGHTS ~]#systemctl stop crond.service

3. Service can be started back using systemctl start command.

[ROOT@YOINSIGHTS ~]#systemctl start crond.service


[ROOT@YOINSIGHTS ~]#systemctl status crond.service

4. Specific service can be restarted using “systemctl restart” command.

[ROOT@YOINSIGHTS ~]#systemctl restart crond.service


[ROOT@YOINSIGHTS ~]#echo $?
0
[ROOT@YOINSIGHTS ~]#systemctl status crond.service

Yoinsights Technologies Pvt. Ltd. Call Us: +91- 0261-6888890/8140206060


3 www.yoinsights.com; [email protected]
5. If you use the restart command, process ID will be changed. But if you use “reload” option, it re-
reads the configuration without a complete stop and start. So the process ID remains same.

[ROOT@YOINSIGHTS ~]#systemctl status sshd.service |head -8

6. To see the service dependency tree, use the below command.

[ROOT@YOINSIGHTS ~]#systemctl list-dependencies crond.service

7. To prevent the service from starting at the boot time, use systemctl disable command.

[ROOT@YOINSIGHTS ~]#systemctl disable crond.service

The same way, if you want to start the specific service at the system boot time, use systemctl enable
command.

[ROOT@YOINSIGHTS ~]#systemctl enable crond.service

8. To disable the service permanently, use “systemctl mask” command.

[ROOT@YOINSIGHTS ~]#systemctl mask crond.service

systemctl – cheat sheet:


Task command
To see the status of specific service systemctl status service_name
To stop the specific service systemctl stop service_name
To start the specific service systemctl start service_name
To restart the service systemctl restart service_name
To reload the service systemctl reload service_name
To completely disabled service. (can’t be started
systemctl mask service_name
even manually
Enable the service from mask systemctl unmask service_name
To start the service at boot time systemctl enable service_name
Disable the service at boot time systemctl disable service_name
List the dependencies for the service systemctl list-dependencies service_name

Yoinsights Technologies Pvt. Ltd. Call Us: +91- 0261-6888890/8140206060


4 www.yoinsights.com; [email protected]
How to stop/start and disable/enable Firewall
To check the status of firewall

#systemctl status firewalld

To start/stop firewall

#systemctl start/stop firewalld

To start/stop firewall permanently or at boot time

#systemctl enable/disable firewalld

To allow service in firewall

#firewall-cmd --permanent --add-service=nfs


#firewall-cmd --permanent --add-service=mountd
#firewall-cmd --permanent --add-service=rpc-bind

Yoinsights Technologies Pvt. Ltd. Call Us: +91- 0261-6888890/8140206060


5 www.yoinsights.com; [email protected]

You might also like