Audio not working when squeezelite started as system service

MikeyIII

New Member
Joined
Mar 16, 2023
Messages
6
Reaction score
0
Credits
52
I am running squeezelite using the systemd scripts to run init.d scripts which start the service on boot. I am having trouble with the audio server not working when the service is running. If I stop the service and run the binary directly then audio works in squeezelite and in everything else. This leads me to believe that it is because the script is being run as root. I added `--chuid` to the `start-stop-script` and now if I start the service from a logged in terminal everything works but if I let systemd start the service it still doesn't work. Does anyone have any experience with getting this to work?
 


G'day Mikey, Welcome to Linux.org

Squeezelite is a small headless Logitech Squeezebox emulator. It is aimed at supporting high quality audio including USB DAC based output at multiple sample rates.

The player is controlled using, and media is streamed from, a Logitech Media Server instance running somewhere on the local network.

That could very well be the problem. Logitech.
 
The software works fine when started from the terminal. I think if I start it as a user it should work. I just can't get it to work, I thought --chuid would help but when its there it doesn't start at all it just exits with exit code 0.
I will post the init.d script maybe I'm doing something wrong.
#!/bin/sh ### BEGIN INIT INFO # Provides: squeezelite # Required-Start: $network $remote_fs # Required-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Lightweight headless Squeezebox emulator # Description: Lightweight headless streaming audio player for Logitech's # Squeezebox audio server ### END INIT INFO # Author: Chris Boot <[email protected]> PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Squeezebox client" NAME=squeezelite DAEMON=/usr/bin/$NAME PIDFILE=/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { DAEMON_ARGS="" # add squeezelite name if set if [ -n "$SL_NAME" ]; then DAEMON_ARGS="${DAEMON_ARGS} -n ${SL_NAME}" fi # add souncard setting if set if [ -n "$SL_SOUNDCARD" ]; then DAEMON_ARGS="${DAEMON_ARGS} -o ${SL_SOUNDCARD}" fi # add squeezebox server ip address if set if [ -n "$SB_SERVER_IP" ]; then DAEMON_ARGS="${DAEMON_ARGS} -s ${SB_SERVER_IP}" fi # add any other options given by the user if [ -n "$SB_EXTRA_ARGS" ]; then DAEMON_ARGS="${DAEMON_ARGS} ${SB_EXTRA_ARGS}" fi # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ --test > /dev/null || return 1 start-stop-daemon --start --chuid my_user --quiet --pidfile $PIDFILE --exec $DAEMON \ --background --make-pidfile -- $DAEMON_ARGS || return 2 } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \ --pidfile $PIDFILE --exec $DAEMON } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start; RET=$? case $RET in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0; exit 0 ;; *) [ "$VERBOSE" != no ] && log_end_msg 1; exit 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop; RET=$? case $RET in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0; exit 0 ;; *) [ "$VERBOSE" != no ] && log_end_msg 1; exit 1 ;; esac ;; status) status_of_proc "$DAEMON" "$NAME" ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop; RET=$? case $RET in 0|1) do_start; RET=$? case $RET in 0) log_end_msg 0; exit 0 ;; 1) log_end_msg 1; exit 1 ;; # Old process is still running *) log_end_msg 1; exit 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1; exit 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac

This line is changed:
start-stop-daemon --start --chuid my_user --quiet --pidfile $PIDFILE --exec $DAEMON \ --background --make-pidfile -- $DAEMON_ARGS || return 2
 
If there is such, what is the text of the systemd service file that starts it from systemd?
 
systemctl cat squeezelite.service

# /etc/systemd/system/squeezelite.service [Unit] Description=Squeezelite LMS player After=network.target [Service] Type=forking ExecStart=/etc/init.d/squeezelite start ExecStop=/etc/init.d/squeezelite stop PIDFile=/run/squeezelite.pid [Install] #WantedBy=multi-user.target WantedBy=default.target
 
You could try to run the executables like:
Code:
ExecStart=/bin/sh -c /etc/init.d/squeezelite start
ExecStop=/bin/sh -c /etc/init.d/squeezelite stop
to get the shell to pass the commands explicitly.
 
$ sudo systemctl restart squeezelite.service

Job for squeezelite.service failed because the control process exited with error code. See "systemctl status squeezelite.service" and "journalctl -xe" for details.

