Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting rails 5 as a daemon #22811

Closed
Paxa opened this issue Dec 28, 2015 · 3 comments
Closed

Starting rails 5 as a daemon #22811

Paxa opened this issue Dec 28, 2015 · 3 comments

Comments

@Paxa
Copy link
Contributor

Paxa commented Dec 28, 2015

I create new rails app and try to run it with -d option

rails _5.0.0.beta1_ new example_app -G -d sqlite3
cd example_app
./bin/rails server -d

Output:

=> Booting Puma
=> Rails 5.0.0.beta1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
I, [2015-12-28T16:56:38.914107 #54996]  INFO -- : Celluloid 0.17.2 is running in BACKPORTED mode. [ http://git.io/vJf3J ]

From log file:

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in tsort_each at /Users/pavel/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:226)
DEPRECATION WARNING: before_filter is deprecated and will be removed in Rails 5.1. Use before_action instead. (called from <top (required)> at /Sites/example_app/app/controllers/application_controller.rb:1)
DEPRECATION WARNING: after_filter is deprecated and will be removed in Rails 5.1. Use after_action instead. (called from <top (required)> at /Sites/example_app/app/controllers/application_controller.rb:1)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in tsort_each at /Users/pavel/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:226)
DEPRECATION WARNING: before_filter is deprecated and will be removed in Rails 5.1. Use before_action instead. (called from <top (required)> at /Sites/example_app/app/controllers/application_controller.rb:1)
DEPRECATION WARNING: after_filter is deprecated and will be removed in Rails 5.1. Use after_action instead. (called from <top (required)> at /Sites/example_app/app/controllers/application_controller.rb:1)
Couldn't cleanly terminate all actors in 10 seconds!

When running without -d it works just fine

@claudiob
Copy link
Member

I confirm what written above. And that switching back to Rails 4.2.5 makes the daemon server work.

@tawan
Copy link
Contributor

tawan commented Jan 11, 2016

Hi, I can confirm this bug as well. I took the time and got to the root of the problem. I already created a PR (see above).
A current workaround would be to pass the absolute path to the server.pid file as an argument:

./bin/rails server -d -P /my_rails_project/tmp/pids/server.pid

The bug in detail: The server startup procedure crashes, since it tries to
open a file at /tmp/pids/server.pid instead of
<path to project>/tmp/pids/server.pid. This bug was introduced in 51211a9
when Rack was upgraded from version 1.x to 2.x. Since version 2.x,
Rack does not memoize the options hash, and as a consequence
Rails::Server#default_options will be evaluated multiple times.
The hash returned by Rails::Server#default_options holds the default path
to the server.pid file. The path is generated with the method
File.expand_path. However, the return value of this method depends on the
current working directory, which changes once Process.daemon is invoked
by Rack::Server#daemonize_app and the process is detached from the current
shell.

tawan added a commit to tawan/rails that referenced this issue Jan 16, 2016
Fix bug (rails#22811) that occurs when rails server is started in daemon mode
and optional path to the `server.pid` file is omitted. Store default path
in a constant instead of evaluating it multiple time using `File.expand_path`.

The bug in detail: The server startup procedure crashes, since it tries to
open a file at `/tmp/pids/server.pid` instead of
`<path to project>/tmp/pids/server.pid`. This bug was introduced in 51211a9
when Rack was upgraded from version 1.x to 2.x. Since version 2.x,
Rack does not memoize the options hash [1], and as a consequence
`Rails::Server#default_options` will be evaluated multiple times.
The hash returned by `Rails::Server#default_options` holds the default path
to the `server.pid` file. The path is generated with the method
`File.expand_path`. However, the return value of this method depends on the
current working directory [2], which changes once `Process.daemon` is invoked
by `Rack::Server#daemonize_app` and the process is detached from the current
shell.

Close rails#22811

[1]https://git.io/vzen2
[2]http://ruby-doc.org/core-2.1.5/File.html#method-c-expand_path
@Paxa
Copy link
Contributor Author

Paxa commented Jan 17, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants