Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
opensas committed Mar 29, 2012
0 parents commit 7f980f9
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
logs
project/project
project/target
#target #commented for deploying to openshift
tmp
.history
dist
5 changes: 5 additions & 0 deletions .openshift/action_hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# This is a simple build script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the deploy step. This script gets executed directly, so it
# could be python, php, ruby, etc.
5 changes: 5 additions & 0 deletions .openshift/action_hooks/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# This deploy hook gets executed after dependencies are resolved and the
# build hook has been run but before the application has been started back
# up again. This script gets executed directly, so it could be python, php,
# ruby, etc.
35 changes: 35 additions & 0 deletions .openshift/action_hooks/load_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# debug
# set -x

# check needed vars
if [[ -z $OPENSHIFT_REPO_DIR ]]; then
echo "Error: OPENSHIFT_REPO_DIR not defined"
return 1
fi

PLAY_PARAMS=""

PLAY_CONFIG_FILE="${OPENSHIFT_REPO_DIR}conf/openshift.conf"

if [[ -f $PLAY_CONFIG_FILE ]]; then

function read_conf {
local key=$1
local default=$2
local result=`grep "^$key[ |=]" $PLAY_CONFIG_FILE`

# key not found
if [[ -z "$result" ]]; then
echo $default
else
result=`echo "$result" | grep -oP "=.*" | cut -b 1 --complement`
echo $result
fi
}

PLAY_PARAMS=$(read_conf "openshift.play.params" $PLAY_PARAMS)
fi

return 0
4 changes: 4 additions & 0 deletions .openshift/action_hooks/post_deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# This is a simple post deploy hook executed after your application
# is deployed and started. This script gets executed directly, so
# it could be python, php, ruby, etc.
5 changes: 5 additions & 0 deletions .openshift/action_hooks/pre_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# This is a simple script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the build step. This script gets executed directly, so it
# could be python, php, ruby, etc.
22 changes: 22 additions & 0 deletions .openshift/action_hooks/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080


# loads $PLAY_PARAMS
. ${OPENSHIFT_REPO_DIR}.openshift/action_hooks/load_config

if [[ ! $? -eq 0 ]]; then
exit $?
fi

LOG_FILE="${OPENSHIFT_LOG_DIR}play.log"

APP_COMMAND="${OPENSHIFT_REPO_DIR}target/start $PLAY_PARAMS "\
"-Dhttp.port=${OPENSHIFT_INTERNAL_PORT} "\
"-Dhttp.address=${OPENSHIFT_INTERNAL_IP} "\
"-Dconfig.resource=openshift.conf"

echo $APP_COMMAND &>> $LOG_FILE
nohup bash -c "$APP_COMMAND &>> ${LOG_FILE} 2>&1" &> /dev/null &
65 changes: 65 additions & 0 deletions .openshift/action_hooks/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
# The logic to stop your application should be put in this script.

# debug
# set -x

LOG_FILE="${OPENSHIFT_LOG_DIR}play.log"

function kill_app {
COMMAND="$1"
# try 5 times to kill it
for c in `seq 1 5`; do
echo "Trying to kill proccess, attempt number $c" >> $LOG_FILE
echo "$COMMAND" >> $LOG_FILE
bash -c "$COMMAND &>> $LOG_FILE 2>&1" &> /dev/null
sleep $c
#killed it
if [[ -z `ps -A | grep ' java$'` ]]; then
if [[ -f "RUNNING_PID" ]]; then
rm RUNNING_PID
fi
popd > /dev/null
exit 0
fi
done
}

if [[ ! $? -eq 0 ]]; then
exit $?
fi

pushd "$OPENSHIFT_REPO_DIR" > /dev/null

#kill play if it was running
if [[ -f "RUNNING_PID" ]]; then

pid=`cat RUNNING_PID`
echo "Stopping play application" >> $LOG_FILE

if [[ -n $pid ]]; then
#try to kill it nicely
kill_app "kill -SIGTERM $pid"
#try to kill it harshly
kill_app "kill -SIGKILL $pid"
fi
fi

#it survived, try to kill java
if [[ -n `ps -A | grep java` ]]; then
echo "Stopping java proccess" >> $LOG_FILE
#try to kill it nicely
kill_app "pkill -SIGTERM java"
#try to kill it harshly
kill_app "pkill -SIGKILL java"
fi

#couldn't kill it
if [[ -n `ps -A | grep java` ]]; then
echo "Error: could not stop play application, error executing 'pkill java'" >> $LOG_FILE
popd
exit 1
fi

popd > /dev/null
exit 0
22 changes: 22 additions & 0 deletions .openshift/cron/README.cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Run scripts or jobs on a periodic basis
=======================================
Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly
directories will be run on a scheduled basis (frequency is as indicated by the
name of the directory) using run-parts.

run-parts ignores any files that are hidden or dotfiles (.*) or backup
files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved}

The presence of two specially named files jobs.deny and jobs.allow controls
how run-parts executes your scripts/jobs.
jobs.deny ===> Prevents specific scripts or jobs from being executed.
jobs.allow ===> Only execute the named scripts or jobs (all other/non-named
scripts that exist in this directory are ignored).

The principles of jobs.deny and jobs.allow are the same as those of cron.deny
and cron.allow and are described in detail at:
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access

See: man crontab or above link for more details and see the the weekly/
directory for an example.

Empty file.
Empty file.
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions .openshift/cron/weekly/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Run scripts or jobs on a weekly basis
=====================================
Any scripts or jobs added to this directory will be run on a scheduled basis
(weekly) using run-parts.

run-parts ignores any files that are hidden or dotfiles (.*) or backup
files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles
the files named jobs.deny and jobs.allow specially.

In this specific example, the chronograph script is the only script or job file
executed on a weekly basis (due to white-listing it in jobs.allow). And the
README and chrono.dat file are ignored either as a result of being black-listed
in jobs.deny or because they are NOT white-listed in the jobs.allow file.

For more details, please see ../README.cron file.

1 change: 1 addition & 0 deletions .openshift/cron/weekly/chrono.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Time And Relative D...n In Execution (Open)Shift!
3 changes: 3 additions & 0 deletions .openshift/cron/weekly/chronograph
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "`date`: `cat $(dirname \"$0\")/chrono.dat`"
12 changes: 12 additions & 0 deletions .openshift/cron/weekly/jobs.allow
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Script or job files listed in here (one entry per line) will be
# executed on a weekly-basis.
#
# Example: The chronograph script will be executed weekly but the README
# and chrono.dat files in this directory will be ignored.
#
# The README file is actually ignored due to the entry in the
# jobs.deny which is checked before jobs.allow (this file).
#
chronograph

7 changes: 7 additions & 0 deletions .openshift/cron/weekly/jobs.deny
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Any script or job files listed in here (one entry per line) will NOT be
# executed (read as ignored by run-parts).
#

README

Loading

0 comments on commit 7f980f9

Please sign in to comment.