summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Gordon <assafgordon@gmail.com>2014-10-23 20:49:23 (GMT)
committerA. Gordon <assafgordon@gmail.com>2014-10-23 20:49:23 (GMT)
commit08d19f76f6c4de1f4e0f6ba894746a2b299c67a1 (patch)
tree52c2b3405ca83ecc10a80f0dc42618a4cce03664
parent8c5484cfa4849340d2978e5d6b356b3e37c45419 (diff)
downloadgsv-eval-08d19f76f6c4de1f4e0f6ba894746a2b299c67a1.zip
gsv-eval-08d19f76f6c4de1f4e0f6ba894746a2b299c67a1.tar.gz
gsv-eval-08d19f76f6c4de1f4e0f6ba894746a2b299c67a1.tar.bz2
Website: add start/stop scripts
-rwxr-xr-xwebsite/gsv-eval-web.sh167
-rwxr-xr-xwebsite/gsv-eval-worker.sh155
2 files changed, 322 insertions, 0 deletions
diff --git a/website/gsv-eval-web.sh b/website/gsv-eval-web.sh
new file mode 100755
index 0000000..3037f02
--- /dev/null
+++ b/website/gsv-eval-web.sh
@@ -0,0 +1,167 @@
+#!/bin/sh
+
+##
+## Startup script adapted from http://ipipet.teamerlich.org
+##
+# This file is part of iPipet.
+# copyright (c) 2014 Dina Zielinski (dina@wi.mit.edu)
+#
+# iPipet is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or any later version.
+
+# iPipet is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with iPipet. If not, see <http://www.gnu.org/licenses/agpl-3.0.html>.
+
+
+##
+## A user-land script, based gunicorn init.d script here:
+## https://gist.github.com/suda/748450
+##
+## 1. Adapted to run one specific application.
+## 2. Adapted to run as a non-system user (not ideal, but works)
+## 3. Adapter to write logs and PID to the script's directory (not idael, but works)
+## 4. minimal support for error reporting - not yet suitible for "/etc/init.d/" usage.
+
+die()
+{
+ BASE=$(basename "$0")
+ echo "$BASE: error: $@" >&2
+ exit 1
+}
+
+DESC="gsv-eval"
+## The application script name (e.g. "pooling.py")
+## This will determine the name of the PID and LOG files, as well.
+FLASK_APP_FILE=gsv_eval_flask.py
+## The name of the variable containing the flask application ('app' in most cases)
+FLASK_APP_VAR_NAME=app
+## IP To bind to (commonly: 0.0.0.0 or 127.0.0.1)
+BIND_IP=127.0.0.1
+BIND_TCP_PORT=5105
+## Number of thread for gunicorn
+WORKERS=2
+
+## Find the full path of the current directory
+## (note: readlink -e only works with GNU Coreutils)
+BASEDIR=$(readlink -e $(dirname "$0")) || exit 1
+
+[ -e "$BASEDIR/$FLASK_APP_FILE" ] \
+ || die "Flask script '$BASEDIR/$FLASK_APP_FILE' not found"
+FLASK_NAME=$(basename "$FLASK_APP_FILE" .py) || exit 1
+
+PIDFILE=/var/run/gsv-eval/$FLASK_NAME.pid
+ACCESSLOG=/var/log/gsv-eval/$FLASK_NAME.access.log
+ERRORLOG=/var/log/gsv-eval/$FLASK_NAME.error.log
+
+USER=www-data
+GROUP=www-data
+
+GUNICORN=$(which gunicorn) || die "'gunicorn' program not found"
+
+## For non-root users, 'start-stop-daemon' might not be in the $PATH,
+## so find it.
+START_STOP_DAEMON=/sbin/start-stop-daemon
+test -x "$START_STOP_DAEMON" \
+ || die "'start-stop-daemon' not found ($START_STOP_DAEMON)"
+
+start()
+{
+ "$START_STOP_DAEMON" --start \
+ --pidfile "$PIDFILE" \
+ --chdir "$BASEDIR" \
+ --exec "$GUNICORN" \
+ --chuid "$USER:$GROUP" \
+ --verbose \
+ -- \
+ --bind "$BIND_IP:$BIND_TCP_PORT" \
+ --workers "$WORKERS" \
+ --daemon \
+ --pid "$PIDFILE" \
+ --preload \
+ --log-level error \
+ --access-logfile "$ACCESSLOG" \
+ --error-logfile "$ERRORLOG" \
+ "$FLASK_NAME:$FLASK_APP_VAR_NAME"
+
+ ## Ugly Hack
+ ## 'gunicorn' returns 0 even if the flask application failed to load.
+ ## So wait a bit, then check the status
+ sleep 2
+ status
+}
+
+stop ()
+{
+ "$START_STOP_DAEMON" --stop \
+ --pidfile "$PIDFILE" \
+ --user "$USER" \
+ --name gunicorn
+}
+
+status()
+{
+ "$START_STOP_DAEMON" --status \
+ --pidfile "$PIDFILE" \
+ --user "$USER" \
+ --name gunicorn
+}
+
+reload()
+{
+ "$START_STOP_DAEMON" --stop \
+ --signal HUP \
+ --pidfile "$PIDFILE" \
+ --user "$USER" \
+ --name gunicorn
+}
+
+case "$1" in
+ start)
+ printf "Starting $DESC ..."
+ start
+ case "$?" in
+ 0) printf "OK\n" ;;
+ *) printf "Failed\n" ;;
+ esac
+ ;;
+ stop)
+ printf "Stopping $DESC ..."
+ stop
+ case "$?" in
+ 0|1) printf "OK\n" ;;
+ 2) printf "Failed\n" ;;
+ esac
+ ;;
+ status)
+ printf "Status-check $DESC ..."
+ status
+ case "$?" in
+ 0) printf "Running.\n" ;;
+ 1) printf "Not running (but PID file exists)\n" ;;
+ 3) printf "Not running\n" ;;
+ 4) printf "Failed to check status\n" ;;
+ esac
+ ;;
+ reload)
+ echo "Reloading $DESC"
+ reload
+ ;;
+ restart)
+ echo "Restarting $DESC"
+ stop
+ sleep 1
+ start
+ ;;
+ *)
+ echo "Usage: $(basename $0) {start|stop|status|restart|reload}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/website/gsv-eval-worker.sh b/website/gsv-eval-worker.sh
new file mode 100755
index 0000000..321fde1
--- /dev/null
+++ b/website/gsv-eval-worker.sh
@@ -0,0 +1,155 @@
+#!/bin/sh
+
+##
+## Startup script adapted from http://ipipet.teamerlich.org
+##
+# This file is part of iPipet.
+# copyright (c) 2014 Dina Zielinski (dina@wi.mit.edu)
+#
+# iPipet is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or any later version.
+
+# iPipet is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with iPipet. If not, see <http://www.gnu.org/licenses/agpl-3.0.html>.
+
+
+##
+## A user-land script, based gunicorn init.d script here:
+## https://gist.github.com/suda/748450
+##
+## 1. Adapted to run one specific application.
+## 2. Adapted to run as a www-data user (not ideal, but works)
+## 4. minimal support for error reporting - not yet suitible for "/etc/init.d/" usage.
+
+die()
+{
+ BASE=$(basename "$0")
+ echo "$BASE: error: $@" >&2
+ exit 1
+}
+
+DESC="gsv-eval-worker"
+NAME="gsv-eval-worker"
+PIDFILE=/var/run/gsv-eval/$NAME.pid
+STDOUT=/var/log/gsv-eval/$NAME.stdout.log
+STDERR=/var/log/gsv-eval/$NAME.stderr.log
+
+USER=www-data
+GROUP=www-data
+
+## Find the full path of the current directory
+## (note: readlink -e only works with GNU Coreutils)
+BASEDIR=$(readlink -e $(dirname "$0")) || exit 1
+
+test -e "gsv_eval_worker.py" \
+ || die "gsv_eval_worker.py not found (is this the correct directory?)"
+
+RQWORKER=$(which rqworker) || die "'rqworker' program not found"
+
+## For non-root users, 'start-stop-daemon' might not be in the $PATH,
+## so find it.
+START_STOP_DAEMON=/sbin/start-stop-daemon
+test -x "$START_STOP_DAEMON" \
+ || die "'start-stop-daemon' not found ($START_STOP_DAEMON)"
+
+
+
+start()
+{
+ "$START_STOP_DAEMON" --start \
+ --pidfile "$PIDFILE" \
+ --chdir "$BASEDIR" \
+ --exec "$RQWORKER" \
+ --chuid "$USER:$GROUP" \
+ --verbose \
+ --background \
+ --no-close \
+ --make-pidfile \
+ -- \
+ --verbose \
+ > "$STDOUT" 2>"$STDERR" \
+ || die "start-stop-daemon failed"
+
+ ## Ugly Hack
+ ## With '--background', start-stop-daemon returns 0 even if the
+ ## application failed to load.
+ ## So wait a bit, then check the status
+ sleep 2
+ status
+}
+
+stop ()
+{
+ "$START_STOP_DAEMON" --stop \
+ --pidfile "$PIDFILE" \
+ --user "$USER" \
+ --name rqworker
+}
+
+status()
+{
+ "$START_STOP_DAEMON" --status \
+ --pidfile "$PIDFILE" \
+ --user "$USER" \
+ --name rqworker
+}
+
+reload()
+{
+ "$START_STOP_DAEMON" --stop \
+ --signal HUP \
+ --pidfile "$PIDFILE" \
+ --user "$USER" \
+ --name rqworker
+}
+
+case "$1" in
+ start)
+ printf "Starting $DESC ..."
+ start
+ case "$?" in
+ 0) printf "OK\n" ;;
+ *) printf "Failed\n" ;;
+ esac
+ ;;
+ stop)
+ printf "Stopping $DESC ..."
+ stop
+ case "$?" in
+ 0|1) printf "OK\n" ;;
+ 2) printf "Failed\n" ;;
+ esac
+ ;;
+ status)
+ printf "Status-check $DESC ..."
+ status
+ case "$?" in
+ 0) printf "Running.\n" ;;
+ 1) printf "Not running (but PID file exists)\n" ;;
+ 3) printf "Not running\n" ;;
+ 4) printf "Failed to check status\n" ;;
+ esac
+ ;;
+ reload)
+ echo "Reloading $DESC"
+ reload
+ ;;
+ restart)
+ echo "Restarting $DESC"
+ stop
+ sleep 1
+ start
+ ;;
+ *)
+ echo "Usage: $(basename $0) {start|stop|status|restart|reload}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0