Created
October 1, 2012 15:42
-
-
Save boris317/3812583 to your computer and use it in GitHub Desktop.
OpenShift action hooks for python tornado deployment.
This file contains hidden or 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/bash | |
| # | |
| # .openshift/action_hooks/build | |
| # | |
| DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| source $DIR/../env.sh | |
| if [ ! -d $X_OPENSHIFT_VENV ]; then | |
| echo "[build] $(virtualenv --distribute $X_OPENSHIFT_VENV)" | |
| fi | |
| echo "[build] $($X_OPENSHIFT_VENV/bin/pip install -e ${OPENSHIFT_REPO_DIR})" |
This file contains hidden or 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/bash | |
| # | |
| # .openshift/env.sh | |
| # | |
| # This script will sense if we are running locally and set some sane | |
| # defaults for all of the OPENSHIFT_XX environmental variables. If | |
| # we are running locally all files will be created in PROJECT_ROOT/.local | |
| # | |
| # NOTE: Openshift paths seem to all end in a "/". Assuming this | |
| # to always be true will probably bite me in the ass. (e.g. fix) | |
| PWD=$( cd "$( dirname "$0" )" && pwd ) | |
| if [ -z "${OPENSHIFT_APP_NAME+x}" ] | |
| then | |
| X_OPENSHIFT_RUNNING_LOCAL=true | |
| OPENSHIFT_APP_NAME="local_app" | |
| else | |
| X_OPENSHIFT_RUNNING_LOCAL=false | |
| fi | |
| if [ -z "${OPENSHIFT_REPO_DIR+x}" ]; then | |
| OPENSHIFT_REPO_DIR=$PWD | |
| for i in 1 2; do | |
| OPENSHIFT_REPO_DIR=$(dirname $OPENSHIFT_REPO_DIR) | |
| done | |
| OPENSHIFT_REPO_DIR="${OPENSHIFT_REPO_DIR}/" | |
| fi | |
| if [ -z "${OPENSHIFT_DATA_DIR+x}" ]; then OPENSHIFT_DATA_DIR="${OPENSHIFT_REPO_DIR}.local/data/"; fi | |
| if [ -z "${OPENSHIFT_LOG_DIR+x}" ]; then OPENSHIFT_LOG_DIR="${OPENSHIFT_REPO_DIR}.local/logs/"; fi | |
| if [ -z "${OPENSHIFT_RUN_DIR+x}" ]; then OPENSHIFT_RUN_DIR="${OPENSHIFT_REPO_DIR}.local/runtime/"; fi | |
| if [ -z "${OPENSHIFT_TMP_DIR+x}" ]; then OPENSHIFT_TMP_DIR="${OPENSHIFT_REPO_DIR}.local/tmp/"; fi | |
| if [ ! -d $OPENSHIFT_DATA_DIR ]; then mkdir -p $OPENSHIFT_DATA_DIR; fi | |
| if [ ! -d $OPENSHIFT_LOG_DIR ]; then mkdir -p $OPENSHIFT_LOG_DIR; fi | |
| if [ ! -d $OPENSHIFT_RUN_DIR ]; then mkdir -p $OPENSHIFT_RUN_DIR; fi | |
| if [ ! -d $OPENSHIFT_TMP_DIR ]; then mkdir -p $OPENSHIFT_TMP_DIR; fi | |
| X_OPENSHIFT_PID_FILE="${OPENSHIFT_RUN_DIR}${OPENSHIFT_APP_NAME}.pid" | |
| X_OPENSHIFT_VENV="${OPENSHIFT_DATA_DIR}env2.6" | |
| PYTHON_EGG_CACHE="${OPENSHIFT_TMP_DIR}egg_cache" |
This file contains hidden or 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
| #!/usr/bin/env python | |
| # | |
| # Example diy/run.py script. | |
| # Gets called by .openshift/action_hooks/start | |
| # | |
| import os | |
| from tornado.wsgi import WSGIContainer | |
| from tornado.httpserver import HTTPServer | |
| from tornado.ioloop import IOLoop | |
| from flaskexample import make_app | |
| def serve(app): | |
| http_server = HTTPServer(WSGIContainer(app)) | |
| http_server.listen( | |
| int(os.environ.get("OPENSHIFT_INTERNAL_PORT", 8080)), | |
| address=os.environ.get("OPENSHIFT_INTERNAL_IP", "127.0.0.1") | |
| ) | |
| IOLoop.instance().start() | |
| serve(make_app()) |
This file contains hidden or 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/bash | |
| # | |
| # .openshift/action_hooks/start | |
| # | |
| DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| source $DIR/../env.sh | |
| if ! $X_OPENSHIFT_RUNNING_LOCAL; then | |
| source $X_OPENSHIFT_VENV/bin/activate | |
| fi | |
| LOG_FILE="${OPENSHIFT_LOG_DIR}app.log" | |
| RUN_CMD="${OPENSHIFT_REPO_DIR}diy/run.py" | |
| echo "[start] Staring ${OPENSHIFT_APP_NAME}..." | |
| if [ -e $X_OPENSHIFT_PID_FILE ]; then | |
| echo "[start] Found pid file. App might already be running." | |
| $DIR/stop | |
| fi | |
| nohup $RUN_CMD > $LOG_FILE 2>&1 & | |
| PID=$! | |
| echo "[start] ${OPENSHIFT_APP_NAME} started. PID: ${PID}" | |
| echo $PID > $X_OPENSHIFT_PID_FILE | |
| exit 0 |
This file contains hidden or 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/bash | |
| # | |
| # .openshift/action_hooks/stop | |
| # | |
| function remove_pid { | |
| echo "[stop] Removing $X_OPENSHIFT_PID_FILE." | |
| rm $X_OPENSHIFT_PID_FILE | |
| } | |
| DIR=$( cd "$( dirname "$0" )" && pwd ) | |
| source $DIR/../env.sh | |
| if [ ! -e $X_OPENSHIFT_PID_FILE ]; then | |
| echo "[stop] Couldn't find a PID file." | |
| exit 1 | |
| fi | |
| echo "[stop] Attempting to kill pid $(cat $X_OPENSHIFT_PID_FILE)..." | |
| KILL_OUTPUT=$(kill $(cat $X_OPENSHIFT_PID_FILE) 2>&1) | |
| if [ $? -eq 0 ] | |
| then | |
| echo "[stop] Successful." | |
| remove_pid | |
| exit 0 | |
| else | |
| echo "[stop] Failed. ${KILL_OUTPUT}" | |
| remove_pid | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment