Photon OS manages services with
systemctl, its command-line utility for inspecting and controlling the system. It does not use the deprecated commands of
Basic system administration commands on Photon OS differ from those on operating systems that use SysVinit. Since Photon OS uses systemd instead of SysVinit, you must use systemd commands to manage services.
For example, instead of running the /etc/init.d/ssh script to stop and start the OpenSSH server on a init.d-based Linux system, you control the service by running the following systemctl commands on Photon OS:
systemctl stop sshd
systemctl start sshd
For an overview of systemd, see systemd System and Service Manager and the man page for systemd. The systemd man pages are listed at https://www.freedesktop.org/software/systemd/man/.
1 - Enabling 'systemd' Debug Shell During Boot
systemd related boot issues, you can enable early shell access during boot.
Perform the following steps to enable early shell access:
Restart the Photon OS machine or the virtual machine running Photon OS.
When the Photon OS splash screen appears, as it restarts, type the letter
systemd.debug-shell=1 to the kernel command line.
Optionally, to change logging level to debug, you can append
F10 to proceed with the boot.
Alt+Ctrl+F9 to switch to
tty9 to access the debug shell.
2 - Troubleshooting Services With 'systemctl'
To view a description of all the active, loaded units, execute the systemctl command without any options or arguments:
To see all the loaded, active, and inactive units and their description, run this command:
To see all the unit files and their current status but no description, run this command:
grep command filters the services by a search term, a helpful tactic to recall the exact name of a unit file without looking through a long list of names. Example:
systemctl list-unit-files | grep network
For example, to list all the services that you can manage on Photon OS, you run the following command instead of
systemctl list-unit-files --type=service
Similarly, to check whether the
sshd service is enabled, on Photon OS you run the following command instead of
systemctl is-enabled sshd
chkconfig --list command that shows which services are enabled for which runlevel on a SysVinit computer becomes substantially different on Photon OS because there are no runlevels, only targets:
You can also display similar information with the following command:
systemctl list-unit-files --type=service
The following is list of some of the systemd commands that take the place of
SysVinit commands on Photon OS:
USE THIS SYSTEMD COMMAND INSTEAD OF THIS SYSVINIT COMMAND
systemctl start sshd service sshd start
systemctl stop sshd service sshd stop
systemctl restart sshd service sshd restart
systemctl reload sshd service sshd reload
systemctl condrestart sshd service sshd condrestart
systemctl status sshd service sshd status
systemctl enable sshd chkconfig sshd on
systemctl disable sshd chkconfig sshd off
systemctl daemon-reload chkconfig sshd --add
3 - Analyzing System Logs with 'journalctl'
The journalctl tool queries the contents of the systemd journal. On Photon OS, all the system logs except the installation log and the cloud-init log are written into the systemd journal.
When you run the
journalctl command without any parameters, it displays all the contents of the journal, beginning with the oldest entry.
To display the output in reverse order with new entries first, include the
-r option in the command:
journalctl command includes many options to filter its output. For help troubleshooting systemd, two journalctl queries are particularly useful:
Showing the log entries for a systemd service unit.Item
The following command reveals the messages for only the systemd service unit specified by the
-u option, which in the following example is the auditing service:
journalctl -u auditd
You can look at the messages for systemd itself or for the network service:
journalctl -u systemd
journalctl -u systemd-networkd
root@photon-1a0375a0392e [ ~ ]# journalctl -u systemd-networkd
-- Logs begin at Tue 2016-08-23 14:35:50 UTC, end at Tue 2016-08-23 23:45:44 UTC. --
Aug 23 14:35:52 photon-1a0375a0392e systemd: Starting Network Service...
Aug 23 14:35:52 photon-1a0375a0392e systemd-networkd: Enumeration completed
Aug 23 14:35:52 photon-1a0375a0392e systemd: Started Network Service.
Aug 23 14:35:52 photon-1a0375a0392e systemd-networkd: eth0: Gained carrier
Aug 23 14:35:53 photon-1a0375a0392e systemd-networkd: eth0: DHCPv4 address 198.51.100.1
Aug 23 14:35:54 photon-1a0375a0392e systemd-networkd: eth0: Gained IPv6LL
Aug 23 14:35:54 photon-1a0375a0392e systemd-networkd: eth0: Configured
For more information, see journalctl or the journalctl man page by running this command:
4 - Inspecting Services with 'systemd-analyze'
systemd-analyze command reveals performance statistics for boot times, traces system services, and verifies unit files. It can help troubleshoot slow system boots and incorrect unit files. See the man page for a list of options.
5 - Inspecting Services with 'systemd-analyze'
systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as Process ID 1 and starts the rest of the system.
To manage the services run the following commands:
systemctl list-units : This command lists the running units.
systemctl --failed : This command lists failed units.
systemctl list-unit-files : This command lists all the installed unit files. The unit files are usually present in /usr/lib/systemd/system/ and /etc/systemd/system/.
systemctl status pid : This command displays the cgroup slice, memory and parent for a PID.
systemctl start unit : This command starts a unit immediately.
systemctl stop unit : This command stops a unit.
systemctl restart unit : This command restarts a unit.
systemctl reload unit : This command asks a unit to reload its configuration.
systemctl status unit : This command displays the status of a unit.
systemctl enable unit : This command enables a unit to run on startup.
systemctl enable --now unit : This command enables a unit to run on startup and start immediately.
systemctl disable unit : This command disables a unit and removes it from the startup program.
systemctl mask unit : This command masks a unit to make it impossible to start.
systemctl unmask unit : This command unmasks a unit.
To get an overview of the system boot-up time, run the following command:
To view a list of all running units, sorted by the time they took to initialize (highest time on top), run the following command: