我想在同一台服务器上运行两个相同的项目。因此,我为此目的定义了两个环境alpha
和beta
。
alpha
应该在端口3000上运行beta
应在端口4000上运行然后我尝试启动服务器两次:
$ ruby bin/rails server -b 0.0.0.0 -p 3000 -e alpha --pid tmp/pids/server-alpha.pid
$ ruby bin/rails server -b 0.0.0.0 -p 4000 -e beta --pid tmp/pids/server-beta.pid
不幸的是,其中一个服务器(第二个启动)在识别时停止,还有另一个实例。
环境alpha
开始:
=> Booting Puma
=> Rails 5.0.0.1 application starting in alpha on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: alpha
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
环境beta
开始:
=> Booting Puma
=> Rails 5.0.0.1 application starting in beta on http://0.0.0.0:4000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: beta
* Listening on tcp://0.0.0.0:4000
Use Ctrl-C to stop
环境alpha
重启(不知道原因!):
* Restarting...
=> Booting Puma
=> Rails 5.0.0.1 application starting in alpha on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
A server is already running. Check tmp/pids/server-alpha.pid.
Exiting
显然pid
文件仍然存在。但是,当我启动另一台服务器时,如何避免重启服务器?如何告诉rails在重启时删除pidfile?或者我怎么能处理这个问题?
答案 0 :(得分:2)
您的config / puma.rb中可能有plugin :tmp_restart
。每次触摸tmp / restart.txt(每次服务器启动时),其他服务器都会重新启动。
只需对该行进行注释即可行(您无法通过触摸tmp / restart.txt重新启动rails服务器。)
答案 1 :(得分:0)
我不确定这会有效,但请尝试在=
之后使用--pid
$ ruby bin/rails server -b 0.0.0.0 -p 3000 -e alpha --pid=tmp/pids/server-alpha.pid
$ ruby bin/rails server -b 0.0.0.0 -p 4000 -e beta --pid=tmp/pids/server-beta.pid