Sha256: 6ff8041d35f0f78e4ce8117b88063e08bef1553afd65356846bda91ded7e3fca

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

#!/usr/bin/env ruby
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'optparse'
require 'bluepill'

# defaults
options = {
  :application => "all",
  :log_file => "/var/log/bluepill.log"
}

OptionParser.new do |opts|
  opts.banner = "Usage: bluepill [app] cmd [options]"
  
  opts.on("--logfile LOGFILE") do |file|
    options[:log_file] = file
  end
  
  opts.on("--base-dir DIR") do |base_dir|
    options[:base_dir] = base_dir
  end
end.parse!

ALLOWED_COMMANDS = %w(load status start stop restart log unmonitor quit)

controller = Bluepill::Controller.new(options.slice(:base_dir))

if controller.list.include?(ARGV.first)
  options[:application] = ARGV.shift 
elsif controller.list.length == 1 && ALLOWED_COMMANDS.include?(ARGV.first)
  options[:application] = controller.list.first
end

options[:command] = ARGV.shift

case options[:command]
when "load"
  file = ARGV.shift
  eval(File.read(file))
when "log"
  pattern = ARGV.shift
  pattern = controller.send_cmd(options[:application], :grep_pattern, pattern)
  
  cmd = "tail -n 100 -f #{options[:log_file]} | grep -E '#{pattern}'"
  Kernel.exec(cmd)

when *ALLOWED_COMMANDS
  process_or_group_name = ARGV.shift
  puts controller.send_cmd(options[:application], options[:command], process_or_group_name)

else
  "Unknown command `%s`" % options[:command]
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bluepill-0.0.1 bin/bluepill