1

I would like to run one and the same project twice on the same server. So I defined two environments alpha and beta for this purpose.

  • alpha should run on port 3000
  • beta should run on port 4000

Then I try to start the server twice:

$ 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

Unfortunately one of those servers (the second to start) stops when it recognizes, that there is another instance.

Environment alpha starts:

=> 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

Environment beta starts:

=> 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

Environment alpha restarts (don't know why!):

* 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

Obviously the pid file still exists. But how can I avoid a restart of the server when I start another one? How can I tell rails to delete the pidfile on restart? Or how else could I handle this problem?

2 Answers 2

4

You probable have plugin :tmp_restart in your config/puma.rb. Everytime tmp/restart.txt is touched (which is everytime a server starts), the other server restarts.

Just comment the line and it works (you won't be able to restart your rails server by touching tmp/restart.txt anymore).

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure this will work but try using = after --pid like this

$ 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

1 Comment

The = did not change much, unfortunately. The pidfile path works quite well either way. It appears the automatic restart does not erase the pidfile when stopping and for the start it recognizes an existing pidfile and rejects...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.