Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract common code into 'bootstrap', and allow a bootstrap.user for …

…plugging in rvm etc.
  • Loading branch information...
commit e7b31af8923743d07f729030436baab952d1f766 1 parent 80a53d6
@purcell authored
View
1  bin/.gitignore
@@ -0,0 +1 @@
+*
View
19 bootstrap
@@ -0,0 +1,19 @@
+# -*- mode: shell-script -*-
+#
+# This is designed to be sourced by the various other 'run' scripts in order to
+# establish the working environment. Do not edit this file! Instead, create a file
+# 'bootstrap.user', and set additional env vars / paths there.
+
+BASE=$(dirname $(readlink $0))
+BASE=$($BASE/readlink_canonical $BASE)
+PATH=$BASE/script:$BASE/bin:$BASE:$PATH
+export PATH
+USER=$(id -un)
+APP_DIR=$(readlink_canonical $BASE/app)
+if [ ! -d "$APP_DIR" ]; then
+ echo "no such app dir: $APP_DIR (did you create a symlink to your Rails app?)" 1>&2;
+ exit 2
+fi
+
+[[ -s "$BASE/bootstrap.user" ]] && . "$BASE/bootstrap.user"
+true
View
11 ferret-server-run
@@ -1,11 +1,4 @@
#!/bin/sh -e
-BASE=$(dirname $(readlink $0))
-APP_DIR=$BASE/app
-
-if [ ! -d "$APP_DIR" ]; then
- echo "no such app dir: $APP_DIR (did you create a symlink to your Rails app?)" 1>&2;
- exit 2
-fi
-
-RAILS_ROOT=$APP_DIR exec $APP_DIR/script/ferret_server -e production run
+. ../../bootstrap
+RAILS_ROOT=$APP_DIR exec ferret_server -e production run
View
3  haproxy-run
@@ -1,5 +1,7 @@
#!/bin/sh -e
+. ../../bootstrap
+
PORT=$(basename $(pwd)|awk -F- '{print $2}')
USER=$(id -un)
@@ -36,5 +38,4 @@ listen stats 127.0.0.1:$(($PORT - 2))
mode http
stats uri /
END
-PATH=/usr/local/bin:/opt/local/bin:/usr/bin:/usr/sbin:/bin
exec haproxy -db -f haproxy.conf
View
9 maintenance-run
@@ -1,17 +1,12 @@
#!/bin/sh -e
+. ../../bootstrap
PORT=$(basename $(pwd)|awk -F- '{print $2}')
BASE=$(dirname $(readlink $0))
-APP_DIR=$BASE/app
if [ -z "$PORT" ]; then
echo "usage: $0 port" 1>&2;
exit 2
fi
-if [ ! -d "$APP_DIR" ]; then
- echo "no such app dir: $APP_DIR (did you create a symlink to your Rails app?)" 1>&2;
- exit 2
-fi
-
-exec $APP_DIR/script/maintenance_server $PORT
+exec maintenance_server $PORT
View
10 memcached-run
@@ -1,17 +1,11 @@
#!/bin/sh -e
+. ../../bootstrap
PORT=$(basename $(pwd)|awk -F- '{print $2}')
-BASE=$(dirname $(readlink $0))
-
-if [ -e $BASE/memcached ]; then
- MEMCACHED=$BASE/memcached
-else
- MEMCACHED=memcached
-fi
if [ -z "$PORT" ]; then
echo "usage: $0 port" 1>&2;
exit 2
fi
-exec $MEMCACHED start -p $PORT
+exec memcached start -p $PORT
View
16 mongrel-run
@@ -1,23 +1,11 @@
#!/bin/sh -e
+. ../../bootstrap
PORT=$(basename $(pwd)|awk -F- '{print $2}')
-BASE=$(dirname $(readlink $0))
-APP_DIR=$BASE/app
-
-if [ -e $BASE/mongrel_rails ]; then
- MONGREL_RAILS=$BASE/mongrel_rails
-else
- MONGREL_RAILS=mongrel_rails
-fi
if [ -z "$PORT" ]; then
echo "usage: $0 port" 1>&2;
exit 2
fi
-if [ ! -d "$APP_DIR" ]; then
- echo "no such app dir: $APP_DIR (did you create a symlink to your Rails app?)" 1>&2;
- exit 2
-fi
-
-exec $MONGREL_RAILS start -e production -p $PORT -c $APP_DIR
+exec mongrel_rails start -e production -p $PORT -c $APP_DIR
View
16 nginx-run
@@ -1,16 +1,8 @@
#!/bin/sh -e
+. ../../bootstrap
PORT=$(basename $(pwd)|awk -F- '{print $2}')
BACKEND_PORT=$(basename $(pwd)|awk -F- '{print $3}')
-USER=$(id -un)
-BASE=$(dirname $(readlink $0))
-APP_DIR=$($BASE/readlink_canonical $BASE/app)
-
-if [ -e $BASE/nginx ]; then
- NGINX=$BASE/nginx
-else
- NGINX=nginx
-fi
TEMP_BASE_DIR=/var/tmp/${USER}-nginx-${PORT}
if [ ! -d $TEMP_BASE_DIR ]; then
@@ -34,6 +26,10 @@ events {
http {
+ # See http://wiki.nginx.org/NginxHttpLimitReqModule
+ # and http://sysarcana.com/2010/05/26/rate-limiting-with-nginx/
+ limit_req_zone \$proxy_add_x_forwarded_for zone=one:10m rate=100r/m;
+
access_log ${APP_DIR}/log/access.log;
fastcgi_temp_path ${TEMP_BASE_DIR}/fastcgi;
@@ -106,4 +102,4 @@ http {
}
EOF
-exec $NGINX -p $PWD/ -c nginx.conf || echo "do you need to create the symlink '$BASE/nginx?'"
+exec nginx -p $PWD/ -c nginx.conf || echo "do you need to create the symlink '$BASE/bin/nginx?'"
View
16 thin-run
@@ -1,23 +1,11 @@
#!/bin/sh -e
+. ../../bootstrap
PORT=$(basename $(pwd)|awk -F- '{print $2}')
-BASE=$(dirname $(readlink $0))
-APP_DIR=$($BASE/readlink_canonical $BASE/app)
-
-if [ -e $BASE/thin ]; then
- THIN=$BASE/thin
-else
- THIN=thin
-fi
if [ -z "$PORT" ]; then
echo "usage: $0 port" 1>&2;
exit 2
fi
-if [ ! -d "$APP_DIR" ]; then
- echo "no such app dir: $APP_DIR (did you create a symlink to your Rails app?)" 1>&2;
- exit 2
-fi
-
-exec $THIN start -e production -p $PORT -c $APP_DIR
+exec thin start -e production -p $PORT -c $APP_DIR
View
8 thinking-sphinx-run
@@ -1,12 +1,6 @@
#!/bin/sh -e
+. ../../bootstrap
PORT=$(basename $(pwd)|awk -F- '{print $2}')
-BASE=$(dirname $(readlink $0))
-APP_DIR=$BASE/app
-
-if [ ! -d "$APP_DIR" ]; then
- echo "no such app dir: $APP_DIR (did you create a symlink to your Rails app?)" 1>&2;
- exit 2
-fi
cd $APP_DIR && RAILS_ENV=production rake ts:in && sleep 300
View
14 unicorn-run
@@ -6,17 +6,11 @@
# itself for upgrades etc.
#
+. ../../bootstrap
+
PORT=$(basename $(pwd)|awk -F- '{print $2}')
-BASE=$(dirname $(../../readlink_canonical $0))
-APP_DIR=$BASE/app
THIS_DIR=$(pwd)
-if [ -e $BASE/unicorn_rails ]; then
- UNICORN_RAILS=$BASE/unicorn_rails
-else
- UNICORN_RAILS=unicorn_rails
-fi
-
if [ -z "$PORT" ]; then
echo "usage: $0 port" 1>&2;
exit 2
@@ -125,7 +119,7 @@ fi
if [ ! $RUNNING ]; then
echo "Starting unicorn"
- $UNICORN_RAILS -E production -c $THIS_DIR/unicorn.rb -D
+ unicorn_rails -E production -c $THIS_DIR/unicorn.rb -D
sleep 2
CUR_PID=$(cat $CUR_PID_FILE)
fi
@@ -156,4 +150,4 @@ while [ -n "$(is_pid_running $CUR_PID)" ]; do
/bin/echo -n '.'
sleep 2
done
-echo "Unicorn has exited."
+echo "Unicorn has exited."
View
13 varnish-run
@@ -1,16 +1,9 @@
#!/bin/sh -e
+. ../../bootstrap
+
PORT=$(basename $(pwd)|awk -F- '{print $2}')
BACKEND_PORT=$(basename $(pwd)|awk -F- '{print $3}')
-USER=$(id -un)
-BASE=$(dirname $(readlink $0))
-APP_DIR=$($BASE/readlink_canonical $BASE/app)
-
-if [ -e $BASE/varnishd ]; then
- VARNISHD=$BASE/varnishd
-else
- VARNISHD=varnishd
-fi
TEMP_BASE_DIR=/var/tmp/${USER}-varnish-${PORT}
VARNISH_NAME=$TEMP_BASE_DIR
@@ -76,4 +69,4 @@ sub vcl_deliver {
}
EOF
-exec $VARNISHD -a 127.0.0.1:$PORT -F -f varnish.conf -s file,$TEMP_BASE_DIR/data,200MB -n $VARNISH_NAME || echo "do you need to create the symlink '$BASE/varnishd?'"
+exec varnishd -a 127.0.0.1:$PORT -F -f varnish.conf -s file,$TEMP_BASE_DIR/data,200MB -n $VARNISH_NAME || echo "do you need to create the symlink '$BASE/varnishd?'"
Please sign in to comment.
Something went wrong with that request. Please try again.