Skip to content

Commit

Permalink
[DEB] permit packaging on debian squeeze using sysvinit as dameon script
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy92 committed Jan 28, 2013
1 parent 272ae5f commit fc57fa5
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -25,6 +25,7 @@ opencv
/debian/thumbor.debhelper.log
/debian/thumbor.postinst.debhelper
/debian/thumbor.preinst.debhelper
/debian/thumbor.postrm.debhelper
/debian/thumbor.prerm.debhelper
/debian/thumbor.substvars
/debian/tmp/
11 changes: 11 additions & 0 deletions debian/rules
Expand Up @@ -2,6 +2,14 @@

PYTHON2 ?= $(shell pyversions -vr)

# copy good script for upstart capable system or not
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
PREPINITSRC='debian/thumbor.ubuntu.upstart'
PREPINITDST='debian/thumbor.upstart'
else
PREPINITSRC='debian/thumbor.debian.init'
PREPINITDST='debian/thumbor.init'
endif

build build-arch: debsetup.py
python$(PYTHON2) debsetup.py build
Expand All @@ -27,12 +35,15 @@ binary-arch: build-arch
install -d -o root -g root -m 755 debian/thumbor/etc debian/thumbor/etc/init/
install -p -o root -g root -m 644 debian/thumbor.conf debian/thumbor/etc
install -p -o root -g root -m 644 debian/thumbor-worker.upstart debian/thumbor/etc/init/thumbor-worker.conf
rm -f debian/thumbor.upstart debian/thumbor.init
cp $(PREPINITSRC) $(PREPINITDST)
dh_install --exclude=.c
dh_python2
dh_strip
dh_shlibdeps
dh_installdirs
dh_installdocs README.mkd
$(PREPINIT)
dh_installinit --restart-after-upgrade
dh_installchangelogs
dh_lintian
Expand Down
123 changes: 123 additions & 0 deletions debian/thumbor.debian.init
@@ -0,0 +1,123 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: thumbor
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Thumbor image manipulation service
# Description: Thumbor is a Python service providing an HTTP GET API to manipulate images
# This startup script launch as much as service as ports defined in /etc/default/thumbor
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=thumbor

conffile=/etc/thumbor.conf
keyfile=/etc/thumbor.key
ip=0.0.0.0
port=8888

DAEMON=/usr/bin/$NAME
DAEMON_ARGS="-c ${conffile} -i ${ip} -k ${keyfile}"
PIDDIR=/var/run/$NAME
USER=thumbor

. /lib/lsb/init-functions

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

#Service must not be disabled
if ! [ "$enabled" != "0" ] || [ "$force_start" = "1" ]; then
echo "Thumbor service is desabled by /etc/default/$NAME"
exit 0
fi

#
# Function that starts the daemon/service
#
do_start()
{
mkdir -p $PIDDIR
#Loop on all conf for ports
for p in `echo $port | tr ',' ' '`; do
start-stop-daemon --start --quiet -b -m -c $USER --pidfile $PIDDIR/$p.pid --exec $DAEMON -- $DAEMON_ARGS -p $p || return 2
done
}

#
# Function that stops the daemon/service
#
do_stop()
{
ret=0
#Loop on all pids available
for i in $PIDDIR/*.pid; do
if [ -e $i ]; then
kill `cat $i`
if [ $? -ne 0 ]; then
ret=$?
fi
rm -f $i
fi
done
if [ "$ret" != 0 ]; then
return 1
fi
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
*) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
*) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

:

File renamed without changes.

0 comments on commit fc57fa5

Please sign in to comment.