Skip to content

Instantly share code, notes, and snippets.

@wedi
Last active March 30, 2020 05:07
Show Gist options
  • Save wedi/c80659c3ae9880eccfd5cb4be8c10a17 to your computer and use it in GitHub Desktop.
Save wedi/c80659c3ae9880eccfd5cb4be8c10a17 to your computer and use it in GitHub Desktop.

Install spotifyd as daemon on Rasbian

  • Create a new user:
    sudo adduser --no-create-home --disabled-login --system --group spotifyd

  • Allow audio access:
    sudo usermod -a -G audio spotifyd

  • Get the spotifyd.
    Either the binary or build it yourself.

  • Put the spotifyd binary in place: sudo mv spotifyd /opt/bin/.
    Adjust permissions: sudo chown -R spotifyd:spotifyd /opt/bin && sudo chmod 755 /opt/bin/spotifyd

  • Adjust your settings in spotifyd.conf.

  • Get your settings in place:
    sudo cp spotifyd.conf /etc/
    Adjust permissions: sudo chown spotifyd:spotifyd && sudo chmod 700 /etc/spotifyd.conf.
    It's not to cool to store the credentials in that file but that's the way it is, when you don't want to start the daemon manually...

  • Setup the init.d script:
    sudo cp spotifyd /etc/init.d/
    Adjust permissions: sudo chown root:root /etc/init.d/spotifyd && sudo chmod 755 /etc/init.d/spotifyd

  • Install with sudo update-rc.d spotifyd defaults

  • Move all spotifyd log messages to its own file:
     cp spotifyd_rsyslog.conf /etc/rsyslog.d/spotifyd.conf

  • Start with sudo service spotifyd start

# Move spotifyd log to it's own logfile
# $syslogseverity == 7 is DEBUG, we don't want this
if tolower($programname) == "spotifyd" \
and $syslogseverity < 7 \
and not ($msg == "Load Done" or $msg startswith "Loading track " ) \
then /var/log/spotifyd.log
#!/bin/sh
### BEGIN INIT INFO
# Provides: spotifyd
# Required-Start: $local_fs $network $named $time $syslog alsa-utils
# Required-Stop: $local_fs $network $named $time $syslog alsa-utils
# Should-Start: avahi avahi-daemon
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Spotify Connect Daemon
# Description: Start Spotify Connect Daemon on boot.
### END INIT INFO
set -e
NAME="spotifyd"
PIDFILE=/var/run/$NAME.pid
DAEMON="/opt/bin/$NAME"
DAEMON_PARAMETER="--pid /var/run/$NAME.pid"
RUNAS=$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
# remove pid file if it's empty or the process is not running anymore
if [ -f "$PIDFILE" ]; then
if [ -s "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
rm -f "$PIDFILE"
fi
fi
start() {
echo -n "Starting $NAME..."
touch "$PIDFILE"
chown $RUNAS:$RUNAS "$PIDFILE"
start-stop-daemon --start --quiet --chuid $RUNAS --exec "$DAEMON" -- $DAEMON_PARAMETER
echo " Done!"
}
stop() {
echo -n "Stopping $NAME..."
start-stop-daemon --stop --quiet --retry 30/TERM/forever/KILL --oknodo --user $RUNAS
echo " Done!"
}
restart() {
echo "Restarting $NAME..."
stop
start
echo "$NAME restarted!"
}
uninstall() {
read -r -p "Are you sure you want to remove $NAME? This cannot be undone. [yes|NO] " response
case "$response" in
[yY][eE][sS]|[yY])
stop
rm -f "$PIDFILE"
# echo "Notice: The log file is not removed: '$LOGFILE'"
update-rc.d -f $NAME remove
rm -fv "$0"
;;
*)
exit 3
;;
esac
}
case "$1" in
start)
start
;;
stop)
stop
;;
uninstall)
uninstall
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart|status|uninstall}"
esac
[global]
username =
password =
backend = alsa
device_name = Spotify on Raspi
bitrate = 320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment