Sha256: bb43bdf7767494ee3b079f2f553067a902a04226c861d697378b14641f430632

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

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

# defaults
options = {
  :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
  puts "Unknown command `%s`" % options[:command]
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bluepill-0.0.3 bin/bluepill
bluepill-0.0.2 bin/bluepill