#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/hudson' require 'un' require 'optparse' options = { :port => 3001, :control => 3002, :home => File.join(ENV['HOME'], '.hudson') } args = ARGV.dup opts = OptionParser.new do |opts| opts.banner = "Usage: hudson [options] [HUDSON_HOME]" opts.on("-d", "--daemon", "fork into background and run as daemon") do options[:daemon] = true end opts.on("-p", "--port [3001]", "run hudson on specified port ") do |port| options[:port] = port end opts.on("-c", "--control-port [3002]", Integer, "set the shutdown/control port") do |port| options[:control] = cport end opts.on_tail("-k", "--kill", "send shutdown signal to control port") do require 'socket' TCPSocket.open("localhost", options[:control]) do |sock| sock.write("0") end exit end opts.on_tail("-v", "--version", "show version information") do puts "#{Hudson::VERSION} (Hudson Server #{Hudson::HUDSON_VERSION})" exit end opts.on_tail("-h", "--help") do puts opts exit end end opts.parse!(args) dir = args.shift || options[:home] FileUtils.mkdir_p dir FileUtils.cp_r Hudson::PLUGINS, dir ENV['HUDSON_HOME'] = dir cmd = ["java", "-jar", Hudson::WAR] cmd << "--httpPort=#{options[:port]}" cmd << "--controlPort=#{options[:control]}" cmd << "--daemon" if options[:daemon] puts cmd.join(" ") exec(*cmd)