Last active
December 15, 2015 12:39
-
-
Save hamstar/5262182 to your computer and use it in GitHub Desktop.
Init script for a ruby app
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 | |
path="/home/user/app" | |
port="3030" | |
user="user" | |
branch="stable" | |
gemset="1.9.3@app" | |
usage() { | |
echo "Usage: $0 {start|stop|restart|migrate|update}" | |
} | |
start() { | |
su - $user -c " | |
cd $path; | |
source /home/$user/.rvm/scripts/rvm; | |
rvm use $gemset; | |
git checkout $branch; | |
export RAILS_ENV=production | |
passenger start -a 127.0.0.1 -p $port -d; | |
" | |
} | |
stop() { | |
su - $user -c " | |
cd $path; | |
source /home/$user/.rvm/scripts/rvm; | |
rvm use $gemset; | |
git checkout $branch; | |
export RAILS_ENV=production | |
passenger stop -p $port; | |
" | |
} | |
restart() { | |
stop | |
start | |
} | |
migrate() { | |
su - $user -c " | |
cd $path; | |
source /home/$user/.rvm/scripts/rvm; | |
rvm use $gemset; | |
git checkout $branch; | |
export RAILS_ENV=production | |
rake db:migrate | |
" | |
} | |
update() { | |
stop | |
su - $user -c " | |
cd $path; | |
git checkout $branch; | |
git pull origin $branch; | |
source /home/$user/.rvm/scripts/rvm; | |
rvm use $gemset; | |
export RAILS_ENV=production | |
bundle install | |
" | |
migrate | |
start | |
} | |
case $1 in | |
"start") start ;; | |
"stop") stop ;; | |
"restart") restart;; | |
"migrate") migrate ;; | |
"update") update ;; | |
*) usage ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment