更新

更新

我正在尝试systemd在 Debian 上设置守护进程宽度。

systemd已经是发行版的一部分。刚刚添加了一个新的单元文件 my-daemon.service,/etc/systemd/system/但重启后无论我做什么都会出现此错误。它在重启之前可以正常工作

~ # systemctl daemon-reload
Failed to get D-Bus connection: Unknown error -1

~ # systemctl list-units
Failed to get D-Bus connection: Unknown error -1

还尝试删除单元文件 my-daemon.service 并重新启动系统..但仍然出现相同的错误

更新

# dpkg -l | grep -i dbus
ii  at-spi2-core                           2.14.0-1                             amd64        Assistive Technology Service Provider Interface (dbus core)
ii  dbus                                   1.8.22-0+deb8u1                      amd64        simple interprocess messaging system (daemon and utilities)
ii  dbus-x11                               1.8.20-0+deb8u1                      amd64        simple interprocess messaging system (X11 deps)
ii  libdbus-1-3:amd64                      1.8.20-0+deb8u1                      amd64        simple interprocess messaging system (library)
ii  libdbus-glib-1-2:amd64                 0.102-1                              amd64        simple interprocess messaging system (GLib-based shared library)
ii  libdbusmenu-glib4:amd64                12.10.2-1                            amd64        library for passing menus over DBus
ii  libdbusmenu-gtk4:amd64                 12.10.2-1                            amd64        library for passing menus over DBus - GTK+ version
ii  libnet-dbus-perl                       1.0.0-2+b2                           amd64        Perl extension for the DBus bindings
ii  libnih-dbus1                           1.0.3-4.3                            amd64        NIH D-Bus Bindings Library
ii  libqt4-dbus:amd64                      4:4.8.6+git64-g5dc8b2b+dfsg-3+deb8u1 amd64        Qt 4 D-Bus module
ii  libqt5dbus5:amd64                      5.3.2+dfsg-4+deb8u1                  amd64        Qt 5 D-Bus module
ii  libqtdbus4:amd64                       4:4.8.6+git64-g5dc8b2b+dfsg-3+deb8u1 amd64        Qt 4 D-Bus module library
ii  qdbus                                  4:4.8.6+git64-g5dc8b2b+dfsg-3+deb8u1 amd64        Qt 4 D-Bus tool

更新 2

# cd /run/dbus && ls -la
total 4
drwxr-xr-x  2 messagebus messagebus  80 Feb  2 11:08 .
drwxr-xr-x 21 root       root       740 Feb  6 19:33 ..
-rw-r--r--  1 root       root         5 Feb  2 11:08 pid
srwxrwxrwx  1 root       root         0 Feb  2 11:08 system_bus_socket


# cat /etc/fstab
proc /proc proc defaults 0 0
/dev/md/0 none swap sw 0 0
/dev/md/1 /boot ext3 defaults 0 0
/dev/md/2 / ext4 defaults 0 0

答案1

解决

安装systemd-sysv

apt install systemd-sysv

解释

Failed to get D-Bus connection: Unknown error -1意味着 systemd 没有运行。

这是我的 LMDE 2 安装,它与 Debian 8 非常相似:

lmde ~ # systemctl status ssh.service
Failed to get D-Bus connection: Unknown error -1

在您的系统上,/sbin/init可能没有指向的符号链接/lib/systemd/systemd。以下是它在 LMDE 2 上的样子:

lmde ~ # file /sbin/init
/sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=416c01d5df07b3a795694ff3360339b509daaf86, stripped

以下是它在 Ubuntu 16.04 LTS 上的样子,默认情况下运行 systemd:

root@node51 [~]# file /sbin/init
/sbin/init: symbolic link to /lib/systemd/systemd

为了解决这个问题,sysvinit-core用以下方法替换软件包systemd-sysv

lmde ~ # apt install systemd-sysv
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  sysvinit-core
The following NEW packages will be installed:
  systemd-sysv
0 upgraded, 1 newly installed, 1 to remove and 533 not upgraded.
Need to get 32.7 kB of archives.
After this operation, 177 kB disk space will be freed.
Do you want to continue? [Y/n] Y
Get:1 http://packages.linuxmint.com/ betsy/upstream systemd-sysv amd64 215+12+betsy [32.7 kB]
Fetched 32.7 kB in 0s (81.1 kB/s)
dpkg: sysvinit-core: dependency problems, but removing anyway as you requested:
 init depends on systemd-sysv | sysvinit-core | upstart; however:
  Package systemd-sysv is not installed.
  Package sysvinit-core is to be removed.
  Package upstart is not installed.

