Created
April 23, 2012 00:24
-
-
Save skamithi/2467746 to your computer and use it in GitHub Desktop.
Sample Rails init startup script on ubuntu
This file contains hidden or 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
### /etc/default/rails ### | |
APP_USER=vagrant | |
RVM_SETTING="1.9.3-p125@rails32" | |
RAILSDIR=/home/vagrant/rails | |
# Example: STAGES=("vagrant_staging", "vagrant_production") | |
STAGES=("vagrant_staging") | |
# Example APPS=("myapp1" "myapp2") | |
APPS=("myapp") | |
This file contains hidden or 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
#!/bin/bash | |
#BEGIN INIT INFO | |
# Provides: thin | |
# Required-Start: $network $remote_fs $syslog | |
# Required-Stop: $network $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start thin web services at boot time | |
# Description: Start thin web services at boot time. | |
### END INIT INFO | |
usage() { | |
echo "Usage: $0 {start|stop}" | |
} | |
### /etc/init.d/thin ### | |
# Include rails defaults if available | |
if [ -f /etc/default/rails ]; then | |
. /etc/default/rails | |
fi | |
ACTION=${!#} | |
case "$ACTION" in | |
'start') | |
;; | |
'stop') | |
;; | |
*) | |
echo $1 | |
usage | |
exit | |
;; | |
esac | |
for app in "${APPS[@]}" | |
do | |
for stage in "${STAGES[@]}" | |
do | |
echo "$ACTION $stage server for $app..." | |
su -c "/etc/init.d/thin_server.sh -s $stage -a $app -m $RAILSDIR -r $RVM_SETTING $ACTION" - $APP_USER | |
done | |
done | |
This file contains hidden or 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
#!/bin/bash | |
# Script run as rails user. Starts/stops thin server | |
usage() | |
{ | |
cat <<EOF | |
usage: $0 options | |
Start thin web service for Rails app | |
OPTIONS: | |
-h Show this message | |
-s rails environment name | |
-a app name | |
-r rvm setting | |
-u user running the app | |
-m rails directory | |
EOF | |
} | |
ACTION=${!#} | |
case "$ACTION" in | |
'start') | |
;; | |
'stop') | |
;; | |
*) | |
echo $1 | |
usage | |
exit | |
;; | |
esac | |
while getopts "ha:u:s:r:m:" opt; do | |
case $opt in | |
h) | |
usage | |
exit 1 | |
;; | |
a) | |
APP_NAME=$OPTARG | |
;; | |
u) | |
APP_USER=$OPTARG | |
;; | |
r) | |
RVM_SETTING=$OPTARG | |
;; | |
s) | |
STAGE=$OPTARG | |
;; | |
m) | |
RAILSDIR=$OPTARG | |
;; | |
\?) | |
usage | |
exit | |
;; | |
esac | |
done | |
# Load RVM into a shell session *as a function* | |
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then | |
source "$HOME/.rvm/scripts/rvm" | |
fi | |
cd $RAILSDIR/${APP_NAME}_${STAGE}/current | |
rvm use $RVM_SETTING | |
bundle exec thin -C config/thin_cluster.yml $ACTION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment