2016-09-29 48 views
1

我想在同一臺服務器上運行兩次同一個項目。所以我爲此定義了兩個環境alphabeta如何並行運行多個rails環境?

  • 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

我不知道這會工作,但試圖利用=--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

+0

不幸的是,'='變化不大。 pidfile路徑工作得很好。看起來,自動重新啓動不會在停止時清除pidfile,並且在啓動時它會識別現有的pidfile並拒絕... – wurfmaul

2

你可能在你的config/puma.rb有plugin :tmp_restart。每次觸摸tmp/restart.txt(每次服務器啓動時),其他服務器都會重新啓動。

只需評論該行,它的工作原理(您將無法通過觸摸tmp/restart.txt重新啓動您的導航服務器)。