How to run rake jobs:work in background?

5.5k Views Asked by At

I am deploying Sharetribe application. Following their documentation, I need to run bundle exec rake RAILS_ENV=production jobs:work. The problem is that after execution of this command, I need to close the SSH connection, and to do this I have to exit jobs process.

How can I run bundle exec rake RAILS_ENV=production jobs:work in background?

3

There are 3 best solutions below

0
On

You can run it like any other console command by using nohup or just adding & symbol in the end of the command, but note that solution with & will be stopped if you will close the terminal tab with it.

0
On

Please include the gem "daemons" to your Gemfile. And use the below command

RAILS_ENV=production script/delayed_job start

For more information please check the delayed job gem.

0
On

Integration of a backgroud in stain executants at startup.

To do so, we will use [systemd].

  1. Create the file YourJob.service in / etc / systemd / system /. #The File will be used to define the code to execute in the background.
  2. Run the command "enable systemctl YourJob.service"
  3. Create a .sh script file in any such directory "/home/marketuser/bin/rakejob.sh"C
  4. Checked the status of execution of YourJob.service service with the command "status systemctl tmarketjob.service"
  5. reboot the server.

File structure.

# YourJob.service

    [Unit]
    Description = Tmarket background processing daemon program

    [Service]
    Type = Single
    ExecStart = / home / marketuser / bin / rakejob.sh
    Restart = always

   [Install]
   WantedBy = graphical.target

# Rakejob.sh

! / Bin / bash

export PATH = / home / marketuser / bin:     /home/marketuser/.nvm/versions/node/v6.1.0/bin: /home/marketuser/.rbenv/plugins/ruby-build/bin: / home / marketuser /. rbenv / shims: /home/marketuser/.rbenv/bin: / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / games: / usr / local / games
cd / var / www / tmarket /
exec rake jobs: work

[-] The PATH is obtenur by executing the console command 'echo $ PATH' tmarket is the directory of our RoR application