I am trying to deploy Sunspot Solr with Capistrano. I have been setting this up based on this gist: 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'
I have set the IP for my internal server which is hosting my production app in sunspot.yml:
production:
solr:
hostname: [My Server IP]
port: 8983
log_level: WARNING
# read_timeout: 2
# open_timeout: 0.5
When I try to run cap deploy, I get the following error:
* 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
What am I missing? Any help is appreciated.
When run
executes the command provided in the solr:stop
task, it looks like you're not yet running solr, so their is no pid file for solr present. You're trying to stop a process that doesn't exist.
A Capistrano task is going to throw an exception if the code returned from run
is an error code. You can fix this by forcing that command to never return an error.
Make that run
command look like this
run("YOUR COMMAND HERE > /dev/null 2>&1 || true")
Now if you call solr:stop
when solr isn't running, true
will return, letting Capistrano continue on.