Skip to content

Instantly share code, notes, and snippets.

@Ruxton
Last active Dec 18, 2015
Embed
What would you like to do?
#! /bin/bash
START_DIR=$PWD
DIASPORA_DIR="/var/vhosts/diaspora.digitalignition.net/diaspora"
DEFAULT_BRANCH="develop"
UNICORN_EXEC="service unicorn"
UNICORN_CONF="/etc/unicorn/diaspora.conf"
RAILS_ENV="production"
function diaspora_unicorn_service() {
if [ $# -lt 1 ]; then
echo "Must provide start/stop to diaspora_unicorn_service"
return 1
fi
if [[ "$1" == "start" ]] || [[ "$1" == "stop" ]]; then
$UNICORN_EXEC $1 $UNICORN_CONF
else
echo "Must provide start/stop to diaspora_unicorn_service"
return 1
fi
}
function diaspora_sidekiq_service() {
case "$1" in
start) sudo service sidekiq start app_dir=$DIASPORA_DIR index=0 job_name=diaspora;;
stop) sudo service sidekiq stop app=$DIASPORA_DIR index=0 job_name=diaspora;;
*) echo "Must provide start/stop to diaspora_sidekiq_service"; return 1;;
esac
}
function handle_error_return() {
if [[ $# -lt 1 ]]; then
string="Error running update for Diaspora"
else
string=$1
fi
retval=$?
if [[ $retval -ne 0 ]]; then
echo $string
exit $retval
fi
}
cd $DIASPORA_DIR
diaspora_sidekiq_service "stop"
handle_error_return "Error stopping the Diaspora sidekiq service"
diaspora_unicorn_service "stop"
handle_error_return "Error stopping the Diaspora unicorn service"
git pull origin $DEFAULT_BRANCH
handle_error_return "Error pulling new code from git repository"
bundle install --without development test heroku
handle_error_return "Error running bundler"
RAILS_ENV=$RAILS_ENV bundle exec rake db:migrate assets:precompile
handle_error_return "Error trying to migrate database and precompile assets"
diaspora_unicorn_service "start"
handle_error_return "Error starting the Diaspora unicorn service"
diaspora_sidekiq_service "start"
handle_error_return "Error starting the Diaspora sidekiq service"
cd $START_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment