Last active
August 14, 2016 18:50
-
-
Save koehn/fde0832318a6328f20c8 to your computer and use it in GitHub Desktop.
Init file to start/stop Diaspora. Requires a file in /home/diaspora/diaspora/diaspora-init (see my gists for more). Hit me up on diaspora at bkoehn@diaspora.koehn.com if you have any questions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: diaspora | |
# Required-Start: apache2 | |
# Required-Stop: | |
# Should-Start: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: | |
# Short-Description: Diaspora social networking pod server | |
# Description: Diaspora is a social networking pod server. | |
### END INIT INFO | |
# Load the VERBOSE setting and other rcS variables | |
. /lib/init/vars.sh | |
# Define LSB log_* functions. | |
. /lib/lsb/init-functions | |
PROC_NAME=Diaspora | |
HOME_DIR=/home/diaspora | |
DAEMON=$HOME_DIR/diaspora/diaspora-init | |
PID_FILE=/var/run/diaspora.pid | |
RUN_AS_USER=diaspora | |
WAITFORDAEMON=60 | |
wait_for_deaddaemon () { | |
pid=$1 | |
sleep 1 | |
if test -n "$pid" | |
then | |
if kill -0 $pid 2>/dev/null | |
then | |
cnt=0 | |
while kill -0 $pid 2>/dev/null | |
do | |
cnt=`expr $cnt + 1` | |
if [ $cnt -gt $WAITFORDAEMON ] | |
then | |
log_action_end_msg 1 "still running" | |
exit 1 | |
fi | |
sleep 1 | |
[ "`expr $cnt % 3`" != 2 ] || log_action_cont_msg "" | |
done | |
fi | |
fi | |
log_action_end_msg 0 | |
} | |
case "$1" in | |
start) | |
log_action_begin_msg "Starting $PROC_NAME service: " | |
if start-stop-daemon --start --user $RUN_AS_USER --pidfile $PID_FILE --startas $DAEMON --chuid $RUN_AS_USER --background --make-pidfile | |
then | |
log_action_end_msg 0 | |
else | |
log_action_end_msg 1 | |
exit 1 | |
fi | |
;; | |
stop) | |
log_action_begin_msg "Stopping $PROC_NAME service: " | |
pid=`cat $PID_FILE 2>/dev/null` || true | |
if test ! -f $PID_FILE -o -z "$pid"; then | |
log_action_end_msg 0 "not running - there is no $PID_FILE" | |
exit 0 | |
fi | |
if start-stop-daemon --stop --user $RUN_AS_USER --pidfile $PID_FILE | |
then | |
wait_for_deaddaemon $pid | |
elif | |
kill -0 $pid 2>/dev/null; then | |
log_action_end_msg 1 "Is $pid not $PROC_NAME? Is $DAEMON a different binary now?" | |
exit 1 | |
else | |
log_action_end_msg 1 "$DAEMON died: process $pid not running; or permission denied" | |
exit 1 | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment