Sha256: 4103bb9f8fecb9aa424e80484a54fde8046bb2b446fe3322fa23656aa7b745fa

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

namespace :unicorn do
  desc 'start server'
  task :start, [:env, :config] do |task, args|
    args = { :env => 'development', :config => 'unicorn.rb' }.merge args.to_hash
    cmd = 'unicorn_rails'
    cmd << ' -c ' << args[:config] if File.exists?(File.join(Rails.root, args[:config]))
    cmd << ' -E ' << args[:env]
    sys cmd << ' -D'
  end
  
  desc 'stop server'
  task :stop do
    sys 'kill -QUIT `cat tmp/unicorn.pid`' if File.exists? File.join(Rails.root, 'tmp', 'unicorn.pid')
    sleep 1
    sys 'rm -r tmp/*'
  end
  
  desc 'restart server'
  task :restart, [:env, :config] => [:stop, :start]
  
  desc 'copy unicorn.rb to root path'
  task :copy, [:processes] do |task, args|
    path = File.join(Rails.root, 'unicorn.rb')
    if File.exists? path
      err 'unicorn.rb is exists! Please remove it and run again.'
    else
      args = { :processes => 1 }.merge args.to_hash
      p file = "# Added by zfben_rails_rake\nworker_processes #{args[:processes]}\nlisten File.realpath(File.dirname(__FILE__)) << '/tmp/unicorn.sock', :tcp_nopush => true, :tcp_nodelay => true\npid 'tmp/unicorn.pid'\npreload_app true\n# End zfben_rails_rake"
      File.open(path, 'w'){ |f| f.write file }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zfben_rails_rake-0.0.12 lib/zfben_rails_rake/tasks/unicorn.rb