2013-05-21 40 views
2

好吧,我即将尝试与独角兽建立一个生产系统。为什么独角兽在生产模式下创建多个主进程?

当我尝试启动麒麟服务器时,通过我写的脚本启动了2个主实例。

这只发生在我给出的“-E生产”开始时。

初始化素文字,我开始与麒麟:

#!/bin/sh 
set -e 

TIMEOUT=${TIMEOUT-60} 
APP_ROOT=/application/path/current 
PID=$APP_ROOT/tmp/pids/unicorn.pid 
CMD="/usr/local/rvm/scripts/rvm && cd $APP_ROOT && bundle exec unicorn -D -E production -c $APP_ROOT/config/production/unicorn.rb" 
action="$1" 
set -u 

old_pid="$PID.oldbin" 

cd $APP_ROOT || exit 1 

sig() { 
     test -s "$PID" && kill -$1 `cat $PID` 
} 

oldsig() { 
     test -s $old_pid && kill -$1 `cat $old_pid` 
} 

case $action in 
start) 
     sig 0 && echo >&2 "Already running" && exit 0 
     su -s /bin/bash -c "$CMD" - www-data 
     ;; 
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 
     echo >&2 "Couldn't reload, starting '$CMD' instead" 
     su -s /bin/bash -c "$CMD" - www-data 
     ;; 
upgrade) 
     if sig USR2 && sleep 2 && sig 0 && oldsig QUIT 
     then 
       n=$TIMEOUT 
       while test -s $old_pid && test $n -ge 0 
       do 
         printf '.' && sleep 1 && n=$(($n - 1)) 
       done 
       echo 

       if test $n -lt 0 && test -s $old_pid 
       then 
         echo >&2 "$old_pid still exists after $TIMEOUT seconds" 
         exit 1 
       fi 
       exit 0 
     fi 
     echo >&2 "Couldn't upgrade, starting '$CMD' instead" 
     su -s /bin/bash -c "$CMD" - www-data 
     ;; 
reopen-logs) 
     sig USR1 
     ;; 
*) 
     echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" 
     exit 1 
     ;; 
esac 

Uncorn配置:

working_directory "/application/path/current" 
pid "/application/path/current/tmp/pids/unicorn.pid" 
stderr_path "/application/path/current/log/unicorn.log" 
stdout_path "/application/path/current/log/unicorn.log" 

listen "/application/path/current/tmp/unicorn.application_name.sock" 
worker_processes 1 
timeout 30 

before_fork do |server, worker| 
    defined?(ActiveRecord::Base) and 
    ActiveRecord::Base.connection.disconnect! 

    old_pid = "#{server.config[:pid]}.oldbin" 
    if File.exists?(old_pid) && server.pid != old_pid 
    begin 
     Process.kill("QUIT", File.read(old_pid).to_i) 
    rescue Errno::ENOENT, Errno::ESRCH 
    end 
    end 
end 

会真的感谢任何帮助!

编辑: 嗡嗡声......如果我写命令“ps aux | grep unicorn”,它只显示2个进程(1个主进程和1个进程),但为什么dos htop状态表明我有5个进程活跃(2名大师和3名工人)?

+0

同样的问题在这里...我想它是与'htop' – mdesantis

回答

2

htop分别列出了一个进程的每个线程,而ps没有。请阅读this answer了解更多详情。

相关问题