好的,我正在尝试使用独角兽设置生产服务。
当我尝试通过我编写的脚本启动独角兽服务器时,它会启动 2 个主实例。
这只发生在我使用给定的“-E production”启动它时。
我开始独角兽的init scipt:
#!/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
独角兽配置:
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 名工人)?