RHEL Services

Service and chkconfig

This is the older style of working with services is to use the services and chkconfig commands, if possible you should use the newer systemctl commands below

chkconfig
chkconfig <service> --list
chkconfig on <service>
chkconfig off <service>

chkconfig --levels 234 <service> on
chkconfig --levels 234 <service> off

chkconfig --add <service>
chkconfig --remove <service>
service
service <service> status
service <service> start
service <service> stop
service <service> restart

service <service> --status-all

Systemd

This is the newer style of working with services and replaces the old service and chkconfig commands

Directory stucture and service files
/etc/systemd				                        # global config dir
/usr/lib/systemd/system			                        # unit/configuration files
/etc/systemd/systems			                        # target directories with links to service (unit) files

ls -l /usr/lib/systemd/system/ |grep target	                # list targets
ls -l /usr/lib/systemd/system/ |grep service	                # list service (also have mount, automount, path, socket, timer, slice)
Version
systemctl --version				                # version
Boot time information
systemd-analyze					                # boot time
systemd-analyze blame				                # boot time for each service (unit)
systemd-analyze critical-chain			                # critical chain boot timings
systemd-analyze critical-chain sshd.service 	                # specific service (unit) boot timings
Dependancies
systemctl list-dependencies					# List of service (unit) dependancies (text graphics)
systemctl list-dependencies sshd				# dependancies of a specific service (unit)
systemctl list-dependencies graphical.target | grep target	# dependancies of a specific target
Systemd handles the system event log through Journald
journalctl					                # display system events log
journalctl /sbin/crond				                # display events for crond
journalctl /sbin/sshd				                # display events for sshd (lots more)
journalctl -u chronyd				                # display events for a specific service
journalctl -b					                # display events since last reboot
journalctl -k					                # display kernel events
journalctl --since=today		                        # display events since for today
journalctl -p err				                # display events with a priority (0/emerg upto 7/debug)
journalctl -f					                # tail events
journalctl --list-boots			                        # list recent reboots
journalctl --disk-usage				                # display disk usage by journalctl
Systemd organizes processes in control groups
systemd-cgls							# system control groups
systemd-cgtop							# system control group top (monitoring/performance)

systemctl list-units -all					# Detailed list of all services (units)
systemctl list-units -all --state=[inactive|active]		# Same as above but with specific state
systemctl list-units -all --type=[service|target|mount|device]	# Same as above but type is a specific service, device, target or mount, etc 
systemctl list-unit-files					# List all services (units)
systemctl list-units --type=target				# List all types (ideal for runlevels)
systemctl --failed						# List all failed services (units)
 
systemctl cat sshd						# List service unit file (how it starts, kill comand, etc)
systemctl edit sshd --full					# Edit unit file above					
systemctl show httpd						# show a service properties (i.e restart, timeouts, controlPID)
systemctl kill httpd						# kill a service
systemctl mask httpd						# Stops a service automatically or manually being started (links to dev/null)
systemctl unmask httpd						# unmasks a service (see above line)

systemctl enable sshd						# Enable a service (adds symlink to service from /etc/systemd/system to /usr/lib/systemd/system)
systemctl disable sshd						# Disable a service (removes symlink from /usr/lib/systemd/system)
systemctl start sshd						# Start a service
systemctl stop sshd						# Stop a service
systemctl status sshd						# get status of service
systemctl restart sshd						# Restart a service
systemctl reload sshd						# Reload a service
systemctl reload-or-restart					# Service will either be reloaded or restarted

systemctl is-enabled sshd					# is service started at boot (chkconfig)
systemctl is-active sshd					# is service running
systemctl is-failed sshd					# has service failed
systemctl daemon-reload						# reload a service after a change
Service state
enabled 							# explicitly installed 
static 								# installed as dependency (cannot be enable or disable manually)
disabled 							# not installed
target and Runlevels
who -r								# Get current runlevel
runlevel							# Get current runlevel
systemctl list-units --type=target				# Identify runlevel types
systemctl rescue						# Move to Maintenance mode
systemctl isolate runlevel3.target				# Move to runlevel 3 
systemctl isolate multi-user.target				# Move to runlevel 3 (multi-user)
systemctl isolate graphical.target				# Move to runlevel 5 (graphical)
systemctl get-default						# Get default runlevel (/etc/systemd/system/default.target which is a symlink to a target)
systemctl set-default graphical.target				# Set default runlevel

systemctl poweroff						# Power off server
systemctl reboot						# Reboot server
systemctl suspend						# Suspend server
systemctl hibernate						# Hibernate server
Traditional runLevelv New Target Name
Runlevel 0      |    runlevel0.target -> poweroff.target
Runlevel 1      |    runlevel1.target -> rescue.target
Runlevel 2      |    runlevel2.target -> multi-user.target
Runlevel 3      |    runlevel3.target -> multi-user.target
Runlevel 4      |    runlevel4.target -> multi-user.target
Runlevel 5      |    runlevel5.target -> graphical.target
Runlevel 6      |    runlevel6.target -> reboot.target