2016-07-26 149 views
1

我想要一個從systemd服務啓動的python腳本來輸出音頻。systemd服務音頻輸出

我有一個從模板啓動systemd服務的udev規則。模板然後開始一個python腳本有兩個參數(--device和設備路徑)

multiupload @。服務文件:

[Unit] 
Description=Mutiupload start service routine 

[Service] 
Type=oneshot 

ExecStart=/path/to/script.py --device %I 

[Install] 
WantedBy=multi-user.target 

在Python腳本我叫任CVLC,mpg123的或ffplay與音頻文件輸出音頻:

# cvlc does not like to be run as root 
#audio_args = ["cvlc", "--play-and-exit", "/dir/to/audio/file"] 

#mpg123 shits its pants when doing this 
#audio_args = ["mpg123", "/dir/to/audio/file"] 

#ffplay blacks out my screen? also no output 
#audio_args = ["ffplay", "-autoexit", "/dir/to/audio/file"] 

subprocess.call(audio_args) 

與登錄會話,但是當通過systemd服務,稱爲不輸出音頻從終端中執行時,所有這些工作的很好。

我可以從我的python腳本輸出任何方式,由systemd服務調用?或者這是不可能的(系統服務不應該以這種方式與用戶會話交互?)?

也許Mopidy會的工作,但我想用盡可能少的部件儘可能...

感謝所有的想法!

回答

0

看起來像運行腳本需要某種權限,因爲您可以在登錄會話中運行它。 能否請您提供的

systemctl status <yourservicefilename> 

輸出,您也可以嘗試在你的服務文件中設置User=root和提供服務文件WorkingDirectory

請參閱link的所有細節。