Sha256: b4314c4993747a99472f04c6d10b1736a7371e6117f81016700f393bfb292442

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

# Server tasks, like starting/stopping/restarting.
#
desc "Start the server."
task :start do
  Rake::Task[:'server:start'].invoke
end
desc "Stop the server."
task :stop do
  Rake::Task[:'server:stop'].invoke
end

namespace :server do

  # desc "Start the unicorns. (Wehee!)"
  #
  task :start => :framework do
    chdir_to_root
    daemonize = PICKY_ENVIRONMENT == 'production' ? '-D' : ''
    command = "export PICKY_ENV=#{PICKY_ENVIRONMENT}; unicorn -c unicorn.rb #{daemonize}".strip
    puts "Running \`#{command}\`."
    exec command
  end

  # desc "Stop the unicorns. (Blam!)"
  #
  task :stop => :framework do
    `kill -QUIT #{current_pid}` if current_pid
  end

  # desc "Restart the unicorns."
  task :restart do
    Rake::Task[:"server:stop"].invoke
    sleep 5
    Rake::Task[:"server:start"].invoke
  end

  def chdir_to_root
    Dir.chdir Picky.root
  end

  def current_pid
    pidfile = 'tmp/pids/unicorn.pid'
    pid = `cat #{File.join(Picky.root, pidfile)}`
    if pid.blank?
      puts
      puts "No server running (no #{pidfile} found)."
      puts
    else
      pid.chomp
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
picky-4.12.1 lib/tasks/server.rake
picky-4.12.0 lib/tasks/server.rake
picky-4.11.3 lib/tasks/server.rake
picky-4.11.2 lib/tasks/server.rake
picky-4.11.1 lib/tasks/server.rake
picky-4.11.0 lib/tasks/server.rake
picky-4.10.0 lib/tasks/server.rake
picky-4.9.0 lib/tasks/server.rake
picky-4.8.1 lib/tasks/server.rake
picky-4.8.0 lib/tasks/server.rake