Skip to content

Instantly share code, notes, and snippets.

@cyberhiker
Last active April 13, 2016 07:34
Show Gist options
  • Save cyberhiker/9b60b1115e250a597c3f to your computer and use it in GitHub Desktop.
Save cyberhiker/9b60b1115e250a597c3f to your computer and use it in GitHub Desktop.
Cobbled Together init.d script for shairplay
This is the init.d and default file that I am using to get shairplay to run as a service.
On Ubuntu:
sudo cp "init.d - shairplay" /etc/init.d/shairplay
sudo cp "default - shairplay" /etc/default/shairplay
sudo chmod a+x /etc/init.d/shairplay
sudo update-rc.d shairplay defaults
sudo service shairplay start
If it doesn't work immediately, customize the /etc/default/shairplay to your environment.
# Shairplay Daemon options
# Uncomment and modify lines to change defaults
# User and group under which shairplay should be run
# user should have permission to output sound
# Check the audio output documentation for details.
#USER=<yourusername>
#GROUP=audio
# Process' nice on start
#NICE=0
# Specify where the airport.key is located
KEYLOCATION=/opt/shairplay
# File where log messages should be redirected.
# If a non-default log or error file is used, and logrotate is configured with
# the provided configuration file, then the paths of the log files should be
# updated in /etc/logrotate.d/shairplay to reflect the value of $LOGFILE and $ERRFILE
LOGFILE=/var/log/shairplay.log
# If empty, errors are redirected to LOGFILE
#ERRFILE=/var/log/shairplay.err
PIDFILE=/var/run/shairplay.pid
# Set the AirPlay advertised name.
# Defaults to computer's hostname
APNAME=House
# Set output driver and options
# Defaults to the first available, depends on the build options
# Check 'shairplay -h' for details
#OUTPUT=ao
#OUTPUT_OPTS=
#RUN_ONSTART=
#RUN_ONSTOP=
#!/bin/bash
#
# This starts and stops shairplay
#
### BEGIN INIT INFO
# Provides: shairplay
# Required-Start: $network
# Required-Stop:
# Short-Description: shairplay - Airtunes emulator!
# Description: Airtunes emulator!
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
# Check for existance of defaults file
# and utilze if available
if [ -f /etc/default/shairplay ]; then
. /etc/default/shairplay
else
echo "/etc/default/shairplay not found using default settings.";
fi
# Source function library.
. /lib/lsb/init-functions
NAME=shairplay
USER=${USER}
DAEMON=/usr/local/bin/shairplay
KEYLOCATION=${KEYLOCATION-/opt/shairplay}
PIDFILE=${PIDFILE-/var/run/pulse/$NAME.pid}
APNAME=${APNAME-shairplay}
LOGFILE=${LOGFILE-/var/log/shairport.log}
DAEMON_ARGS="-w $PIDFILE -a $APNAME"
[ -x $binary ] || exit 0
RETVAL=0
start() {
echo -n "Starting shairplay: "
start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
--chuid $USER \
--chdir "$KEYLOCATION" \
--exec "$DAEMON" -b --oknodo -- $DAEMON_ARGS
log_end_msg $?
}
stop() {
echo -n "Shutting down shairplay: "
start-stop-daemon --stop --quiet --pidfile "$PIDFILE" \
--retry 1 --oknodo
log_end_msg $?
}
restart() {
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status shairplay
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
;;
esac
exit 0
@kione
Copy link

kione commented Apr 13, 2016

well done! I have had problems pathing the airport.key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment