lib/tasks/server.rake in picky-0.0.4 vs lib/tasks/server.rake in picky-0.0.5

- old
+ new

@@ -1,48 +1,37 @@ # TODO This file needs some love. # namespace :server do + def chdir_to_root Dir.chdir SEARCH_ROOT end + def current_pid pid = `cat #{File.join(SEARCH_ROOT, 'tmp/pids/unicorn.pid')}` pid.blank? ? nil : pid.chomp end + desc "Start the unicorns. Weheee!" - task :start => :application do + task :start => :framework do chdir_to_root # Rake::Task[:"solr:start"].invoke # TODO Move to better place. - config = {} - config['production'] = { - :port => 6000, - :daemonize => true - } - config['development'] = { - :port => 4000, - :daemonize => false - } - # TODO Move port configuration! - port = SEARCH_ENVIRONMENT == 'production' ? 6000 : 4000 - `export SEARCH_ENV=#{SEARCH_ENVIRONMENT}; unicorn -p #{config[SEARCH_ENVIRONMENT][:port]} -c #{File.join(SEARCH_ROOT, 'app/unicorn.ru')} #{config[SEARCH_ENVIRONMENT][:daemonize] ? '-D' : ''} #{File.join(SEARCH_ROOT, 'app/application.ru')}` + daemonize = SEARCH_ENVIRONMENT == 'production' ? '-D' : '' + command = "export SEARCH_ENV=#{SEARCH_ENVIRONMENT}; unicorn -c unicorn.ru #{daemonize}".strip + puts "Running \`#{command}\`." + exec command end + + desc "Stop the unicorns. Blam!" + task :stop => :framework do + `kill -QUIT #{current_pid}` if current_pid + # Rake::Task[:"solr:stop"].invoke # TODO Move to better place. + end + desc "Restart the unicorns!" task :restart do Rake::Task[:"server:stop"].invoke - sleep 15 + sleep 5 Rake::Task[:"server:start"].invoke end - desc "Stop the unicorns. Blam!" - task :stop => :application do - chdir_to_root - `kill -QUIT #{current_pid}` if current_pid - # Rake::Task[:"solr:stop"].invoke # TODO Move to better place. - end - - # TODO - # - desc 'send the USR1 signal to the thin server' - task :usr1 => :ruby_version do - puts "Sending USR1 signal to the thin server." - `pidof thin#{RUBY_VERSION_APPENDIX}`.split.each { |pid| Process.kill('USR1', pid.to_i) } - end + end