Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/allenai/ike
Browse files Browse the repository at this point in the history
  • Loading branch information
sbhaktha committed Sep 23, 2016
2 parents 0318b5b + 68cae68 commit e658360
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 36 deletions.
117 changes: 117 additions & 0 deletions src/main/bin/ike_control.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

#usage: $0 [start|stop|status]

export APPROOT=$(cd $(dirname $0)/..; pwd -P)

if [ -e /etc/default/ike ]; then
. /etc/default/ike
else
echo "Missing config file: /etc/default/ike. Contact your administrator"
exit 1
fi

if [ $UID -eq 0 ]; then
echo "Do not run as root. exiting"
exit 1
fi

# vars defined in /etc/default/ike:
# START - used by rc.d to determine whether $0 should be invoked on system startup
# APPROOT - fully qualified path to install location
# CREDENTIALS - path to postgres pw file

#user defined variables
CLASS_NAME="org.allenai.ike.IkeToolWebapp"
#CLASS_PATH is determined programmatically below in start()
JVM_ARGS="-Xmx60G -Xms60G"
prog="ike"
LOGBACK_APP="$prog"
LOGBACK_CONF="$APPROOT/conf/logback.xml"
CONF_FILE="$APPROOT/conf/env.conf"

ike_action=$1

exec="/usr/bin/java"
SCRIPT_DIR="$APPROOT/bin"
pidfile=$APPROOT/${prog}.pid
stdoutfile=$APPROOT/${prog}.out
stderrfile=$APPROOT/${prog}.err

LOGBACK_ARGS="-Dlogback.appname=$LOGBACK_APP -Dlogback.configurationFile=$LOGBACK_CONF"
CONF_ARGS="-Dconfig.file=$CONF_FILE"

start() {
status > /dev/null
if [ $? -eq 0 ]; then
echo "$0 is already running."
return 0
fi

if [ -e "$CREDENTIALS" ]; then
source "$CREDENTIALS"
else
echo "Error: $CREDENTIALS not found; Should be defined in /etc/default/$prod. $0 will fail to start."
fi

cd $APPROOT
CLASS_PATH=`find lib -name '*.jar' | tr "\\n" :`
JAVA_ARGS="$JVM_ARGS -classpath $CLASS_PATH $CONF_ARGS $LOGBACK_ARGS"

# --- start the program ---
echo -n "Starting $prog: "
nohup $exec $JAVA_ARGS $CLASS_NAME > "$stdoutfile" 2> "$stderrfile" &
retval=$?
echo

sleep 2

ps -p $! > /dev/null
if [ $? -eq 0 ]; then
echo $! > "$pidfile"
fi

return $retval
}

stop() {
if ! [ -e $pidfile ]; then
echo "pidfile: $pidfile not found. Assumption: $prog is NOT running"
return 0
fi
kill `cat "$pidfile"` > /dev/null
retval=$?
rm $pidfile
return $retval
}

# returns 0 if running; 1 or 2 if not
status() {
if ! [ -e $pidfile ]; then
echo "pidfile: $pidfile not found. Assumption: $prog is NOT running"
return 2
fi
ps -p `cat "$pidfile"` > /dev/null
if [ $? -eq 0 ]; then
echo "$prog is running"
return 0
else
echo "$prog is NOT running"
return 1
fi
}

case "$1" in
start)
$1
;;
stop)
$1
;;
status)
$1
;;
*)
echo "Unsupported Input: $1. expected: start|stop|status"
;;
esac
4 changes: 0 additions & 4 deletions src/main/bin/prepare-env.sh

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/bin/webapp-prod.sh

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/bin/webapp-test.sh

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/bin/webapp.sh

This file was deleted.

1 change: 1 addition & 0 deletions src/main/etc/default/ike.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREDENTIALS="/opt/ops/var/s3/ops-keystore/database/ike/pgpass-prod.sh"
1 change: 1 addition & 0 deletions src/main/etc/default/ike.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREDENTIALS="/path/to/pgpass-<env>.sh"
26 changes: 26 additions & 0 deletions src/main/etc/init.d/ike
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: ike
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ike webapp
# Description: ike ike ike
### END INIT INFO

export APPROOT=$(cd $(dirname $(readlink -f $0))/../..; pwd)

. /etc/default/ike

exec="$APPROOT/bin/ike_control.sh"
exec_user="ai2service"

if ! [ $# -eq 1 ]; then
echo "usage: $0 stop|start|status"
exit 1
fi

sudo -u $exec_user $exec $1
exit $?
1 change: 1 addition & 0 deletions src/main/resources/pgpass-ENV.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export POSTGRES_PASSWORD='PASSWORD'

0 comments on commit e658360

Please sign in to comment.