好的,所以我试图用独角兽设置制作服务。
当我尝试通过我编写的脚本启动unicorn服务器时,它启动了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
Uncorn config:
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个工人) )?