Skip to content

Instantly share code, notes, and snippets.

@ehlertij
Created June 8, 2012 18:43
Show Gist options
  • Save ehlertij/2897525 to your computer and use it in GitHub Desktop.
Save ehlertij/2897525 to your computer and use it in GitHub Desktop.
emproxy init.d script
# /data/ngin/shared/bin/emproxy/emproxy.sh
#!/bin/sh
# This script starts and stops the em-proxy
# This script belongs in /data/ngin/shared/bin
###############################################################################
export PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2
###############################################################################
usage() {
echo "Usage: $0 <appname> {start, stop} [ssl]"
exit 1
}
if [ $# -lt 2 ]; then usage; fi
###############################################################################
LOGBASE=/var/log/engineyard
PIDFILE=/var/run/emproxy_$1$3.pid
OUTPUT=$LOGBASE/emproxy$3.log
###############################################################################
export RAILS_ENV="$FRAMEWORK_ENV"
export RACK_ENV="$FRAMEWORK_ENV"
export HOME="/home/$USER"
if [ -d /data/$1/current ]; then
cd /data/$1/current
# handle the second param, don't start if already existing
case "$2" in
start)
echo "Starting emproxy $3"
case "$3" in
ssl)
PID=`sudo env RUBYOPT=-rauto_gem ruby /data/ngin/shared/proxy/proxy_ssl.rb >> $OUTPUT 2>&1 & echo $!`
;;
*)
PID=`sudo env RUBYOPT=-rauto_gem ruby /data/ngin/shared/proxy/proxy.rb >> $OUTPUT 2>&1 & echo $!`
;;
esac
if [ -z $PID ]; then
printf "%s\n" "Fail"
else
echo $PID > $PIDFILE
printf "%s\n" "Ok"
fi
;;
stop)
echo "Stopping emproxy $3"
PID=`cat $PIDFILE`
if [ -f $PIDFILE ]; then
sudo kill -9 $PID
printf "%s\n" "Ok"
rm -f $PIDFILE
else
printf "%s\n" "pidfile not found"
fi
;;
*)
usage
;;
esac
else
echo "/data/$1/current doesn't exist."
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment