Created
January 8, 2012 14:55
-
-
Save fred/1578597 to your computer and use it in GitHub Desktop.
Script to update Diaspora as a cron job. Install as a daily cron.
This file contains 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 | |
# Assuming that Diaspora is deployed to $HOME/diaspora/master | |
HOME_FOLDER="/home/diaspora" | |
cd $HOME_FOLDER/diaspora/master | |
source "${HOME_FOLDER}/.rvm/environments/ruby-1.9.3-p0@diaspora" | |
rvm use "ruby-1.9.3-p0@diaspora" | |
# RUBY GC HEAP | |
export RUBY_HEAP_MIN_SLOTS=1250000 | |
export RUBY_HEAP_SLOTS_INCREMENT=100000 | |
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 | |
export RUBY_GC_MALLOC_LIMIT=30000000 | |
export RUBY_HEAP_FREE_MIN=12500 | |
# RESQUE | |
export RAILS_ENV=production | |
export COUNT=1 | |
export QUEUE=* | |
export VERBOSE=0 | |
export PIDFILE="${HOME_FOLDER}/diaspora/master/tmp/pids/resque_worker_QUEUE.pid" | |
export BACKGROUND="yes" | |
# IMPORTANT, set to mysql if you are using MySQL, or just comment it out. | |
# we like PG more | |
export DB="postgres" | |
# LOG Rotation Settings | |
# Get data in dd-mm-yyyy format | |
BACKUP_DIR="${HOME_FOLDER}/diaspora/logs" | |
NOW="$(date +"%Y%m%d_%H%M%S")" | |
DATE_FOLDER="$(date +"%Y/%m")" | |
FINAL_FOLDER="${BACKUP_DIR}/${DATE_FOLDER}" | |
LOG_FILE="${HOME_FOLDER}/diaspora/master/log/production.log" | |
mkdir -p $FINAL_FOLDER | |
# Pids and Logs | |
UNICORN_PID="${HOME_FOLDER}/diaspora/master/tmp/pids/unicorn.pid" | |
# Need to restore those files so that git pull suceeds | |
echo "remove files" | |
rm -rf db/schema.rb | |
git co app/views/shared/_donate.html.haml | |
git co app/models/user.rb | |
git co config/locales/diaspora/en.yml | |
git co app/views/layouts/_header.html.haml | |
git co Gemfile.lock | |
git co Gemfile | |
echo "git pull" | |
git pull | |
# replace default_account to our Admin account. | |
sed -i 's/[email protected]/[email protected]/g' $HOME_FOLDER/diaspora/master/app/models/user.rb | |
# fix a small translation | |
sed -i 's/monthly donation/donation/g' config/locales/diaspora/en.yml | |
# Bundler | |
echo "bundle install" | |
bundle install --without "test development" | |
# DB migrations | |
echo "rake db:migrate" | |
bundle exec rake db:migrate | |
echo "Restore our custom donate partial files" | |
cp $HOME_FOLDER/diaspora/shared/files/_donate.html.haml app/views/shared/_donate.html.haml | |
# Rotate Production LOG if it's bigger than 4MB | |
echo "Check for log file size for rotation" | |
SIZE1="2097152" # 2MB | |
SIZE2=$(stat -c%s $LOG_FILE) | |
if [[ "$SIZE2" -gt "$SIZE1" ]]; then | |
echo 'Log File is larger than 2MB, rotating it now' | |
mv $LOG_FILE "${FINAL_FOLDER}/production.log.${NOW}" | |
lzma -2 "${FINAL_FOLDER}/production.log.${NOW}" | |
fi | |
echo "Stopping resque" | |
PID=`cat ${PIDFILE}` | |
kill -QUIT $PID | |
rm -f $PIDFILE | |
sleep 2 | |
echo "Compressing Assets" | |
bundle exec jammit | |
sleep 2 | |
if [ -f $UNICORN_PID ]; | |
then | |
echo "Stoping Unicorn" | |
kill -QUIT `cat $UNICORN_PID` | |
fi | |
echo "Starting Unicorn" | |
unicorn_rails -c $HOME_FOLDER/diaspora/master/config/unicorn.rb -E production -D | |
sleep 20 | |
echo "Starting Resque" | |
nohup bundle exec rake resque:work RAILS_ENV=production QUEUE=* VERBOSE=0 PIDFILE=tmp/pids/resque_worker_QUEUE.pid >/dev/null 2&>/dev/null & | |
sleep 20 | |
# NO MORE WebSocket. | |
# remove from diaspora on 63cdd93afcbff4d2a93fb04c36dbd1fe393f19cd | |
# echo "Starting WebSocket" | |
# nohup ruby ./script/websocket_server.rb >/dev/null & | |
# echo $! > ./tmp/pids/websocket.pid | |
echo "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment