我正在尝试用Capistrano部署Sunspot Solr。我一直在根据这个要点进行设置:https://gist.github.com/doitian/1795439。
deploy.rb
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
desc "Migrate Database"
task :migrate_db do
run "cd #{current_path} && rake db:migrate RAILS_ENV=production"
run "touch #{current_path}/tmp/restart.txt"
end
desc "Create Solr Directory"
task :setup_solr_data_dir do
run "mkdir -p #{shared_path}/solr/data"
end
end
namespace :solr do
desc "start solr"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr start --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"
end
desc "stop solr"
task :stop, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr stop --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"
end
desc "reindex the whole database"
task :reindex, :roles => :app do
stop
run "rm -rf #{shared_path}/solr/data"
start
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:reindex"
end
end
after "deploy", "deploy:cleanup", "deploy:migrate_db", 'deploy:setup_solr_data_dir', 'solr:stop', 'solr:reindex', 'solr:start'
我为我的内部服务器设置了IP,该服务器在sunspot.yml中托管我的生产应用程序:
production:
solr:
hostname: [My Server IP]
port: 8983
log_level: WARNING
# read_timeout: 2
# open_timeout: 0.5
当我尝试运行上限部署时,出现以下错误:
* 2013-04-24 08:28:04 executing `solr:stop'
* executing "cd /home/username/apps/appname/current && RAILS_ENV=production bundle exec sunspot-solr stop --port=8983 --data-directory=/home/username/apps/appname/shared/solr/data --pid-dir=/home/datacomm/apps/appname/shared/pids"
servers: ["0.0.0.0"]
[0.0.0.0] executing command
** [out :: 0.0.0.0] java version "1.7.0_15"
** [out :: 0.0.0.0]
** [out :: 0.0.0.0] OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
** [out :: 0.0.0.0]
** [out :: 0.0.0.0] OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
** [out :: 0.0.0.0]
** [out :: 0.0.0.0] **No PID file at /home/username/apps/appname/shared/pids/sunspot-solr.pid**
** [out :: 0.0.0.0]
command finished in 990ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'cd /home/username/apps/appname/current && RAILS_ENV=production bundle exec sunspot-solr stop --port=8983 --data-directory=/home/username/apps/appname/shared/solr/data --pid-dir=/home/username/apps/appname/shared/pids'" on 0.0.0.0
我错过了什么?任何帮助表示赞赏。
答案 0 :(得分:3)
当run
执行solr:stop
任务中提供的命令时,看起来您还没有运行solr,因此它们不是solr存在的pid文件。你试图阻止一个不存在的过程。
如果从run
返回的代码是错误代码,则Capistrano任务将抛出异常。您可以通过强制该命令永远不会返回错误来解决此问题。
使run
命令看起来像这样
run("YOUR COMMAND HERE > /dev/null 2>&1 || true")
现在如果你在solr未运行时调用solr:stop
,true
将返回,让Capistrano继续运行。
答案 1 :(得分:1)
与Deefour的解决方案类似,更详细的方法可以将'run'命令包装在'begin / rescue'语句中:
....
desc "start solr"
task :start, :roles => :app, :except => { :no_release => true } do
begin
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr start --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"
rescue Exception => error
puts "***Unable to start Solr with error: #{error}."
puts "***Continuing anyway.***"
end
end
...