slackbuilds/xap/calibre/rc.calibre-server

76 lines
1.6 KiB
Text
Raw Normal View History

#!/bin/bash
CALIBRE_LIBRARY_PATH="/home/cycojesus/BKP/tibou/Documents/eBooks/Livres/"
PIDFILE=/tmp/calibre-server.pid
USER=cycojesus
PORT=8081
2016-09-21 22:15:20 +02:00
AUTH=""
# uncomment and adapt to enable authtentication
# AUTH=" --username=\"$USER\" --password=\"password\""
OPTIONS=" --enable-local-write"
LOGFILE=/home/$USER/.calibre-server.log
start() {
echo "Starting Calibre server..."
su $USER -c "calibre-server --port=$PORT --pidfile=$PIDFILE --log=$LOGFILE --daemonize $AUTH $OPTIONS \"$CALIBRE_LIBRARY_PATH\"" &
if [ $? -ne 0 ]; then
2016-09-21 22:15:20 +02:00
echo "Could not start calibre-server."
fi
}
stop() {
echo "Stopping Calibre server..."
if [ -e $PIDFILE ]; then
2016-09-21 22:15:20 +02:00
read PID < $PIDFILE
ps aux | grep "$PID" | grep 'calibre-server' > /dev/null
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
kill $PID
if [ $? -eq 0 ]; then
rm $PIDFILE
fi
else
echo "Could not find a calibre-server process with PID $PID."
fi
else
2016-09-21 22:15:20 +02:00
echo "Could not find pidfile: $PIDFILE"
fi
}
restart() {
stop
start
}
status() {
if [ -e $PIDFILE ]; then
2016-09-21 22:15:20 +02:00
read PID < $PIDFILE
echo "calibre-server is running with PID $PID."
else
2016-09-21 22:15:20 +02:00
echo "calibre-server is not running."
fi
}
unknown() {
echo "Unrecognized command: $1"
echo "Try one of the following: (start|stop|restart|status)"
}
case $1 in
start )
2016-09-21 22:15:20 +02:00
start
;;
stop )
2016-09-21 22:15:20 +02:00
stop
;;
restart )
2016-09-21 22:15:20 +02:00
restart
;;
status )
2016-09-21 22:15:20 +02:00
status
;;
* )
2016-09-21 22:15:20 +02:00
unknown
;;
esac