我想从capistrano的sidekiq开始。下面是这方面的代码
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。
输出:
$ 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"发布于 2014-06-03 18:05:51
你的问题出在这里:
cd /home/project/current && bundle exec sidekiq -c 10 -e production -L log/sidekiq.log &在末尾添加&时,命令正在单独的进程中执行,但此进程仍然是当前进程的子进程,并在当前进程停止时终止。相反,您需要将sidekiq作为守护进程来运行。
bundle exec sidekiq -c 10 -e production -L log/sidekiq.log -d请注意extra -d选项
发布于 2016-12-07 16:59:06
在不使用任何gem的情况下,以下是我的解决方案,可以完美地使用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发布于 2018-09-28 01:53:15
以防以某种方式尝试使用capistrano start/restart/stop环境
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进行连接,并获取最新版本的代码/分支)
ssh -T git@github.com的密钥eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa
在那之后,我总是使用它来部署
bundle exec cap staging deploy当您已经在prod中并且遇到问题时,这些工具非常方便,但特别是为了升级,您可以根据您的Capfile执行单独的exec (例如,大多数时候我使用puma作为rack middleware服务器,sidekiq作为scheculed-jobs服务器)
Capfile
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:restartbundle exec cap production puma:restart以及在试运行中:
bundle exec cap staging sidekiq:restartbundle exec cap staging puma:restart希望这能有所帮助!:D
https://stackoverflow.com/questions/24011860
复制相似问题