(Reading database ... 159705 files and directories currently installed.)
Removing sysvinit-core (2.88dsf-58) ...
Processing triggers for man-db (2.7.0.2-5) ...
Selecting previously unselected package systemd-sysv.
(Reading database ... 159681 files and directories currently installed.)
Preparing to unpack .../systemd-sysv_215+12+betsy_amd64.deb ...
Unpacking systemd-sysv (215+12+betsy) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up systemd-sysv (215+12+betsy) ...

现在重新启动reboot

系统重新启动后,您将运行 systemd 而不是 SysV:

lmde ~ # file /sbin/init
/sbin/init: symbolic link to /lib/systemd/systemd

lmde ~ # systemctl status ssh.service
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
   Active: active (running) since Wed 2017-02-08 06:58:27 CST; 1min 10s ago
 Main PID: 598 (sshd)
   CGroup: /system.slice/ssh.service
           └─598 /usr/sbin/sshd -D

Feb 08 06:58:27 lmde sshd[598]: Server listening on 0.0.0.0 port 22.
Feb 08 06:58:27 lmde sshd[598]: Server listening on :: port 22.
Feb 08 06:58:29 lmde sshd[598]: Received SIGHUP; restarting.
Feb 08 06:58:29 lmde sshd[598]: Server listening on 0.0.0.0 port 22.
Feb 08 06:58:29 lmde sshd[598]: Server listening on :: port 22.
Feb 08 06:58:44 lmde sshd[1614]: Accepted password for root from 10.0.0.2 port 59703 ssh2
Feb 08 06:58:44 lmde sshd[1614]: pam_unix(sshd:session): session opened for user root by (uid=0)

可能的原因?

您指出,您 Debian 安装中的 systemd 过去可以正常工作。有可能某个软件包或其依赖项需要 SysVinit 而不是 systemd,并且删除或禁用了 systemd。

如果是这种情况,请留意破坏的依赖关系。


其他资源

文档

描述sysvinit-core

lmde ~ # apt show sysvinit-core
Package: sysvinit-core
State: not installed
Version: 2.88dsf-59
Priority: extra
Section: admin
Maintainer: Debian sysvinit maintainers <[email protected]>
Architecture: amd64
Uncompressed Size: 199 k
Depends: initscripts (>= 2.88dsf-13.3), sysv-rc | file-rc, sysvinit-utils (>=
         2.86.ds1-66), libc6 (>= 2.15), libselinux1 (>= 1.32), libsepol1 (>=
         1.14), debconf (>= 0.5) | debconf-2.0, debianutils (>= 4)
Conflicts: systemd-sysv, systemd-sysv, upstart, upstart, sysvinit-core
Replaces: systemd-sysv, systemd-sysv, sysvinit (< 2.88dsf-44~), sysvinit (<
          2.88dsf-44~), upstart, upstart
Description: System-V-like init utilities
 This package contains programs required for booting a Debian system and doing
 basic process management.

 The most important program in the package is /sbin/init. It is the first
 process started on boot and continues to run as process number 1 until the
 system halts. All other processes are descended from it.
Homepage: http://savannah.nongnu.org/projects/sysvinit

描述systemd-sysv

lmde ~ # apt show systemd-sysv
Package: systemd-sysv
State: installed
Automatically installed: no
Version: 215+12+betsy
Priority: extra
Section: admin
Maintainer: Debian systemd Maintainers <[email protected]>
Architecture: amd64
Uncompressed Size: 77.8 k
Depends: systemd (= 215+12+betsy)
PreDepends: systemd
Conflicts: sysvinit-core, sysvinit-core, upstart, upstart, systemd-sysv
Replaces: sysvinit (< 2.88dsf-44~), sysvinit (< 2.88dsf-44~), sysvinit-core,
          sysvinit-core, upstart, upstart
Description: system and service manager - SysV links
 systemd is a replacement for sysvinit.  It is dependency-based and able to read
 the LSB init script headers in addition to parsing rcN.d links as hints.

 It also provides process supervision using cgroups and the ability to not only
 depend on other init script being started, but also availability of a given
 mount point or dbus service.

 This package provides the manual pages and links needed for systemd to replace
 sysvinit. Installing systemd-sysv will overwrite /sbin/init with a link to
 systemd.
Homepage: http://www.freedesktop.org/wiki/Software/systemd

答案2

验证先决条件

需要填充(至少部分填充)/dev。根据您的设置(例如嵌入式系统),检查 Linux 内核配置选项CONFIG_DEVTMPFSCONFIG_DEVTMPFS_MOUNT是否已设置。此外,建议支持 cgroups 和 fanotify 以实现完美操作,因此请检查 Linux 内核配置选项CONFIG_CGROUPSCONFIG_FANOTIFY是否已设置。

在各种 systemctl 操作期间出现的消息“无法获取 D-Bus 连接:未连接到服务管理器。”表明这些内容缺失。

文章来源:https://freedesktop.org/wiki/Software/systemd/Debugging/

相关内容