Subash
Subash

Reputation: 3168

rails 5 run script only after server start

I want to run a ftp listener class only when the server starts and not when console, generators, dbconsole, test, destroy, runner and rake commands run.

I've found some people doing same thing with rails 3 and 4 using checks like defined? Rails::Generators but I can't get it working in rails 5, I do not get any return with the defined check.

Upvotes: 2

Views: 1014

Answers (1)

Christoph Petschnig
Christoph Petschnig

Reputation: 4147

The config.ru file is only used by web servers and not loaded by the console script, rake tasks or even your test suite. What you put there is only executed when a server instance launches.

Web servers themselves have also ways to do this. When you use Puma for instance, there are hooks like on_worker_boot or after_worker_boot, which may come to help (http://www.rubydoc.info/github/puma/puma/Puma/Configuration/DSL).

However, I'd recommend integrating this into your deployed server environment and out of the Rails app.

Upvotes: 4

Related Questions