Provide an init.d script with install for Linux users
I'm struggling to get Bliss set up as a service in Ubuntu 11.10 that auto starts on boot and can be stopped/started/restarted with the standard Linux "service bliss start" style commands.
I'd really appreciate it if you could include an init.d script with the Linux install, or provide instructions for setting this up on the blisshq website.
-
PaulB commented
For debian, I've got the following init script. I've taken this from some skeleton script and modified it.
Although it does work, there are peculiarities preventing the PID to be recorded at all.
Maybe someone can use it as inspiration and make it fully functional....The complete script uses two files, one for the actual script, and one for configuring it. I will post both as separate comments.
-
PaulB commented
Script file: /etc/init.d/bliss-server
=========================
<pre>#! /bin/sh
# Copyright (C) 2011- by Mar2zz <LaSi.Mar2zz@gmail.com>
# released under GPL, version 2 or later################################################
# #
# TO CONFIGURE EDIT /etc/default/bliss-server #
# #
################################################### BEGIN INIT INFO
# Provides: Bliss server instance
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of Bliss server
# Description: starts instance of Bliss server using start-stop-daemon
### END INIT INFO# main variables
DAEMON=/usr/local/bliss/bin/bliss.sh
SETTINGS=/etc/default/bliss-serverSETTINGS_LOADED=FALSE
DESC='Bliss Server by start-stop-deamon'
# Avoid using root's TMPDIR
unset TMPDIR# only accept values from /etc/default/bliss-server
unset RUN_AS LIBRARY PORT PID_FILE# Source function library.
. /lib/lsb/init-functions# Check that networking is up.
[ -n $NETWORK ] || {
log_warning_msg "$DESC: No network found, aborting. See $DAEMON";
return 1; }
[ -x $DAEMON ] || {
log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
return 1; }[ -r $SETTINGS ] || {
log_warning_msg "$DESC: Can't read settings, aborting. See $SETTINGS";
return 1; }check_retval() {
if [ $? -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}load_settings() {
if [ $SETTINGS_LOADED != "TRUE" ]; then
. $SETTINGS[ -n "$APP_PATH" ] || {
log_warning_msg "$DESC: path to $DESC not set, aborting. See $SETTINGS";
return 1; }[ $ENABLE_DAEMON = 1 ] || {
log_warning_msg "$DESC: daemon not enabled, aborting. See $SETTINGS";
return 1; }[ -n "$RUN_AS" ] || {
log_warning_msg "$DESC: daemon username not set, aborting. See $SETTINGS";
return 1; }
[ -z "${RUN_AS%:*}" ] && exit 1DAEMON_OPTS="--daemonize"
[ -n "$LIBRARY" ] && DAEMON_OPTS="$DAEMON_OPTS --with-library=$LIBRARY"
[ -n "$PORT" ] && DAEMON_OPTS="$DAEMON_OPTS --port=$PORT"
[ -n "$USERNAME" ] && DAEMON_OPTS="$DAEMON_OPTS --username=$USERNAME"
[ -n "$PASSWORD" ] && DAEMON_OPTS="$DAEMON_OPTS --password=$PASSWORD"
[ -n "$PID_FILE" ] || PID_FILE=/var/run/bliss/bliss-server.pid
DAEMON_OPTS="$DAEMON_OPTS --pidfile=$PID_FILE"
[ $ENABLE_DEVELOPMENT = 1 ] && DAEMON_OPTS="$DAEMON_OPTS --develop"
SETTINGS_LOADED=TRUE
fi
return 0
}load_settings || exit 0
is_running () {
# returns 1 when running, else 0.
PID=$(pgrep -f "$APP_PATH/bin/bliss-server $DAEMON_OPTS")
RET=$?
[ $RET -gt 1 ] && exit 1 || return $RET
}handle_pid () {
PID_PATH=`dirname $PID_FILE`
[ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || {
log_warning_msg "$DESC: Could not create $PID_FILE, aborting.";
return 1;}
}start_bliss () {
if ! is_running; then
log_daemon_msg "Starting $DESC"
[ "$WEB_UPDATE" = 1 ] && enable_updates
handle_pid
start-stop-daemon -o -c $RUN_AS --start --pidfile $PID_FILE $DEAMON_OPTS --exec $DAEMON -- $EXTRA_OPTS
# /usr/local/bliss/bin/bliss.sh &
check_retval
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}status_bliss () {
if ! is_running; then
log_daemon_msg "$DESC: not running"
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}stop_bliss () {
if is_running; then
log_daemon_msg "Stopping $DESC"
start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15
check_retval
else
log_success_msg "$DESC: not running"
fi
}case "$1" in
start)
start_bliss
;;
stop)
stop_bliss
;;
status)
status_bliss
;;
restart|force-reload)
stop_bliss
start_bliss
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
exit 1
;;
esacexit 0
===================
</pre> -
PaulB commented
Configuration file: /etc/default/bliss-server
=================================
<pre># This file is sourced by /etc/init.d/bliss-server
#
# When bliss server is started using the init script
# is started under the account of $USER, as set below.
#
# Each setting is marked either "required" or "optional";
# leaving any required setting unconfigured will cause
# the service to not start.# [required] set path where bliss is installed:
APP_PATH=/usr/local/bliss/bin# [optional] change to 1 to enable daemon
ENABLE_DAEMON=1# [required] user or uid of account to run the program as:
RUN_AS=squeezeboxserver# [optional] port number to listen on, defaults to port 3220:
PORT=# [optional] full path for the pidfile
# otherwise, the default location /var/run/bliss/bliss-server.pid is used:
PID_FILE=# [optional] The maximum size for displayed covers. Default is ‘600x800’.
MAX_COVER=# Development mode. Server automatically restarts on file changes and
# serves code files (html, css, js) from the file system instead of
# bliss's resource system. (change to 1 to enable development mode)
DEVELOPMENT=0
ENABLE_DEVELOPMENT=0# [optional] Extra options you want to set. See blissserver --help for more info.
# This needs to be wrapped in quotes "" properly.
EXTRA_OPTS=""===================
</pre> -
What's the standard way of doing this when the app is a download? The best possible solution would be incorporation in a .deb repository, but not sure on the situation with that given licencing.
One place to start maybe the vortexbox start scripts that I/Andrew Gillis wrote. You will probably have to alter them for your system...
(apols for lack of formatting)
<pre>
#!/bin/sh
#
# chkconfig: 345 91 50
# description: Starts and stops the bliss
# pidfile: /opt/ps3mediaserver/bliss.pid# Source function library.
. /etc/rc.d/init.d/functions# Avoid using root's TMPDIR
unset TMPDIR# Source networking configuration.
. /etc/sysconfig/network# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1start() {
# Check if it is already running
echo -n $"Starting bliss daemon: "
if [ ! `pgrep -f /opt/bliss/bin/` ]; then
daemon daemonize /opt/bliss/bin/bliss.sh
else
status bliss
fi
echo
return $RETVAL}
stop() {
echo -n $"Stopping bliss daemon: "
echo_success
for i in `pgrep -f /opt/bliss/bin/`
do
kill $i
done
echo}
restart() {
stop
sleep 1
start
}checkstatus() {
if [ ! `pgrep -f /opt/bliss/bin/` ]; then
echo -n $"bliss is stopped"
echo
else
echo "bliss (pid `pgrep -f /opt/bliss/bin/`) is running..."
fi
}case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
checkstatus
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 2
esac
exit $?
</pre>