Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
### BEGIN INIT INFO
# Provides: bookserver
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Python Book Server
# Description: Python Book Server for Calibre Database
# Author: Typomedia Foundation
# Version: 1.4
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DIR=/usr/local/bin/cps
DESC="Python Book Server"
NAME=bookserver
DAEMON=/usr/bin/python
PIDFILE=/var/run/$NAME.pid
OPTIONS=$DIR/cps.py
USER=root
. /lib/lsb/init-functions
daemon_start () {
start-stop-daemon --start --background \
--make-pidfile --pidfile $PIDFILE --chdir $DIR \
--user $USER --chuid $USER --exec $DAEMON -- $OPTIONS
}
daemon_stop () {
#start-stop-daemon --stop --pidfile $PIDFILE --retry 10
kill $(ps aux | grep '[p]ython /usr/local/bin/cps/cps.py' | awk '{print $2}')
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
daemon_start
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
daemon_stop
log_end_msg $?
;;
restart|reload|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
daemon_stop
sleep 1
daemon_start
log_end_msg $?
;;
status)
status_of_proc "$DAEMON" "$DESC" && exit 0 || exit $?
;;
*)
log_action_msg "Usage: service $NAME {start|stop|restart|status}" || true
exit 2
;;
esac
exit 0
@typomedia

This comment has been minimized.

@typomedia

This comment has been minimized.

Copy link
Owner Author

commented Oct 26, 2014

add #!/usr/bin/env python in cps.py

@typomedia

This comment has been minimized.

Copy link
Owner Author

commented Oct 28, 2014

update-rc.d bookserver defaults 92

@typomedia

This comment has been minimized.

Copy link
Owner Author

commented Oct 28, 2014

update-rc.d -f bookserver remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.