Running sidekiq with capistrano

I want to start sidekiq with capistrano. Below is the code for this

namespace :sidekiq do
  task :start do
    run "cd #{current_path} && bundle exec sidekiq -c 10 -e production -L log/sidekiq.log &"
    p capture("ps aux | grep sidekiq | awk '{print $2}' | sed -n 1p").strip!    
  end
end

It succeeds, but sidekiq does not start on the server.

output:

$ cap sidekiq:start
    triggering load callbacks
  * 2014-06-03 15:03:01 executing `sidekiq:start'
  * executing "cd /home/project/current && bundle exec sidekiq -c 10 -e production -L log/sidekiq.log &"
    servers: ["x.x.x.x"]
    [x.x.x.x] executing command
    command finished in 1229ms
  * executing "ps aux | grep sidekiq | awk '{print $2}' | sed -n 1p"
    servers: ["x.x.x.x"]
    [x.x.x.x] executing command
    command finished in 1229ms
"19291"
+4
source share
2 answers

Your problem is here:

  cd /home/project/current && bundle exec sidekiq -c 10 -e production -L log/sidekiq.log &

When you add &at the end, the command is executed in a separate process, but this process is still a child of the current process and ends when the current process stops. Instead, you need to run sidekiq as deamon.

bundle exec sidekiq -c 10 -e production -L log/sidekiq.log -d

Pay attention to an additional option. -d

+5
source

- , Capistrano 3.4.0

namespace :sidekiq do

  task :restart do
    invoke 'sidekiq:stop'
    invoke 'sidekiq:start'
  end

  before 'deploy:finished', 'sidekiq:restart'

  task :stop do
    on roles(:app) do
      within current_path do
        pid = p capture "ps aux | grep sidekiq | awk '{print $2}' | sed -n 1p"
        execute("kill -9 #{pid}")
      end
    end
  end

  task :start do
    on roles(:app) do
      within current_path do
        execute :bundle, "exec sidekiq -e #{fetch(:stage)} -C config/sidekiq.yml -d"
      end
    end
  end
end
+2

Source: https://habr.com/ru/post/1543046/


All Articles