This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 265e1c5
Showing
15 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "src/python2"] | ||
path = src/python2 | ||
url = https://github.com/python/cpython.git | ||
[submodule "src/rethinkdb"] | ||
path = src/rethinkdb | ||
url = https://github.com/rethinkdb/rethinkdb.git |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
check process rethinkdb | ||
with pidfile /var/vcap/sys/run/rethinkdb/pid | ||
start program "/var/vcap/jobs/rethinkdb/bin/ctl start" | ||
stop program "/var/vcap/jobs/rethinkdb/bin/ctl stop" | ||
group vcap |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
name: rethinkdb | ||
|
||
templates: | ||
ctl.erb: bin/ctl | ||
rethinkdb.conf.erb: rethinkdb.conf | ||
ctl_utils.sh.erb: bin/ctl_utils.sh | ||
|
||
packages: | ||
- rethinkdb | ||
|
||
properties: | ||
rethinkdb.cluster_ips: | ||
description: Array of ip addresses for nodes in the cluster | ||
example: | ||
- 10.244.0.2 | ||
- 10.244.0.3 | ||
- 10.244.0.4 | ||
default: [] | ||
rethinkdb.disable_admin: | ||
description: Set to true to disable web administration console | ||
example: false | ||
rethinkdb.http_port: | ||
description: RethinkDB web UI port | ||
example: 8080 | ||
default: 8080 | ||
rethinkdb.driver_port: | ||
description: RethinkDB client driver port | ||
example: 28015 | ||
default: 28015 | ||
rethinkdb.cluster_port: | ||
description: RethinkDB intracluster traffic port | ||
example: 29015 | ||
default: 29015 | ||
rethinkdb.initial_password: | ||
description: password for web UI user 'admin' | ||
example: secret |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux -o pipefail | ||
|
||
JOB_NAME=rethinkdb | ||
RUN_DIR=/var/vcap/sys/run/${JOB_NAME} | ||
DATA_DIR=/var/vcap/store/${JOB_NAME} | ||
LOG_DIR=/var/vcap/sys/log/${JOB_NAME} | ||
PIDFILE=${RUN_DIR}/pid | ||
PACKAGE_DIR=/var/vcap/jobs/${JOB_NAME}/packages | ||
CONFIG_FILE=/var/vcap/jobs/${JOB_NAME}/rethinkdb.conf | ||
|
||
source /var/vcap/jobs/$JOB_NAME/bin/ctl_utils.sh | ||
|
||
case $1 in | ||
|
||
start) | ||
pid_guard $PIDFILE $JOB_NAME | ||
|
||
mkdir -p $RUN_DIR | ||
mkdir -p $DATA_DIR | ||
mkdir -p $LOG_DIR | ||
|
||
chown -R vcap:vcap $RUN_DIR | ||
chown -R vcap:vcap $LOG_DIR | ||
|
||
exec $PACKAGE_DIR/rethinkdb/bin/rethinkdb \ | ||
--config-file $CONFIG_FILE \ | ||
--no-update-check \ | ||
--initial-password <%= p('rethinkdb.initial_password') %> \ | ||
>> $LOG_DIR/$JOB_NAME.stdout.log \ | ||
2>> $LOG_DIR/$JOB_NAME.stderr.log | ||
|
||
;; | ||
|
||
stop) | ||
kill_and_wait $PIDFILE | ||
|
||
;; | ||
|
||
*) | ||
echo "Usage: ctl {start|stop}" ;; | ||
esac | ||
exit 0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Helper functions used by ctl scripts | ||
|
||
# If loaded within monit ctl scripts then pipe output | ||
# If loaded from 'source ../utils.sh' then normal STDOUT | ||
redirect_output() { | ||
SCRIPT=$1 | ||
mkdir -p /var/vcap/sys/log/monit | ||
exec 1>> /var/vcap/sys/log/monit/$SCRIPT.log 2>&1 | ||
} | ||
|
||
pid_guard() { | ||
pidfile=$1 | ||
name=$2 | ||
|
||
if [ -f "$pidfile" ]; then | ||
pid=$(head -1 "$pidfile") | ||
|
||
if [ -n "$pid" ] && [ -e /proc/$pid ]; then | ||
echo "$name is already running, please stop it first" | ||
exit 1 | ||
fi | ||
|
||
echo "Removing stale pidfile..." | ||
rm $pidfile | ||
fi | ||
} | ||
|
||
wait_pid() { | ||
pid=$1 | ||
try_kill=$2 | ||
timeout=${3:-0} | ||
force=${4:-0} | ||
countdown=$(( $timeout * 10 )) | ||
|
||
echo wait_pid $pid $try_kill $timeout $force $countdown | ||
if [ -e /proc/$pid ]; then | ||
if [ "$try_kill" = "1" ]; then | ||
echo "Killing $pidfile: $pid " | ||
kill $pid | ||
fi | ||
while [ -e /proc/$pid ]; do | ||
sleep 0.1 | ||
[ "$countdown" != '0' -a $(( $countdown % 10 )) = '0' ] && echo -n . | ||
if [ $timeout -gt 0 ]; then | ||
if [ $countdown -eq 0 ]; then | ||
if [ "$force" = "1" ]; then | ||
echo -ne "\nKill timed out, using kill -9 on $pid... " | ||
kill -9 $pid | ||
sleep 0.5 | ||
fi | ||
break | ||
else | ||
countdown=$(( $countdown - 1 )) | ||
fi | ||
fi | ||
done | ||
if [ -e /proc/$pid ]; then | ||
echo "Timed Out" | ||
else | ||
echo "Stopped" | ||
fi | ||
else | ||
echo "Process $pid is not running" | ||
echo "Attempting to kill pid anyway..." | ||
kill $pid | ||
fi | ||
} | ||
|
||
wait_pidfile() { | ||
pidfile=$1 | ||
try_kill=$2 | ||
timeout=${3:-0} | ||
force=${4:-0} | ||
countdown=$(( $timeout * 10 )) | ||
|
||
if [ -f "$pidfile" ]; then | ||
pid=$(head -1 "$pidfile") | ||
if [ -z "$pid" ]; then | ||
echo "Unable to get pid from $pidfile" | ||
exit 1 | ||
fi | ||
|
||
wait_pid $pid $try_kill $timeout $force | ||
|
||
rm -f $pidfile | ||
else | ||
echo "Pidfile $pidfile doesn't exist" | ||
fi | ||
} | ||
|
||
kill_and_wait() { | ||
pidfile=$1 | ||
# Monit default timeout for start/stop is 30s | ||
# Append 'with timeout {n} seconds' to monit start/stop program configs | ||
timeout=${2:-25} | ||
force=${3:-1} | ||
if [[ -f ${pidfile} ]] | ||
then | ||
wait_pidfile $pidfile 1 $timeout $force | ||
else | ||
# TODO assume $1 is something to grep from 'ps ax' | ||
pid="$(ps auwwx | grep "$1" | awk '{print $2}')" | ||
wait_pid $pid 1 $timeout $force | ||
fi | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
directory=/var/vcap/store/rethinkdb | ||
pid-file=/var/vcap/sys/run/rethinkdb/pid | ||
log-file=/var/vcap/sys/log/rethinkdb/rethinkdb.log | ||
bind=all | ||
http-port=<%= p('rethinkdb.http_port') %> | ||
driver-port=<%= p('rethinkdb.driver_port') %> | ||
cluster-port=<%= p('rethinkdb.cluster_port') %> | ||
runuser=vcap | ||
rungroup=vcap | ||
<% if_p('rethinkdb.disable_admin') do %> | ||
no-http-admin | ||
<% end %> | ||
<% p('rethinkdb.cluster_ips').each do |ip| %> | ||
join=<%= "#{ip}:#{p('rethinkdb.cluster_port')}" %> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
# abort script on any command that exits with a non zero value | ||
set -eux -o pipefail | ||
|
||
CPUS=`grep -c ^processor /proc/cpuinfo` | ||
|
||
echo `pwd` | ||
|
||
ls -lha | ||
|
||
pushd python2 | ||
./configure --prefix=${BOSH_INSTALL_TARGET} | ||
make -j${CPUS} | ||
make install | ||
popd |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# abort script on any command that exits with a non zero value | ||
set -e |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
name: python2 | ||
|
||
dependencies: [] | ||
|
||
files: | ||
- python2 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
# abort script on any command that exits with a non zero value | ||
set -eux -o pipefail | ||
|
||
CPUS=`grep -c ^processor /proc/cpuinfo` | ||
|
||
echo `pwd` | ||
|
||
ls -lha | ||
|
||
export PATH=/var/vcap/packages/python/bin:$PATH | ||
export PYTHON=/var/vcap/packages/python2/bin/python | ||
|
||
pushd rethinkdb | ||
./configure --allow-fetch --prefix=${BOSH_INSTALL_TARGET} | ||
make -j${CPUS} | ||
make install | ||
popd |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# abort script on any command that exits with a non zero value | ||
set -e |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
name: rethinkdb | ||
|
||
dependencies: | ||
- python2 | ||
|
||
files: | ||
- rethinkdb |