Sha256: 6289cd078201e5a0d15980497059ec7946704baa9772eede73c315de2f13aa57

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
require 'mirage'
include Mirage::Util
RUBY_CMD = RUBY_PLATFORM == 'JAVA' ? 'jruby' : 'ruby'


def start_mirage(args, mirage)
  puts "Starting Mirage"
  system "(#{RUBY_CMD} #{File.dirname(__FILE__)}/../lib/start_mirage.rb #{args.join(' ')}) > /dev/null 2>&1 &"
  wait_until do
    mirage.running?
  end
end

def mirage_process_ids
  process_ids = []
  process_ids <<  `ps aux | grep "Mirage Server" | grep -v grep`.split(' ')[1]
  process_ids <<  `ps aux | grep "start_mirage" | grep -v grep`.split(' ')[1]
  return process_ids.compact
end

if ARGV.include?('start')

  options =  parse_options(ARGV)
  mirage_client = Mirage::Client.new "http://localhost:#{options[:port]}/mirage"

  if mirage_client.running?
    puts "Mirage already running"
    exit 1
  end

  start_mirage(ARGV, mirage_client)
  begin
    mirage_client.prime
  rescue Mirage::InternalServerException => e
    puts "WARN: #{e.message}"
  end


elsif ARGV.include?('stop')
  puts "Stoping Mirage"
  begin
    mirage_process_ids.each do |id|
      puts "killing #{id}"
      `kill -9 #{id}`
    end
  rescue
    puts 'Mirage is not running'
  end
else
  parse_options ['--help']
  exit 1
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mirage-1.1.0 bin/mirage