Module: Vlad::Unicorn

Defined in:
lib/vlad/unicorn_common.rb

Constant Summary collapse

VERSION =

:nodoc:

'2.3.1'

Class Method Summary collapse

Class Method Details

.maybe_sudo(cmd) ⇒ Object

Runs cmd using sudo if the :unicorn_use_sudo variable is set.



8
9
10
11
12
13
14
# File 'lib/vlad/unicorn_common.rb', line 8

def self.maybe_sudo(cmd)
  if unicorn_use_sudo
    sudo %(sh -c '#{cmd.gsub(/'/, "'\\''")}')
  else
    run cmd
  end
end

.reload(opts = '') ⇒ Object



37
38
39
40
41
# File 'lib/vlad/unicorn_common.rb', line 37

def self.reload(opts = '')
  cmd = signal('USR2')
  cmd << %( || (#{start_unicorn(opts)}))
  maybe_sudo cmd
end

.signal(sig = '0') ⇒ Object



27
28
29
# File 'lib/vlad/unicorn_common.rb', line 27

def self.signal(sig = '0')
  %(test -s "#{unicorn_pid}" && kill -#{sig} `cat "#{unicorn_pid}"`)
end

.start(opts = '') ⇒ Object



31
32
33
34
35
# File 'lib/vlad/unicorn_common.rb', line 31

def self.start(opts = '')
  cmd = signal('HUP')
  cmd << %( || (#{start_unicorn(opts)}))
  maybe_sudo cmd
end

.start_unicorn(opts = '') ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/vlad/unicorn_common.rb', line 16

def self.start_unicorn(opts = '')
  cmd = %(#{unicorn_command} -D --config-file "#{unicorn_config}")
  cmd << %( -E "#{unicorn_env}") if unicorn_env
  cmd << %( #{opts}) if opts and !opts.empty?
  if unicorn_use_bundler
    [unicorn_bundle_cmd, cmd].join(' ')
  else
    cmd
  end
end

.stopObject



43
44
45
46
47
# File 'lib/vlad/unicorn_common.rb', line 43

def self.stop
  cmd = signal('QUIT')
  cmd << %( || echo "stale pid file #{unicorn_pid}")
  maybe_sudo cmd
end