init scripts for gmg
authorLisa Marie Maginnis <lisam@fsf.org>
Sun, 28 Feb 2016 07:43:27 +0000 (02:43 -0500)
committerLisa Marie Maginnis <lisam@fsf.org>
Sun, 28 Feb 2016 07:43:27 +0000 (02:43 -0500)
files/etc/init.d/install-mediagoblin/DEFAULT
files/etc/init.d/mediagoblin-celery-worker/DEFAULT [new file with mode: 0755]
files/etc/init.d/mediagoblin-paster/DEFAULT [new file with mode: 0755]
scripts/GMG/15_install_gmg.sh

index 966d4f48b54433f8dd403a7f23150a36596e63e5..63af9e48c4f154248a049ad8fecdff626f3c2910 100755 (executable)
@@ -23,4 +23,5 @@ if [ ! -d mediagoblin ]; then
     mkdir user_dev && chmod 750 user_dev
     ./bin/easy_install flup
 
+    update-rc.d mediagoblin defaults
 fi
diff --git a/files/etc/init.d/mediagoblin-celery-worker/DEFAULT b/files/etc/init.d/mediagoblin-celery-worker/DEFAULT
new file mode 100755 (executable)
index 0000000..55b9638
--- /dev/null
@@ -0,0 +1,164 @@
+#!/bin/bash
+# /etc/init.d/mediagoblin-celery-worker
+#
+## LICENSE: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
+# To the extent possible under law, Joar Wandborg <http://wandborg.se> has
+# waived all copyright and related or neighboring rights to
+# mediagoblin-celery-worker. This work is published from Sweden.
+#
+## CREDIT
+# Credit goes to jpope <http://jpope.org/> and 
+# chimo <http://chimo.chromic.org/>. From which' Arch init scripts this is
+# based upon.
+#
+### BEGIN INIT INFO
+# Provides:          mediagoblin-celery-worker
+# Required-Start:    $network $named $local_fs
+# Required-Stop:     $remote_fs $syslog $network $named $local_fs
+# Should-Start:      postgres $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: MediaGoblin Celery task processor init script
+# Description:       This script will initiate the GNU MediaGoblin Celery 
+#                    task processor 
+### END INIT INFO
+
+################################################################################
+# CHANGE THIS
+# to suit your environment
+################################################################################
+MG_ROOT=GMG_PATH_TOKEN/mediagoblin
+MG_USER=mediagoblin
+################################################################################
+# NOW STOP
+# You probably won't have to change anything else.
+################################################################################
+
+set -e
+
+DAEMON_NAME=mediagoblin-celery-worker
+
+MG_BIN=$MG_ROOT/bin
+MG_CELERYD_BIN=$MG_BIN/celery\ worker
+MG_CONFIG=$MG_ROOT/mediagoblin_local.ini
+MG_CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery
+MG_CELERYD_PID_FILE=/var/run/mediagoblin/$DAEMON_NAME.pid
+MG_CELERYD_LOG_FILE=/var/log/mediagoblin/$DAEMON_NAME.log
+
+set_up_directories() {
+    install -o $MG_USER -g users -d -m 755 /var/log/mediagoblin
+    install -o $MG_USER -g users -d -m 755 /var/run/mediagoblin
+}
+
+set_up_directories
+
+# Include LSB helper functions
+. /lib/lsb/init-functions
+
+wait_for_death() {
+    pid=$1
+    seconds=1
+
+    if [ -z "$2" ]; then
+        kill_at=20
+    else
+        kill_at=$2
+    fi
+
+    if [ -z "$pid" ]; then
+        log_action_msg "Could not get PID. Aborting"
+        log_end_msg 1
+        exit 1
+    fi
+
+    while ps ax | grep -v grep | grep $pid > /dev/null; do
+        sleep 1
+        seconds=$(expr $seconds + 1)
+        if [ $seconds -ge $kill_at ]; then
+            log_action_msg "Failed to shut down after $kill_at seconds. Aborting"
+            log_end_msg 1
+            exit 1
+        fi
+    done
+    log_end_msg 0
+}
+
+wait_for_pidfile() {
+    pidfile=$1
+    kill_at=20
+    seconds=1
+
+    while ! [[ -f $pidfile ]]; do
+        sleep 1
+        seconds=$(expr $seconds + 1)
+
+        if [ $seconds -ge $kill_at ]; then
+            log_action_msg "Can't find the PID file," \
+                " the application must have crashed."
+            log_end_msg 1
+            exit 1
+        fi
+    done
+}
+
+getPID() {
+    # Discard any errors from cat
+    cat $MG_CELERYD_PID_FILE 2>/dev/null
+}
+
+case "$1" in 
+    start)
+        # Start the MediaGoblin celery worker process
+        log_daemon_msg "Starting GNU MediaGoblin Celery task queue" "$DAEMON_NAME"
+        if [ -z "$(getPID)" ]; then
+            # TODO: Could we send things to log a little bit more beautiful?
+            su -s /bin/sh -c "cd $MG_ROOT && \
+                MEDIAGOBLIN_CONFIG=$MG_CONFIG \
+                CELERY_CONFIG_MODULE=$MG_CELERY_CONFIG_MODULE \
+                $MG_CELERYD_BIN \
+                --pidfile=$MG_CELERYD_PID_FILE \
+                -f $MG_CELERYD_LOG_FILE 2>&1 >> $MG_CELERYD_PID_FILE" \
+                - $MG_USER 2>&1 >> $MG_CELERYD_LOG_FILE &
+
+            CELERYD_RESULT=$?
+
+            wait_for_pidfile $MG_CELERYD_PID_FILE
+
+            log_end_msg $CELERYD_RESULT
+        else
+            # Failed because the PID file indicates it's running
+            log_action_msg "PID file $MG_CELERYD_PID_FILE already exists"
+            log_end_msg 1
+        fi
+        ;;
+    stop)
+        log_daemon_msg "Stopping GNU MediaGoblin Celery task queue" "$DAEMON_NAME"
+        if [ -z "$(getPID)" ]; then
+            # Failed because the PID file indicates it's not running
+            log_action_msg "Could not get PID"
+            log_end_msg 1
+            exit 1
+        else
+            kill $(getPID)
+
+            wait_for_death $(getPID)
+        fi
+        ;;
+    restart)
+        $0 stop
+        $0 start
+        ;;
+    status)
+        if ! [ -z "$(getPID)" ]; then
+            echo "$DAEMON_NAME start/running, process $(getPID)"
+        else
+            echo "$DAEMON_NAME stopped."
+        fi
+        ;;
+    *)
+        echo "Usage: $0 {restart|start|stop|status}"
+        exit 1
+        ;;
+esac
+
+exit 0
\ No newline at end of file
diff --git a/files/etc/init.d/mediagoblin-paster/DEFAULT b/files/etc/init.d/mediagoblin-paster/DEFAULT
new file mode 100755 (executable)
index 0000000..8b37c45
--- /dev/null
@@ -0,0 +1,131 @@
+#!/bin/sh
+# /etc/init.d/mediagoblin-paster
+#
+## LICENSE: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
+# To the extent possible under law, Joar Wandborg <http://wandborg.se> has
+# waived all copyright and related or neighboring rights to
+# mediagoblin-paster. This work is published from Sweden.
+#
+## CREDIT
+# Credit goes to jpope <http://jpope.org/> and 
+# chimo <http://chimo.chromic.org/>. From which' Arch init scripts this is
+# based upon.
+#
+### BEGIN INIT INFO
+# Provides:          mediagoblin-paster
+# Required-Start:    $network $named $local_fs
+# Required-Stop:     $remote_fs $syslog $network $named $local_fs
+# Should-Start:      postgresql $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: MediaGoblin paster FCGI server init script
+# Description:       This script will initiate the GNU MediaGoblin paster
+#                    fcgi server.
+### END INIT INFO
+
+################################################################################
+# CHANGE THIS
+# to suit your environment
+################################################################################
+MG_ROOT=GMG_PATH_TOKEN/mediagoblin
+MG_USER=mediagoblin
+################################################################################
+# NOW STOP
+# You probably won't have to change anything else.
+################################################################################
+
+set -e
+
+DAEMON_NAME=mediagoblin-paster
+
+MG_BIN=$MG_ROOT/bin
+MG_PASTER_BIN=$MG_BIN/paster
+MG_PASTE_INI=$MG_ROOT/paste_local.ini
+MG_FCGI_HOST=127.0.0.1
+MG_FCGI_PORT=26543
+MG_PASTER_PID_FILE=/var/run/mediagoblin/$DAEMON_NAME.pid
+MG_PASTER_LOG_FILE=/var/log/mediagoblin/$DAEMON_NAME.log
+
+set_up_directories() {
+    install -o $MG_USER -g users -d -m 755 /var/log/mediagoblin
+    install -o $MG_USER -g users -d -m 755 /var/run/mediagoblin
+}
+
+set_up_directories
+
+# Include LSB helper functions
+. /lib/lsb/init-functions
+
+getPID () {
+    # Discard any errors from cat
+    cat $MG_PASTER_PID_FILE 2>/dev/null
+}
+
+case "$1" in 
+    start)
+        # Start the MediaGoblin paster process
+        log_daemon_msg "Starting GNU MediaGoblin paster fcgi server" "$DAEMON_NAME"
+       if [ ! -f $MG_PASTE_INI ]; then
+            MG_PASTE_INI=$MG_ROOT/paste.ini
+           fi
+        if [ -z "$(getPID)" ]; then
+            su -s /bin/sh -c "CELERY_ALWAYS_EAGER=False $MG_PASTER_BIN serve \
+                $MG_PASTE_INI \
+                --server-name=fcgi \
+                fcgi_host=$MG_FCGI_HOST fcgi_port=$MG_FCGI_PORT \
+                --pid-file=$MG_PASTER_PID_FILE \
+                --log-file=$MG_PASTER_LOG_FILE \
+                --daemon" - $MG_USER 2>&1 > /dev/null
+
+            PASTER_RESULT=$?
+
+            # Sleep for a while until we're kind of certain that paster has
+            # had it's time to initialize
+            TRIES=0
+            while ! [ "X$PASTER_RESULT" != "X" ]; do
+                log_action_msg "Tried $TRIES time(s)"
+                sleep 0.1
+                TRIES=$((TRIES+1))
+            done
+
+            log_end_msg $PASTER_RESULT
+        else
+            # Failed because the PID file indicates it's running
+            log_action_msg "PID file $MG_PASTER_BIN already exists"
+            log_end_msg 1
+        fi
+        ;;
+    stop)
+        log_daemon_msg "Stopping GNU MediaGoblin paster fcgi server" "$DAEMON_NAME"
+        if [ -z "$(getPID)" ]; then
+            # Failed because the PID file indicates it's not running
+            RET=1
+        else
+            kill $(getPID)
+
+            if [ $? -gt 0 ]; then
+                RET=1
+            else
+                RET=0
+            fi
+        fi
+        log_end_msg $RET
+        ;;
+    restart)
+        $0 stop
+        $0 start
+        ;;
+    status)
+        if ! [ -z "$(getPID)" ]; then
+            echo "$DAEMON_NAME start/running, process $(getPID)"
+        else
+            echo "$DAEMON_NAME stopped."
+        fi
+        ;;
+    *)
+        echo "Usage: $0 {restart|start|stop|status}"
+        exit 1
+        ;;
+esac
+
+exit 0
index d5056b2bce17e711abd328cc425de135fc93590c..4a3fa3e488e25f5201fa03a8d8aa90421054474d 100755 (executable)
@@ -1,5 +1,10 @@
 #!/bin/bash
 
 fcopy -Bv /etc/init.d/install-mediagoblin
+fcopy -Bv /etc/init.d/mediagoblin-paster
+fcopy -Bv /etc/init.d/mediagoblin-celery-worker
+
 $ROOTCMD update-rc.d install-mediagoblin defaults
 sed 's^GMG_PATH_TOKEN^'$GMG_PATH'^g' -i $target/etc/init.d/install-mediagoblin
+sed 's^GMG_PATH_TOKEN^'$GMG_PATH'^g' -i $target/etc/init.d/mediagoblin-celery-worker
+sed 's^GMG_PATH_TOKEN^'$GMG_PATH'^g' -i $target/etc/init.d/mediagoblin-paster