Ubuntu Systemd脚本无法正确执行

时间:2018-08-23 16:13:44

标签: ubuntu systemd

在Ubuntu 16.04上系统化无法实现我想要的功能。

这是我的脚本(/ usr / bin / testscript)在/tmp/pa.log中写了几行:

#!/bin/bash
echo "query pacmd" >> /tmp/pa.log

/usr/bin/pacmd list-sinks >> /tmp/pa.log

echo "done" >> /tmp/pa.log

如果我跑步:

$ /usr/bin/testscript
$ cat /tmp/pa.log
query pacmd
2 sink(s) available.
  * index: 99
  ... (lot of stuff which does not matter here)
done

我想从systemd服务运行它,所以我创建了一个(/etc/systemd/system/pulseaudio-remote-sink.service):

[Unit]
Description=Desc
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target
Wants=network-online.target
After=network.target network-online.target

[Service]
User=xy ###this is my username of course
Group=xy ###this is my group of course
Type=simple
ExecStart=/usr/bin/testscript

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target
WantedBy=default.target

我启用了它并尝试:

$ systemctl enable test.service
$ systemctl start test.service

但是现在,在日志文件中,pacmd没有输出:

$ cat /tmp/pa.log
query pacmd
done

为什么此systemd服务的行为如此?如何获得与手动运行相同的结果?

0 个答案:

没有答案