Skip to content

Instantly share code, notes, and snippets.

@melito
Created March 6, 2011 22:14
Show Gist options
  • Save melito/857764 to your computer and use it in GitHub Desktop.
Save melito/857764 to your computer and use it in GitHub Desktop.
Don't use this verbatim. Just showcases the idea behind HOW to get everything setup
# Add a git user
adduser git
# Add your ssh key
sudo -u git mkdir ~git/.ssh/
sudo cp id_rsa.pub ~git/.ssh/authorized_keys
sudo chown -R git.git ~git/.ssh
# Make a repo
sudo -u git mkdir ~git/MyRepo.git
sudo -u git 'cd ~git/MyRepo.git && git init --bare'
# Log out and go to the local git repo on your development machine
git remote add whatever_you_wanna_call_this [email protected]:~/MyRepo.git
# Then when you want to deploy just do `git push whatever_you_wanna_call_this master`
# Git will sync any changes you've made locally with the remote end.
# The post receive scripts below can be used to deploy rails or node apps
#!/bin/sh
# Same thing as the above post-receive file, only for a node app
AS_USER=`whoami`;
echo "============================";
echo "Deploying project";
echo "Username: $AS_USER";
unset GIT_DIR;
cd /srv/myapp;
git pull -v;
npm bundle;
rm -rf ./vendor;
mv ./node_modules/ ./vendor/
echo "Attempting to restart UDP server....";
forever stop powder.js
forever start -o /var/log/powder_udp.log powder.js
echo "Attempting to restart Web server....";
forever stop server.js
forever start -o /var/log/myapp_web.log server.js
echo "============================";
echo 'Done.';
#!/bin/sh
#
# This is a simple script for deploy a rail app using unicorn
# The git user should have rvm in their path (or the bundle and unicorn tools - wherever they may be)
#
# Copy this script to ~git/MyRepo.git/hooks/post-receive and then chmod +x
#
AS_USER=`whoami`;
APP_ROOT=/srv/myapp_name;
UNICORN_PID=$APP_ROOT/tmp/pids/unicorn.pid;
unset GIT_DIR;
echo "============================";
echo "Deploying project";
echo "Username: $AS_USER";
cd $APP_ROOT;
git pull;
bundle install;
if [ -f $UNICORN_PID ]
then
kill -USR2 `cat $UNICORN_PID`
else
unicorn -c $APP_ROOT/config/unicorn.rb -E production -D
fi
echo "Killing resque (monit will restart)"
ps aux | grep resque | awk '{print $2}' | xargs kill -s 9
echo "============================";
echo 'Done.';
#!/bin/bash
#
# Put this in /etc/init.d
#
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
export RACK_ENV=production
export VVERBOSE=1
export QUEUE=*
case $1 in
start)
cd /srv/my_app;
/usr/bin/nohup rake resque:work > log/resque_worker.log &
echo $! > tmp/pids/resque_worker.pid
;;
stop)
kill `cat /srv/my_app/tmp/pids/resque_worker.pid`
rm -rf /srv/my_app/tmp/pids/resque_worker.pid
;;
*)
echo "usage: resque {start|stop}" ;;
esac
exit 0
check process resque_worker_myapp
with pidfile /srv/myapp/tmp/pids/resque_worker.pid
start program = "/etc/init.d/resque start" as uid git and gid git
stop program = "/etc/init.d/resque stop"
if totalmem is greater than 90 MB for 10 cycles then restart
group resque_workers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment