Troubleshoot systemctl errors on a Linux instance

更新时间:
复制 MD 格式

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

  1. Connect to the Linux instance.

    See Log on to a Linux instance using Workbench.

  2. 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.

      Note

      If you need systemctl scripts, 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 service command instead of systemctl. The following table compares common commands:

      Operation/command

      SysVinit

      Systemd

      Start service

      sudo service service_name start

      sudo systemctl start service_name

      Stop service

      sudo service service_name stop

      sudo systemctl stop service_name

      Restart service

      sudo service service_name restart

      sudo systemctl restart service_name

      Check service status

      sudo service service_name status

      sudo systemctl status service_name

      Enable auto-start

      sudo chkconfig service_name on

      sudo systemctl enable service_name

      Disable auto-start

      sudo chkconfig service_name off

      sudo 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.