$ journalctl -xe Mar 16 22:19:57 <MY_USER> sudo[117895]: <MY_USER> : TTY=pts/2 ; PWD=/home/<MY_USER> ; USER=root ; COMMAND=/usr/bin/systemctl restart squeezelite.service Mar 16 22:19:57 <MY_USER> sudo[117895]: pam_unix(sudo:session): session opened for user root by <MY_USER>(uid=0) Mar 16 22:19:57 <MY_USER> systemd[1]: Starting Squeezelite LMS player... -- Subject: A start job for unit squeezelite.service has begun execution -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- A start job for unit squeezelite.service has begun execution. -- -- The job identifier is 12181. Mar 16 22:19:57 <MY_USER> sh[117899]: Usage: /etc/init.d/squeezelite {start|stop|status|restart|force-reload} Mar 16 22:19:57 <MY_USER> systemd[1]: squeezelite.service: Control process exited, code=exited, status=3/NOTIMPLEMENTED -- Subject: Unit process exited -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- An ExecStart= process belonging to unit squeezelite.service has exited. -- -- The process' exit code is 'exited' and its exit status is 3. Mar 16 22:19:57 <MY_USER> systemd[1]: squeezelite.service: Failed with result 'exit-code'. -- Subject: Unit failed -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- The unit squeezelite.service has entered the 'failed' state with result 'exit-code'. Mar 16 22:19:57 <MY_USER> systemd[1]: Failed to start Squeezelite LMS player. -- Subject: A start job for unit squeezelite.service has failed -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- A start job for unit squeezelite.service has finished with a failure. -- -- The job identifier is 12181 and the job result is failed. Mar 16 22:19:57 <MY_USER> sudo[117895]: pam_unix(sudo:session): session closed for user root


EDIT (Added a little more info)

I added "" like this
ExecStart=/bin/sh -c "/etc/init.d/squeezelite start" And I think it works as far as audio is concerned (I'm not able to fully test) but it hangs I guess because the shell never exits?
Mar 16 22:27:59 <MY_USER> systemd[1]: Starting Squeezelite LMS player... Mar 16 22:29:29 <MY_USER> systemd[1]: squeezelite.service: start operation timed out. Terminating. Mar 16 22:29:29 <MY_USER> systemd[1]: squeezelite.service: Failed with result 'timeout'. Mar 16 22:29:29 <MY_USER> sh[858]: Starting squeezelite (via systemctl): squeezelite.service Mar 16 22:29:29 <MY_USER> systemd[1]: Failed to start Squeezelite LMS player.
 
Last edited:
If the suggestion in post #6 fails, and systemd can't be persuaded to run the program, then you could consider a script in /etc/rc.local.

Does the systemd config need the forking over oneshot?
 
Last edited:
I thought so. It is supposed to stay running, but maybe it should be oneshot because the init script just runs and exits?
I installed it under Fedora there you have two different systemd-unit-file scripts.
/usr/lib/systemd/system/squeezelite.service:
Code:
[Unit]
Description=Squeezelite headless streaming music client
Documentation=man:squeezelite.service(7)
Wants=sound.target
After=sound.target

[Service]
Type=exec
User=squeezelite
Group=squeezelite
EnvironmentFile=/etc/sysconfig/squeezelite
ExecStart=/usr/bin/squeezelite -N /var/lib/squeezelite/player-name $ARGS

[Install]
WantedBy=multi-user.target
/usr/lib/systemd/user/squeezelite.service:
Code:
[Unit]
Description=Squeezelite headless streaming music client
Documentation=man:squeezelite.service(7)
Wants=sound.target
After=pulseaudio.service

[Service]
Type=exec
ExecStartPre=/usr/bin/mkdir -p .local/share/squeezelite
ExecStart=/usr/bin/squeezelite -N .local/share/squeezelite/player-name

[Install]
WantedBy=default.target
Try working with one of those?
 
Thanks for taking the time to look into this for me. Yes. Still not working.
Maybe I am approaching this wrong, and losing sight of the real problem. I was focused on this as a solution but maybe there is a different solution to the original problem. The original problem is that if I run squeezelite from the service on boot then the system sound does not work. If I disable the service system sound works, and squeezelite can be started manually and then they both work. Even a modified version of the service worked when started from the terminal after being logged in.
So I guess my question would be how to get squeezelite to not do whatever it is that causes system sound not to work.
 
Last edited:
If you're starting squeezelite using a systemd service unit file AND you're running it under a user account, e.g.

User=squeezelite
Group=squeezelite

..you have to make sure that the squeezelite user & group exist AND that the squeezelite user account is a member of the Audio group. E.g.:

usermod -a -G Audio squeezelite
 

Members online


Top