module Brindle class Stop < GemPlugin::Plugin "/commands" include GoldenBrindle::Command::Base 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 def validate if @config_file valid_exists?(@config_file, "Config file not there: #@config_file") return false unless @valid @config_file = File.expand_path(@config_file) load_config return false unless @valid end @cwd = File.expand_path(@cwd) valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" return false unless @valid Dir.chdir @cwd valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" return @valid end def run 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 end end