http://linuxtab.blogspot.com/2015/12/rhel7-comparison-of-service-utility.html
RHEL7 - Controlling Services and Daemons
Listing unit files with systemctl
List available units on your system
# systemctl -t help
1. Find the state of all unit
# systemctl
2. Find the state of all available service unit on your system.
# systemctl --type=service
3. Find the status of a service
# systemctl status sshd.service -l
–l option to gives you detail output.
=> List only failed services
# systemctl –failed –type=service
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
4. Check if particular unit is active and enabled to start at boot time.
# systemctl is-active sshd
# systemctl is-enabled sshd
5. List the active state of all loaded units.
# sytsemctl list-units –type=service
List all inactive/inactive state of loaded units
# systemctl list-units –type=service –all
6. Find if unit is enable to start automatically up on reboot or not
# systemctl list-unit-files --type=service
state Description
------ ------------
loaded unit configuration file has been processed
active(running) Running with one or more continuing processes
active(waiting) Running but waiting for an event
active(existed) Successfully completed a one-time configuration
inactive not running
enabled will be started at boot time
disabled will not be started at boot time
static Can not be enabled, but may be started by an enabled unit
automatically
Service status
1. Check the status of a service.
# systemctl status
2. Verify that the process is running.
# ps –up PID
3. Stop the service and verify the status
# systemctl stop sshd.service
# systemctl status sshd.service
4. Start the service and view the status. The process ID will change
# systemctl start sshd.service
# systemctl status sshd.service
5. Stop, then start, the service in a single command.
# systemctl restart sshd.service
# systemctl status sshd.service
6. Reload a service after config file change
# systemctl reload sshd.service
# systemcl status sshd.service
Note: When you restart, process ID will be changed. But when you reload, it
re-reads the configuration without a complete stop and start. So the process
ID remains same.
7. Find the service depencendy tree
# systemctl list-dependencies sshd.service
8. Disable the service and verify the status.
# systemctl disable sshd.service
# systemctl status sshd.service
Note that disabling a service does not stop the service. It only prevents the
service from starting at the boot time.
Masking services
To prevent accidentally starting a service, we can mask the service. Basically
masking will create a link in the configuration directories so that if the
service is started nothing will happen.
To mask the service
# systemctl mask crond.service
# systemctl mask crond
# systemctl unmask crond
note: The disabled service does not start automatically at boot time but it
can be started manually. A masked service does not start manually or
automatically.
1. View the status of a service.
# systemctl status sshd.service
2. Disable the service and verify the status. Note that disabling a service
does not stop the service.
# systemctl disable sshd.service
# systemctl status sshd.service
3. Enable the service and verify the status.
# systemctl enable sshd.service
# systemctl is-enable sshd.service
Cheat sheet on systemctl commands
Check the status of a service
# systemctl status service_name
Stop a service
# systemctl stop service_name
Start a service
# systemctl start service_name
Restart a service
# systemctl restart service_name
Reload a service
# systemctl reload service_name
Mask a service to prevent the change on service
# systemctl mask service_name
Enable mask service (unmask a serice)
# systemctl unmask service_name
Enable a service to start at boot time
# systemctl enable service_name
Disable a service from starting at boot time.
# systemctl disable service_name
List dependencies of a service
# systemcl list-dependencies service_name
List the all sockets units on the system,
# systemctl list-units --type=socket --all
RHEL7 - Controlling Services and Daemons
Listing unit files with systemctl
List available units on your system
# systemctl -t help
1. Find the state of all unit
# systemctl
2. Find the state of all available service unit on your system.
# systemctl --type=service
3. Find the status of a service
# systemctl status sshd.service -l
–l option to gives you detail output.
=> List only failed services
# systemctl –failed –type=service
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
4. Check if particular unit is active and enabled to start at boot time.
# systemctl is-active sshd
# systemctl is-enabled sshd
5. List the active state of all loaded units.
# sytsemctl list-units –type=service
List all inactive/inactive state of loaded units
# systemctl list-units –type=service –all
6. Find if unit is enable to start automatically up on reboot or not
# systemctl list-unit-files --type=service
state Description
------ ------------
loaded unit configuration file has been processed
active(running) Running with one or more continuing processes
active(waiting) Running but waiting for an event
active(existed) Successfully completed a one-time configuration
inactive not running
enabled will be started at boot time
disabled will not be started at boot time
static Can not be enabled, but may be started by an enabled unit
automatically
Service status
1. Check the status of a service.
# systemctl status
2. Verify that the process is running.
# ps –up PID
3. Stop the service and verify the status
# systemctl stop sshd.service
# systemctl status sshd.service
4. Start the service and view the status. The process ID will change
# systemctl start sshd.service
# systemctl status sshd.service
5. Stop, then start, the service in a single command.
# systemctl restart sshd.service
# systemctl status sshd.service
6. Reload a service after config file change
# systemctl reload sshd.service
# systemcl status sshd.service
Note: When you restart, process ID will be changed. But when you reload, it
re-reads the configuration without a complete stop and start. So the process
ID remains same.
7. Find the service depencendy tree
# systemctl list-dependencies sshd.service
8. Disable the service and verify the status.
# systemctl disable sshd.service
# systemctl status sshd.service
Note that disabling a service does not stop the service. It only prevents the
service from starting at the boot time.
Masking services
To prevent accidentally starting a service, we can mask the service. Basically
masking will create a link in the configuration directories so that if the
service is started nothing will happen.
To mask the service
# systemctl mask crond.service
# systemctl mask crond
# systemctl unmask crond
note: The disabled service does not start automatically at boot time but it
can be started manually. A masked service does not start manually or
automatically.
1. View the status of a service.
# systemctl status sshd.service
2. Disable the service and verify the status. Note that disabling a service
does not stop the service.
# systemctl disable sshd.service
# systemctl status sshd.service
3. Enable the service and verify the status.
# systemctl enable sshd.service
# systemctl is-enable sshd.service
Cheat sheet on systemctl commands
Check the status of a service
# systemctl status service_name
Stop a service
# systemctl stop service_name
Start a service
# systemctl start service_name
Restart a service
# systemctl restart service_name
Reload a service
# systemctl reload service_name
Mask a service to prevent the change on service
# systemctl mask service_name
Enable mask service (unmask a serice)
# systemctl unmask service_name
Enable a service to start at boot time
# systemctl enable service_name
Disable a service from starting at boot time.
# systemctl disable service_name
List dependencies of a service
# systemcl list-dependencies service_name
List the all sockets units on the system,
# systemctl list-units --type=socket --all
No comments:
Post a Comment