Comparison of the service Utility with systemctl
service | systemctl | Description |
---|---|---|
service name start | systemctl start name.service | Starts a service. |
service name stop | systemctl stop name.service | Stops a service. |
service name restart | systemctl restart name.service | Restarts a service. |
service name condrestart | systemctl try-restart name.service | Restarts a service only if it is running. |
service name reload | systemctl reload name.service | Reloads configuration. |
service name status | systemctl status name.service systemctl is-active name.service | Checks if a service is running. |
service --status-all | systemctl list-units --type service --all | Displays the status of all services. |
source: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html
Comparison of the chkconfig Utility with systemctl
chkconfig | systemctl | Description |
---|---|---|
chkconfig name on | systemctl enable name.service | Enables a service. |
chkconfig name off | systemctl disable name.service | Disables a service. |
chkconfig --list name | systemctl status name.service systemctl is-enabled name.service | Checks if a service is enabled. |
chkconfig --list | systemctl list-unit-files --type service | Lists all services and checks if they are enabled. |
chkconfig --list | systemctl list-dependencies --after | Lists services that are ordered to start before the specified unit. |
chkconfig --list | systemctl list-dependencies --before | Lists services that are ordered to start after the specified unit. |
Notes:
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
---------------------------------------
# list failed services that are failed during boot
# systemctl --failed
check if service is enabled or not
systemctl is-enabled ssh
Reboot/poweroff
# systemctl halt/reboot/poweroff /suspend/hibernate
# journalctl --> check log
shows logs since the start of machine
# journalctl -b --> journal file/logging from this boot.
if you want to see specific unit log
Show logs for specific service unit
# journalctl -u ssh
===============
Display the status of all services
# systemctl list-units --type service --all
List all the services that will be started when booting into graphical mode.
# systemctl list-dependencies graphical.target | wc -l
===============================
List units: sockets, services and more
# systemctl list unit
get only services
# systemctl list unit | grep .service
List all the services and check if they are enabled
# systemctl list-unit-files --type service
No comments:
Post a Comment