ruby on rails - Capistrano/nginx/Unicorn: Website is randomly up and down -


i using capistrano deploy code digitalocean server. added deploy.rb file block restarting unicorn after every deploy, since have noticed when got browser , start refreshing website, refreshed website , blank (white) page. it's total random.

deploy.rb:

# config valid current version of capistrano lock "3.8.1"  set :application, "project" set :repo_url, "git@bitbucket.org:username/project.git" set :branch, "master" set :tmp_dir, '/home/deployer/tmp'  set :deploy_to, "/home/deployer/apps/project" set :keep_releases, 5  set(:executable_config_files, %w(   unicorn_init.sh ))  # files need symlinked other parts of # filesystem. example nginx virtualhosts, log rotation # init scripts etc. set(:symlinks, [   {     source: "nginx.conf",     link: "/etc/nginx/sites-enabled/default"   },   {     source: "unicorn_init.sh",     link: "/etc/init.d/unicorn_#{fetch(:application)}"   },   {     source: "log_rotation",    link: "/etc/logrotate.d/#{fetch(:application)}"   },   {     source: "monit",     link: "/etc/monit/conf.d/#{fetch(:application)}.conf"   } ])   namespace :deploy      desc 'restart application'   task :restart_unicorn     on roles(:app)       execute '/home/deployer/apps/project/current/config/unicorn_init.sh restart'     end   end   after :publishing, :restart_unicorn    desc "make sure local git in sync remote."   task :check_revision     on roles(:web)       unless `git rev-parse head` == `git rev-parse origin/master`         puts "warning: head not same origin/master"         puts "run `git push` sync changes."         exit       end     end   end   before "deploy", "deploy:check_revision" end 

unicorn_init.sh:

set -e  timeout=${timeout-60} app_root=/home/deployer/apps/project/current #pid=$app_root/tmp/pids/unicorn.pid pid=/home/deployer/apps/project/shared/pids/unicorn.pid #cmd="cd $app_root; bundle exec unicorn -d -c $app_root/config/unicorn.rb -e production" cmd="cd $app_root; bundle exec unicorn -d -c $app_root/config/unicorn/production.rb -e production" as_user=deployer set -u  old_pin="$pid.oldbin"  sig () {   test -s "$pid" && kill -$1 `cat $pid` }  oldsig () {   test -s $old_pin && kill -$1 `cat $old_pin` }  run () {   if [ "$(id -un)" = "$as_user" ];     eval $1   else     su -c "$1" - $as_user   fi }  case "$1" in start)   sig 0 && echo >&2 "already running" && exit 0   run "$cmd"   ;; stop)   sig quit && exit 0   echo >&2 "not running"   ;; force-stop)   sig term && exit 0   echo >&2 "not running"   ;; restart|reload)   #sig hup && echo reloaded ok && exit 0   sig usr2 && echo reloaded ok && exit 0   echo >&2 "couldn't reload, starting '$cmd' instead"   run "$cmd"   ;; upgrade)   if sig usr2 && sleep 2 && sig 0 && oldsig quit       n=$timeout     while test -s $old_pin && test $n -ge 0           printf '.' && sleep 1 && n=$(( $n - 1 ))     done     echo      if test $n -lt 0 && test -s $old_pin           echo >&2 "$old_pin still exists after $timeout seconds"       exit 1     fi     exit 0   fi   echo >&2 "couldn't upgrade, starting '$cmd' instead"   run "$cmd"   ;; reopen-logs)   sig usr1   ;; *)   echo >&2 "usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"   exit 1   ;; esac 

what have change in file - line:

sig hup && echo reloaded ok && exit 0

for one:

sig usr2 && echo reloaded ok && exit 0

i trying unicorn log file, there nothing relevant issue. production.log - same, nothing relevant. when looking nginx log file, found on here: /var/log/nginx/error.log, fiel empty (size 0).

any advice issue/what wrong or start?

edit: in /home/deployer/apps/rentalhistory/shared/pids directory, there these 2 files: unicorn.pid.oldbin , unicorn.pid - should not 1 of removed?

thanks!

what problem in case - when reloaded unicorn, new unicorn pid generated (unicorn.pid) - that's correct, old 1 (unicorn.pid.oldbin) still staying in system. , apparently causing random downs of whole website.

fix: checked unicorn config file (config/production.rb) , line wrong - path:

old_pid = "#{root}/shared/pids/unicorn.pid.oldbin"

the shared directory on same level current, not inside of it.

after change, new unicorn pid created , old 1 removed.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -