1. #!/bin/bash
  2.  
  3. . /etc/rc.conf
  4. . /etc/rc.d/functions
  5.  
  6. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  7. DESC="Calibre Content Server"
  8. NAME=calibre-server
  9. DAEMON=/usr/bin/$NAME
  10. PIDFILE=/var/run/$NAME.pid
  11. PID=$(cat $PIDFILE 2>/dev/null)
  12.  
  13. CONTENT=/home/user/Library
  14. PORT=9797
  15. MAX_COVER=600x800
  16. USERNAME=calibre
  17. PASSWORD=""
  18.  
  19. DAEMON_ARGS="--develop --with-library=$CONTENT --pidfile=$PIDFILE --port=$PORT --max-cover=$MAX_COVER --username=$USERNAME --password=$PASSWORD --daemonize"
  20.  
  21. # Exit if the package is not installed
  22. [ -x "$DAEMON" ] || exit 0
  23.  
  24. # Read configuration variable file if it is present
  25. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  26.  
  27. case "$1" in
  28. start)
  29. stat_busy "Starting $DESC"
  30. $DAEMON $DAEMON_ARGS > /dev/null 2>&1
  31. if [ $? -gt 0 ]; then
  32. stat_fail
  33. else
  34. add_daemon $NAME
  35. stat_done
  36. fi
  37. ;;
  38. stop)
  39. stat_busy "Stopping $DESC"
  40. [ ! -z "$PID" ] && kill $PID &> /dev/null
  41. if [ $? -gt 0 ]; then
  42. stat_fail
  43. else
  44. rm_daemon $NAME
  45. rm $PIDFILE
  46. stat_done
  47. fi
  48. ;;
  49. restart)
  50. $0 stop
  51. $0 start
  52. ;;
  53. *)
  54. echo "usage: $0 {start|stop|restart}"
  55. ;;
  56. esac
  57. exit 0