I cannot launch DelayedJob as soon as I start my Rails application on my VPS on Ubuntu 22.04.
I have one project with Rails 7.1.2 (Ruby 3.0.0) which start with Passenger on apache2:
PassengerRuby /opt/rbenv/versions/3.0.0/bin/ruby
Problem: I have tried several solutions to launch it and it succeeds, but once it has launched all the remaining jobs, it exits automatically, but I would like it to be constantly open.
I tried with Crontab with @reboot (with whenever
gem):
@reboot /bin/bash -l -c 'cd /var/www/extranet-rails/durbano-rails && RAILS_ENV=production /opt/rbenv/shims/bundle exec rake delayed_jobs:start --silent >> log/cron.log 2>&1'
My delayed_jobs:start
task:
namespace :delayed_jobs do desc 'Start delayed jobs' task start: :environment do system("/opt/rbenv/shims/bundle /var/www/extranet-rails/durbano-rails/bin/delayed_job start") endend
I tried with service and exec script
[Unit]Description=Delayed Job WorkersAfter=network.target[Service]Type=simpleEnvironment="RAILS_ENV=production"WorkingDirectory=/var/www/extranet-rails/durbano-railsExecStart=/var/www/extranet-rails/durbano-rails/script.shRestart=on-failureRestartSec=5StandardOutput=syslogStandardError=syslogSyslogIdentifier=delayed_job[Install]WantedBy=multi-user.target
script.sh (with Foreman):
#!/bin/bashcd /var/www/extranet-rails/durbano-railsexport RAILS_ENV=productionecho "Starting foreman..." >> myapp.log 2>&1/opt/rbenv/shims/foreman start >> myapp.log 2>&1echo "Foreman terminated with exit code $?" >> myapp.log 2>&1
Procfile (Foreman):
delayed: /opt/rbenv/shims/bundle exec bin/delayed_job start
For all situations, I don't have any errors but it always quits on its own...
Note that if I run exactly the same command in my process, DelayedJob remains fine open even if there are no jobs to process.