我正在尝试运行一个脚本,该脚本从 systemd 服务启动 vlc 进程。如果我手动启动该脚本,它会正常工作,但如果我从 systemd 调用它,它会失败。我在日志中看到的错误是:
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edc51430] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edc628e0] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edc628e0] main interface error: no suitable interface module
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edb822a0] main libvlc error: interface "dbus,none" initialization failed
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edc728f0] main interface error: no suitable interface module
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edb822a0] main libvlc error: interface "globalhotkeys,none" initialization failed
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [000055f6edc728f0] dummy interface: using the dummy interface module...
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [00007ff32c9933a0] mux_ogg mux: Open
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [00007ff32c9973d0] main tls client error: cannot resolve www.example.com port 443: System error
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [00007ff32c9964d0] access stream error: HTTP connection failure
Oct 18 15:24:40 ip-172-31-13-123 python3[23937]: [00007ff32c9933a0] mux_ogg mux: Close
这是 systemd 服务:
[Unit]
Description=vlc service
After=kurento-media-server.service
StartLimitIntervalSec=0
[Service]
Type=simple
User=ubuntu
ExecStart=/usr/bin/python3 /usr/local/bin/start-vlc.py
[Install]
WantedBy=multi-user.target
这是我的脚本:
#!/usr/bin/python3
import subprocess
subprocess.run("vlc -I rc -I dummy 'https://www.example.com/stream/5f7c91b21584ad57e798678c/interpreter0.sdp' ':sout=#transcode{vcodec=none,acodec=mp3,channels=1}:duplicate{dst=http{mux=ts,mime=,dst=:50001},dst=http{mux=ogg,mime=audio/ogg,dst=:50051/live.ogg}}' ':sout-keep' &", shell=True)
我正在运行 VLC 版本 3.0.8、systemd 237、Ubuntu 18.04.5
谁知道可能出了什么问题?
谢谢