简体   繁体   中英

How to run rake jobs:work in background?

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?

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

您可以像使用任何其他控制台命令一样运行它,方法是使用nohup或在命令末尾添加&符号,但是请注意,如果您要关闭&终端选项卡,则将停止&的解决方案。

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM