diff --git a/config/deploy.rb b/config/deploy.rb index 7f96981..1d0bb77 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -13,7 +13,7 @@ namespace :deploy do desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do - execute :sudo, :service, :unicorn_campo, :restart + execute '/etc/init.d/unicorn_campo', :restart end end diff --git a/script/setup.sh b/script/setup.sh index ad2e63f..15f4a7c 100644 --- a/script/setup.sh +++ b/script/setup.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -USER=vagrant +USER=deploy DEPLOY_PATH=/var/www/campo apt-get update @@ -30,6 +30,6 @@ chown $USER:$USER $DEPLOY_PATH wget -O /etc/init.d/unicorn_campo https://raw.github.com/chloerei/campo/master/script/unicorn.sh chmod +x /etc/init.d/unicorn_campo -wget -O /etc/nginx/sites-available/campo.conf https://raw.github.com/chloerei/campo/master/script/unicorn.sh +wget -O /etc/nginx/sites-available/campo.conf https://raw.github.com/chloerei/campo/master/config/nginx.conf ln -s /etc/nginx/sites-available/campo.conf /etc/nginx/sites-enabled/ service nginx restart diff --git a/script/unicorn.sh b/script/unicorn.sh old mode 100755 new mode 100644 index c86dca8..4c8d728 --- a/script/unicorn.sh +++ b/script/unicorn.sh @@ -5,7 +5,7 @@ set -e TIMEOUT=${TIMEOUT-60} APP_ROOT=/var/www/campo/current PID=$APP_ROOT/tmp/pids/unicorn.pid -USER=vagrant +USER=deploy CMD="cd $APP_ROOT ; RAILS_ENV=production bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb" action="$1" set -u @@ -20,10 +20,18 @@ oldsig () { test -s $old_pid && kill -$1 `cat $old_pid` } +run () { + if [ "$(id -un)" = "$AS_USER" ]; then + eval $1 + else + su -c "$1" - $USER + fi +} + case $action in start) sig 0 && echo >&2 "Already running" && exit 0 - su - $USER -c "$CMD" + run "$CMD" ;; stop) sig QUIT && exit 0 @@ -36,7 +44,7 @@ case $action in restart|reload) sig HUP && echo reloaded OK && exit 0 echo >&2 "Couldn't reload, starting '$CMD' instead" - su - $USER -c "$CMD" + run "$CMD" ;; upgrade) if sig USR2 && sleep 2 && sig 0 && oldsig QUIT @@ -56,7 +64,7 @@ case $action in exit 0 fi echo >&2 "Couldn't upgrade, starting '$CMD' instead" - su - $USER -c "$CMD" + run "$CMD" ;; reopen-logs) sig USR1