Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 'rake task' execute in ‘RAILS_ENV=production' with nohup

I have rake task which continuously need to be active. Whenever I ran it by command

RAILS_ENV=production rake jobs:abc   

it works fine but when I close terminal rake job get stopped.So I found other solution on it by using nohup to run it in background.

I execute command:

nohup RAILS_ENV=production rake jobs:work &

but it gives error:

nohup: failed to run command ‘RAILS_ENV=production’: No such file or directory

Please suggest, to way execute rake task in a production environment.

like image 784
Prakash Bhavnath Avatar asked Dec 27 '16 12:12

Prakash Bhavnath


People also ask

How to run rake task in RAILS?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK – this will be equivalent to running the rake utility with the specified parameters in the command line.


3 Answers

Set the environment variable before the nohup command.

RAILS_ENV=production nohup rake jobs:work
like image 120
sheepdog Avatar answered Nov 12 '22 02:11

sheepdog


Try this one

  nohup rake jobs:work RAILS_ENV=production

I have commented the solution above as well

like image 4
Tushar Pal Avatar answered Nov 12 '22 04:11

Tushar Pal


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

RAILS_ENV=production screen -L rake jobs:work

It starts a new terminal which isn't bound to your current session.

To come back to your normal terminal, type Ctrl+a and then d. You can now log out safely without terminating the rake task.

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

You can come back to your rake process by typing :

screen -r
like image 4
Eric Duminil Avatar answered Nov 12 '22 04:11

Eric Duminil