#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Calibre Content Server"
NAME=calibre-server
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
PID=$(cat $PIDFILE 2>/dev/null)
CONTENT=/home/user/Library
PORT=9797
MAX_COVER=600x800
USERNAME=calibre
PASSWORD=""
DAEMON_ARGS="--develop --with-library=$CONTENT --pidfile=$PIDFILE --port=$PORT --max-cover=$MAX_COVER --username=$USERNAME --password=$PASSWORD --daemonize"
# 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
case "$1" in
start)
stat_busy "Starting $DESC"
$DAEMON $DAEMON_ARGS > /dev/null 2>&1
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon $NAME
stat_done
fi
;;
stop)
stat_busy "Stopping $DESC"
[ ! -z "$PID" ] && kill $PID &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon $NAME
rm $PIDFILE
stat_done
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
;;
esac
exit 0