matthias4217 / jukebox-ultra-nrv

Multi-user jukebox for LAN use
https://gitlab.com/club-jeux-int/jukebox-ultra-nrv
3 stars 3 forks source link

Systemd service call to the jukebox fails when no shell=True #50

Closed PaulDance closed 5 years ago

PaulDance commented 5 years ago

When the jukebox is called in the shell "by hand" to be executed by python3.6, it runs just fine. But when setting up a systemd service as such:

# /etc/systemd/system/jukebox.service
[Unit]
Description=Jukebox service

[Service]
WorkingDirectory=/home/hackademint/jukebox-ultra-nrv/
ExecStart=/usr/bin/python3.6 run.py
Restart=always
User=hackademint
Group=hackademint

[Install]
WantedBy=default.target

then it seems to have a hard time getting the sound card's master control. The 41th line of the main.py script in jukebox/src/, which is:

amixer_out = subprocess.check_output(['amixer', 'get', "'Master',0"]).decode()

fails as the alsa mixer does not find the master control:

amixer: Unable to find simple control 'Master',0

while this definitely does not happen when ran "by hand". A fix that I found was to add the keyword argument shell=True to the check_output() function:

amixer_out = subprocess.check_output(['amixer', 'get', 'Master'], shell=True).decode()

This way, it seems that the subprocess call is made just like from an actual shell, so it works well.

Also, selecting the 'Master' control seems preferable to me, as alsamixer automatically resolves it to 'Master',0 when called, but I'm not too sure on that one.

matthias4217 commented 5 years ago

The current systemd service I use indeed stopped to work (for another reason), so I plan to tackle the issue soon. I'll look Alsamixer too. Thank you for tge insight !