2

I just set up a systemd.service in order to run cmus (a console-music-player) detached to a screen at startup.

i don't get sound, when starting via remote with no user logged in to the machine.
i do get sound, while i'm logged in as the user i set the service to run. but: i can't change volume via remote, it says "mixer is not open".

when i just start cmus detached to a screen logged in as the user manually, i can log out again, and do have sound and mixer via remote.

when i set the service to run as root (which i don't want, for several reasons) it does have sound and mixer.

unfortunately Environment=XDG_RUNTIME_DIR=/run/user/1000 as suggested here doesn't help (1000 is the right one).

so the question is: what is missing here to get alsa fully working in my systemd-service as a user?

my current unit looks like this:

[Unit]
Description=cmusd (consolemusicplayer in screen with remote-web-server)
After=syslog.target network.target sound.target

[Service]
Type=forking
User=myusername
WorkingDirectory=/home/myusername/cmus_daemon
ExecStart=/home/myusername/cmus_daemon/cmusd.init start
ExecStop=/home/myusername/cmus_daemon/cmusd.init stop
Environment="HOME=/home/myusername" "USERNAME=myusername"

[Install]
WantedBy=multi-user.target

Where cmusd.init start does basically

screen -dmS cmusplayer cmus --listen $CMUS_IP

my system is a ubuntu server 19.10 on a small board with optical audio.

1 Answer 1

2

allright, after more searching and experimenting i found a solution, that works like a charme at least on this ubuntu: just add Group=audio. No environment needed.

[Unit]
Description=cmusd (consolemusicplayer in screen with remote-web-server)
After=syslog.target network.target sound.target

[Service]
Type=forking
User=myusername
Group=audio
WorkingDirectory=/home/myusername/cmus_daemon
ExecStart=/home/myusername/cmus_daemon/cmusd.init start
ExecStop=/home/myusername/cmus_daemon/cmusd.init stop

[Install]
WantedBy=multi-user.target

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .