好吧,我正在尝试与独角兽一起制作产品。

当我尝试通过脚本启动独角兽服务器时,它将启动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个工作者) )?

最佳答案

htop分别列出进程的每个线程,而ps不列出。有关更多详细信息,请阅读this answer

10-04 18:33