2015-12-02 10:43:32 +01:00
|
|
|
#!/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\""
|
2017-12-21 22:17:21 +01:00
|
|
|
OPTIONS=" --enable-local-write"
|
|
|
|
LOGFILE=/home/$USER/.calibre-server.log
|
2015-12-02 10:43:32 +01:00
|
|
|
|
|
|
|
start() {
|
|
|
|
echo "Starting Calibre server..."
|
2017-12-21 22:17:21 +01:00
|
|
|
su $USER -c "calibre-server --port=$PORT --pidfile=$PIDFILE --log=$LOGFILE --daemonize $AUTH $OPTIONS \"$CALIBRE_LIBRARY_PATH\"" &
|
2015-12-02 10:43:32 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
2016-09-21 22:15:20 +02:00
|
|
|
echo "Could not start calibre-server."
|
2015-12-02 10:43:32 +01:00
|
|
|
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
|
2015-12-02 10:43:32 +01:00
|
|
|
else
|
2016-09-21 22:15:20 +02:00
|
|
|
echo "Could not find pidfile: $PIDFILE"
|
2015-12-02 10:43:32 +01:00
|
|
|
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."
|
2015-12-02 10:43:32 +01:00
|
|
|
else
|
2016-09-21 22:15:20 +02:00
|
|
|
echo "calibre-server is not running."
|
2015-12-02 10:43:32 +01:00
|
|
|
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
|
|
|
|
;;
|
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 )
|
2016-09-21 22:15:20 +02:00
|
|
|
restart
|
|
|
|
;;
|
2015-12-02 10:43:32 +01:00
|
|
|
status )
|
2016-09-21 22:15:20 +02:00
|
|
|
status
|
|
|
|
;;
|
2015-12-02 10:43:32 +01:00
|
|
|
* )
|
2016-09-21 22:15:20 +02:00
|
|
|
unknown
|
|
|
|
;;
|
2015-12-02 10:43:32 +01:00
|
|
|
esac
|