aboutsummaryrefslogtreecommitdiffstats
path: root/config/foimongreld.ugly
diff options
context:
space:
mode:
Diffstat (limited to 'config/foimongreld.ugly')
-rw-r--r--config/foimongreld.ugly76
1 files changed, 76 insertions, 0 deletions
diff --git a/config/foimongreld.ugly b/config/foimongreld.ugly
new file mode 100644
index 000000000..9eaecb714
--- /dev/null
+++ b/config/foimongreld.ugly
@@ -0,0 +1,76 @@
+#!/bin/bash
+#
+# !!(*= $daemon_name *)!! Start the WhatDoTheyKnow web server daemon (mongrel)
+
+NAME=!!(*= $daemon_name *)!!
+RUNDIR=/data/vhost/!!(*= $vhost *)!!/mysociety/foi
+PIDFILE=/data/vhost/!!(*= $vhost *)!!/mysociety/foi/log/mongrel.pid
+DUSER=!!(*= $user *)!!
+
+function stop_mongrel {
+ if [ -e $PIDFILE ]
+ then
+ su $DUSER -c "cd $RUNDIR; /usr/bin/ruby -I/usr/lib/ruby/ /usr/bin/mongrel_rails stop"
+ sleep 5s
+ if [ -e $PIDFILE ]
+ then
+ if ( ps h -p `cat $PIDFILE` )
+ then
+ echo "kill -9 ing `cat $PIDFILE` because it failed to stop"
+ kill -9 `cat $PIDFILE`
+ sleep 2s
+ fi
+ fi
+ if [ -e $PIDFILE ]
+ then
+ rm $PIDFILE
+ fi
+ else
+ echo " pidfile does not exist, start first "
+ return 1
+ fi
+}
+
+function start_mongrel {
+ if [ -e $PIDFILE ]
+ then
+ echo " pidfile already exists, stop first "
+ return 1
+ else
+ su $DUSER -c "cd $RUNDIR; /usr/bin/ruby -I/usr/lib/ruby/ /usr/bin/mongrel_rails start -d"
+ fi
+}
+
+trap "" 1
+
+case "$1" in
+ start)
+ echo -n "Starting WhatDoTheyKnow web server daemon (mongrel): $NAME"
+ start_mongrel
+ ;;
+
+ stop)
+ echo -n "Stopping WriteToThem web server daemon (mongrel): $NAME"
+ stop_mongrel
+ ;;
+
+ restart)
+ echo -n "Restarting WriteToThem web server daemon (mongrel): $NAME"
+ stop_mongrel
+ start_mongrel
+ ;;
+
+ *)
+ echo "Usage: /etc/init.d/$NAME {start|stop|restart}"
+ exit 1
+ ;;
+esac
+
+if [ $? -eq 0 ]; then
+ echo .
+ exit 0
+else
+ echo " failed"
+ exit 1
+fi
+