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")
end
end
I tried with service and exec script
[Unit]
Description=Delayed Job Workers
After=network.target
[Service]
Type=simple
Environment="RAILS_ENV=production"
WorkingDirectory=/var/www/extranet-rails/durbano-rails
ExecStart=/var/www/extranet-rails/durbano-rails/script.sh
Restart=on-failure
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=delayed_job
[Install]
WantedBy=multi-user.target
script.sh (with Foreman):
#!/bin/bash
cd /var/www/extranet-rails/durbano-rails
export RAILS_ENV=production
echo "Starting foreman..." >> myapp.log 2>&1
/opt/rbenv/shims/foreman start >> myapp.log 2>&1
echo "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.