Skip to content

Instantly share code, notes, and snippets.

@gonfva
Created November 17, 2013 22:35
Show Gist options
  • Select an option

  • Save gonfva/7519177 to your computer and use it in GitHub Desktop.

Select an option

Save gonfva/7519177 to your computer and use it in GitHub Desktop.
Script to update a running server (rvm+puma+nginx)
#!/bin/bash
pwd=*****
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit 1
fi
rvm use default
cd /home/gonfva/whendoigo2
#Import new code
git pull origin
#Install new libraries
RAILS_ENV=production bundle install
#Precompile assets
RAILS_ENV=production bundle exec rake assets:precompile
#Migrate database
RAILS_ENV=production bundle exec rake db:migrate
#Kill current processess
pid=`ps -L n | grep "puma" |awk '{ print $1 }'`
if [[ $pid != "" ]];
then
kill -s SIGTERM $pid
fi
echo $pwd| sudo -S service nginx stop
#Remove communication file
rm -f /tmp/whendoigo.sock
#start Puma
bundle exec puma -e production -b unix:///tmp/whendoigo.sock &
sleep 10
#start nginx
echo $pwd| sudo -S service nginx start
@gonfva
Copy link
Author

gonfva commented Nov 17, 2013

Next time capistrano at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment