Resolve systemctl errors caused by a non-systemd init system or a corrupted systemd configuration.
Symptom
Running systemctl on a Linux instance returns one of the following errorsas follows:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to get D-Bus connection: xxx xxx.
Cause
systemctl is the command-line tool for systemd, the Linux init system and service manager. These errors occur for the following reasons:
-
The system does not use systemd as its init system.
-
Some older or lightweight Linux distributions (such as Devuan, Alpine Linux, or Void Linux) use other init systems (such as OpenRC, SysVinit, or runit) by default. For example, Windows Subsystem for Linux (WSL) uses SysVinit by default.
-
If you run the command inside a Docker or Podman container that is not configured to use systemd, this error occurs.
-
-
The system uses systemd, but systemd is corrupted or misconfigured.
Solution
-
Connect to the Linux instance.
-
Check whether the system uses systemd as its init system:
ps -p 1 -o comm=-
The output is empty or not systemd: The system does not use systemd. Use the service management commands for the current init system.
NoteIf you need
systemctlscripts, use a Linux distribution that supports systemd, or run a systemd-enabled Linux system in a Docker container.For example, if the system uses SysVinit (output is init), use the
servicecommand instead ofsystemctl. The following table compares common commands:Operation/command
SysVinit
Systemd
Start service
sudo service service_name startsudo systemctl start service_nameStop service
sudo service service_name stopsudo systemctl stop service_nameRestart service
sudo service service_name restartsudo systemctl restart service_nameCheck service status
sudo service service_name statussudo systemctl status service_nameEnable auto-start
sudo chkconfig service_name onsudo systemctl enable service_nameDisable auto-start
sudo chkconfig service_name offsudo systemctl disable service_name -
The output is systemd: The system uses systemd. If the error persists, systemd may be corrupted or misconfigured. Refer to the official documentation for your distribution to recover the systemd service.
-