简体   繁体   中英

systemd service audio output

I want a python script started from a systemd service to output audio.

I have a udev rule which starts a systemd service from a template. The template then starts a python script with two parameters (--device and the device path)

multiupload@.service file:

[Unit]
Description=Mutiupload start service routine

[Service]
Type=oneshot

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

[Install]
WantedBy=multi-user.target

In the python script I call either cvlc, mpg123 or ffplay with the audio file to output audio:

# 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)

All of those work nice when executed from terminal with logged in session but does not output audio when called via systemd service.

Any way I can output from my python script, called by a systemd service? Or is this not possible by design (system services should not interact with user sessions in that way?)?

Maybe Mopidy would work, but I'd like to use as few components as possible...

All ideas appreciated!

Looks like some sort of permissions are needed for running the script since you are able to run it with logged in session. Can you please provide output of

systemctl status <yourservicefilename>

Also you can try setting User=root in your service file and provide a WorkingDirectory in the service file.

Refer link for all the details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM