问题
我正在尝试创建一个 CentOS7 systemd 用户脚本 - 以保持多个 VirtualBox VM 处于活动状态。
然而,当我尝试手动测试它时,我得到[1]:
$ systemctl --user start virtualbox.service
Failed to get D-Bus connection: No such file or directory
细节
$ cat /home/qa/.local/share/systemd/user/virtualbox.service
[Unit]
Description=Keep VirtualBox VMs up-and-running
[Service]
ExecStart=/home/qa/start_vms.sh
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
$ cat /home/qa/start_vms.sh
/usr/bin/VBoxManage startvm QAT-116-sonarsql-test-virtualbox --type headless
/usr/bin/VBoxManage startvm QAT-116-oracle12 --type headless
/usr/bin/VBoxManage startvm QAT-116-finder-tests_oori --type headless
$ ls -ls /home/qa/.local/share/systemd/user/virtualbox.service /home/qa/start_vms.sh
4 -rw-rw-r-- 1 qa qa 163 Jun 13 16:58 /home/qa/.local/share/systemd/user/virtualbox.service
4 -rwxrw-r-- 1 qa qa 211 Jun 13 16:49 /home/qa/start_vms.sh
$ whoami
qa
关于如何使 systemd 脚本在 CentOS 上运行有什么建议吗?
编辑1
$ echo $XDG_RUNTIME_DIR
/run/user/1000
$ echo $DBUS_SESSION_BUS_ADDRESS
unix:path=/run/user/1000/bus
$ echo $DBUS_SESSION_BUS_ADDRESS
unix:path=/run/user/1000/bus
$ ls /run/user/1000/bus
ls: cannot access /run/user/1000/bus: No such file or directory
$ systemctl status dbus.service
● dbus.service - D-Bus System Message Bus
Loaded: loaded (/usr/lib/systemd/system/dbus.service; static; vendor preset: disabled)
Active: active (running) since Thu 2019-06-13 17:32:32 PDT; 17h ago
Docs: man:dbus-daemon(1)
Main PID: 3797 (dbus-daemon)
Tasks: 1
CGroup: /system.slice/dbus.service
└─3797 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
...
$ systemctl --user status
Failed to get D-Bus connection: No such file or directory
[1] 谷歌搜索此错误信息没有得到任何有价值的结果。