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