新手问题 Unicorn 的 pid 是什么时候创建的?

xiaoronglv · 2013年03月10日 · 最后由 HalF_taN 回复于 2013年03月11日 · 2557 次阅读

刚开始学习 unicorn, 由于对 unix 不够了解,有两个疑问请大家指点迷津,谢谢啦。

  1. pid 是进程的惟一 id, 如果我的 vps 上同时运行两个应用,unicorn 就有两个 pid 了?

  2. pid 是 unicorn_init.sh 这个脚本产生的吗,然后 unicorn.rb 拿来用?

config/unicorn_init.sh

https://github.com/samqiu/samqiu.com/blob/master/config/unicorn_init.sh#L16

TIMEOUT=${TIMEOUT-60}
APP_ROOT=/data/web/com.samqiu/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=hola
set -u
......

config/unicorn.rb

https://github.com/samqiu/samqiu.com/blob/master/config/unicorn.rb#L3

root = '/data/web/com.samqiu/current'
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"

listen '/tmp/unicorn.samqiu.sock'
worker_processes 4
timeout 30

preload_app true

before_fork do |server, worker|

......

1,是的。但要注意不是一个 unicorn,而是两个 unicorn 的实例在运行。pid 数值存放在 unicorn.rb 指定的文件中 2,不是。init 只是一个帮助处理大量指令的脚本文件,unicrn.rb 是 uniorn 的配置文件。.pid 文件是 unicorn 实例启动并完成初始化之后才生成的。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号