首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从capistrano开始sidekiq

从capistrano开始sidekiq
EN

Stack Overflow用户
提问于 2014-06-03 17:41:31
回答 3查看 12.1K关注 0票数 8

我想从capistrano的sidekiq开始。下面是这方面的代码

代码语言:javascript
复制
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

它可以成功执行,但服务器上仍然没有启动sidekiq。

输出:

代码语言:javascript
复制
$ 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"
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-06-03 18:05:51

你的问题出在这里:

代码语言:javascript
复制
  cd /home/project/current && bundle exec sidekiq -c 10 -e production -L log/sidekiq.log &

在末尾添加&时,命令正在单独的进程中执行,但此进程仍然是当前进程的子进程,并在当前进程停止时终止。相反,您需要将sidekiq作为守护进程来运行。

代码语言:javascript
复制
bundle exec sidekiq -c 10 -e production -L log/sidekiq.log -d

请注意extra -d选项

票数 9
EN

Stack Overflow用户

发布于 2016-12-07 16:59:06

在不使用任何gem的情况下,以下是我的解决方案,可以完美地使用Capistrano 3.4.0

代码语言:javascript
复制
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
票数 8
EN

Stack Overflow用户

发布于 2018-09-28 01:53:15

以防以某种方式尝试使用capistrano start/restart/stop环境

代码语言:javascript
复制
bundle exec cap production sidekiq:start
bundle exec cap production sidekiq:stop
bundle exec cap production sidekiq:restart
#staging
bundle exec cap staging sidekiq:start
bundle exec cap staging sidekiq:stop
bundle exec cap staging sidekiq:restart
#same with other dependencies
bundle exec cap production puma:restart
bundle exec cap staging puma:stop

简要说明

(如果您在线访问存储库,如github,请记住运行ssh代理以通过存储库中的ssh进行连接,并获取最新版本的代码/分支)

  • 在本地设置您自己的github ssh密钥
  • 使用带有ssh -T git@github.com

的密钥eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa

  • check代理运行ssh代理

在那之后,我总是使用它来部署

  • 运行capistrano目标环境bundle exec cap staging deploy

当您已经在prod中并且遇到问题时,这些工具非常方便,但特别是为了升级,您可以根据您的Capfile执行单独的exec (例如,大多数时候我使用puma作为rack middleware服务器,sidekiq作为scheculed-jobs服务器)

Capfile

代码语言:javascript
复制
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#   https://github.com/capistrano/passenger
#
require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
require "capistrano/yarn"
require "capistrano/puma"
install_plugin Capistrano::Puma  # Default puma tasks
require 'capistrano/sidekiq'
require 'slackistrano/capistrano'
require_relative 'lib/capistrano/slack_deployment_message'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

最后,为了在capistrano启用/安装/配置的这些特性上执行start|stop|restart

我总是可以在生产中使用capistrano重启puma:

  • bundle exec cap production sidekiq:restart
  • bundle exec cap production puma:restart

以及在试运行中:

  • bundle exec cap staging sidekiq:restart
  • bundle exec cap staging puma:restart

希望这能有所帮助!:D

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24011860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档