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名工人)?
同樣的問題在這裏...我想它是與'htop' – mdesantis