Init Script for Calibre Server

I use the very excellent Calibre to make my ebooks accessible to all of my devices anywhere I am. It has a very useful server component that many ebook readers can use to download content. What I was missing was a way to automatically start/stop calibre-server. For that,I put together this rc script for Arch Linux.

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

CONTENT=/mnt/miscellaneous/Books/Literary
PORT=8080

DAEMON=calibre-server
PIDFILE=/var/run/$DAEMON.pid
ARGS="--auto-reload --with-library=$CONTENT --pidfile=$PIDFILE --port=$PORT --daemonize"

case "$1" in
 start)
  stat_busy "Starting $DAEMON"
  [ -z "$PID" ] && $DAEMON $ARGS &>/dev/null
   if [ $? = 0 ]; then
     add_daemon $DAEMON
     stat_done
   else
     stat_fail
     exit 1
   fi
   ;;
 stop)
   stat_busy "Stopping $DAEMON"
   PID=`cat $PIDFILE`
   [ -n "$PID" ] && kill $PID &>/dev/null
   if [ $? = 0 ]; then
     rm_daemon $DAEMON
     stat_done
   else
     stat_fail
     exit 1
   fi
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"
esac
About

Application Developer at the University of Iowa. Works mostly with PHP/Oracle, but doesn't like the Oracle bits. Also an avid gamer and tinkerer.

Tagged with: , , ,
Posted in Arch Linux, Scripting
2 comments on “Init Script for Calibre Server
  1. David Ring says:

    Brian,

    I want to keep calibre running all the time – I have selected my local newspaper to be downloaded at 6 AM and sent to my email address. This is done automatically by calibre.

    I want calibre to auto start when I start gnome.

    I don’t seem to be able to do this.

    I put this in an executable file in my home folder in a file called

    ~/.config/autostart/calibre

    Inside this file I put:

    #!/bin/sh

    exec /usr/bin/calibre

    Then I chmod the file to make it executable.

    But it doesn’t start calibre!

    Do you know how I can get calibre to autostart so it downloads my newspaper?

    Thanks!

    David

  2. JayDogg says:

    I’m running freebsd and pretty new to it, I have gotten my Calibre Server up and running and my library built. I have a few questions about your start up script.
    1) Where would I save this file? Does it go into etc/rc.d?
    2) Does the file need to be name a certain name?
    3) Do I need to add anything to my rc.conf file?
    4) And base on my first questions any thing else I should know?