#!/sbin/runscript # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: etherpad.initd,v 1.0 2011/03/11 17:11:50 lkraav Exp $ ## Adapted from https://github.com/redhog/pad/blob/master/debian/etherpad.init DAEMON_BASE="/secure/home/etherpad" DAEMON=$DAEMON_BASE/bin/run.sh DAEMON_ARGS="" PIDFILE=/var/run/etherpad/$SVCNAME.pid OOFFICE_LOG="/var/log/etherpad/ooffice.log" depend() { use net mta need mysql apache2 } start() { ebegin "Starting ${SVCNAME}" # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started pgrep -f 'java.*etherpad' > /dev/null && return 1 # ( cd "$DAEMON_BASE"; su - etherpad -s /bin/bash -c "bin/DocumentConverter.py --daemon" >> "$OOFFICE_LOG" 2>&1 ) & start-stop-daemon --background --chdir $DAEMON_BASE --chuid etherpad:etherpad --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \ $DAEMON_ARGS \ || return 2 # Add code here, if necessary, that waits for the process to be ready # to handle requests from services started subsequently which depend # on this one. As a last resort, sleep for some time. [ "$VERBOSE" != no ] && echo -n "Waiting for service to come up ..." for counter in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do echo "GET /" | netcat -w 1 localhost 9000 > /dev/null 2>&1 && break [ "$VERBOSE" != no ] && echo -n "." sleep 1 done [ "$VERBOSE" != no ] && echo "" eend $? } stop() { ebegin "Stopping ${SVCNAME}" # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred ( cd "$DAEMON_BASE"; su - etherpad -s /bin/bash -c "bin/DocumentConverter.py --shutdown" >> "$OOFFICE_LOG" 2>&1 ) & start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE eend $? }