The rake "rake task" task runs in "RAILS_ENV = production" with nohup

I have a rake task that must always be active. Whenever I ran it with a command

 RAILS_ENV=production rake jobs:abc 

It works fine, but when I close the rake terminal, work stops. So I found another solution on it using nohup to run it in the background.

I execute the command:

 nohup RAILS_ENV=production rake jobs:work & 

but it gives an error:

nohup: failed to execute command 'RAILS_ENV = production: No such file or directory

Please suggest to complete the rake task in a production environment.

+5
source share
3 answers

Set the environment variable before the nohup command.

 RAILS_ENV=production nohup rake jobs:work 
+8
source

Try this one

  nohup rake jobs:work RAILS_ENV=production 

I also commented on the solution above

+3
source

If you need nohup functionality, you should also consider screen .

 RAILS_ENV=production screen -L rake jobs:work 

It launches a new terminal that is not associated with your current session.

To return to the regular terminal, type Ctrl+a , and then d . You can now log out safely without interrupting the rake task.

As a bonus, you automatically get a log file in screenlog.0 .

You can return to your rake method by typing:

 screen -r 
+2
source

Source: https://habr.com/ru/post/1261943/


All Articles