Class: GoldenBrindle::Actions::Stop

Inherits:
Base
  • Object
show all
Defined in:
lib/golden_brindle/actions/stop.rb

Instance Attribute Summary

Attributes inherited from Base

#done_validating, #original_args, #valid

Instance Method Summary collapse

Methods inherited from Base

#config_keys, #help, #initialize, #load_config, #options

Methods included from Validations

#can_change_user?, #failure, #valid?, #valid_dir?, #valid_exists?, #valid_file?, #valid_group?, #valid_user?

Constructor Details

This class inherits a constructor from GoldenBrindle::Base

Instance Method Details

#configureObject



6
7
8
9
10
11
12
13
14
# File 'lib/golden_brindle/actions/stop.rb', line 6

def configure
  options [
    ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."],
    ['-C', '--config PATH', "Use a mongrel based config file", :@config_file, nil],
    ['-f', '--force', "Force the shutdown (kill -9).", :@force, false],
    ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"],
    ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "tmp/pids/unicorn.pid"]
  ]
end

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/golden_brindle/actions/stop.rb', line 30

def run
  @pid_file = File.join(@cwd,@pid_file)
  if @force
    @wait.to_i.times do |waiting|
      exit(0) if not File.exist? @pid_file
      sleep 1
    end
    GoldenBrindle::send_signal("KILL", @pid_file) if File.exist? @pid_file
  else
    GoldenBrindle::send_signal("TERM", @pid_file)
  end
end

#validateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/golden_brindle/actions/stop.rb', line 16

def validate
  if @config_file
    valid_exists?(@config_file, "Config file not there: #@config_file")
    @config_file = File.expand_path(@config_file)
    load_config
    return @valid
  end

  @cwd = File.expand_path(@cwd)
  valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
  valid_exists? File.join(@cwd,@pid_file), "PID file #@pid_file does not exist.  Not running?"
  return @valid
end