【问题标题】:Rails deploy with capistrano: run sunspot solr使用 capistrano 部署 Rails:运行 sunspot solr
【发布时间】:2018-12-10 04:42:50
【问题描述】:

我正在尝试使用 capistrano 3 部署我的 rails 4 应用程序。我已经在 gemfile 中声明了所有要求并添加了 Capfile。我关注了this gist

我当前的deploy.rb 文件看起来像:

# config valid only for Capistrano 3.1
lock '3.2.1'

set :application, 'my_app_name'
set :repo_url, 'git@github.com:.........'

set :user, 'username'
set :use_sudo, false

# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call

set :scm, :git

# set :deploy_via, :remote_cache # off while it is first deployment
set :deploy_via, :copy

# Default value for :format is :pretty
# set :format, :pretty
set :rvm1_ruby_version, "ruby-2.1.5"

# Default value for :linked_files is []
set :linked_files, %w{config/database.yml}

# Default value for linked_dirs is []
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle}
set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

set :pty, true

# Default value for keep_releases is 5
set :keep_releases, 5


# set config unicorn.rb, unicorn_init.sh, nginx.conf file permission after deployment
set :file_permissions_roles, :all
set :file_permissions_users, ['username']
set :file_permissions_chmod_mode, "0777"


namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 1 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
      # execute "sudo service nginx restart"
      # execute "sudo service unicorn restart"
    end

  end

  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
  end

  desc 'Starts SOLR'
  task :reindex do
    run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} sunspot:solr:reindex"
  end

  before "deploy:updated", "deploy:set_permissions:chmod"

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

end

我添加了两个任务(seedreindex)。但是当我通过命令cap production deploy 进行部署时,我的数据库没有填充种子数据。 此外,我无法开始 + 重新索引我的 Solr 依赖项。

任何帮助将不胜感激!

【问题讨论】:

    标签: ruby-on-rails solr capistrano3


    【解决方案1】:

    避免这种情况:

    "#{rake} RAILS_ENV=#{rails_env} sunspot:solr:reindex"
    

    改为写:

    "RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:reindex"
    

    通过将 RAILS_ENV 声明切换到命令的开头,我的许多问题都得到了解决。

    另外,这确实是重新索引 Solr 的命令,但我看不到你从哪里开始 Solr。

    启动 Solr:

    RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:start
    

    但这可能会失败,同时告诉您它工作正常。如果你觉得是这种情况,你可以运行它:

    RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:run
    

    在当前 shell 中执行 solr。然后您将查看是否存在问题以及此类问题的性质。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 1970-01-01
      相关资源
      最近更新 更多