5 ruby_path = ENV["RUBY"].gsub('"','')
6 basedir = ENV["BASEDIR"]
7 libdir = ENV["RUBYLIB"]
8 mcollectived = ENV["MCOLLECTIVED"]
9 configfile = ENV["SERVER_CONFIG"]
11 unless File.exist?(ruby_path)
12 ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
13 ruby = File.join(path, "ruby.exe")
22 abort("Can't find ruby.ext in the path") unless ruby_path
24 options = {:name => "mcollectived",
25 :display_name => "The Marionette Collective",
26 :description => "Puppet Labs server orchestration framework",
27 :command => '%s -I"%s" -- "%s" --config "%s"' % [ ruby_path, libdir, mcollectived, configfile ]}
31 opt.on("--install", "Install service") do
35 opt.on("--uninstall", "Remove service") do
39 opt.on("--name NAME", String, "Service name (#{options[:name]})") do |n|
43 opt.on("--description DESCRIPTION", String, "Service description (#{options[:description]})") do |v|
44 options[:description] = v
47 opt.on("--display NAME", String, "Service display name (#{options[:display_name]})") do |n|
48 options[:display_name] = n
51 opt.on("--command COMMAND", String, "Service command (#{options[:command]})") do |c|
57 abort "Please choose an action with --install or --uninstall" unless action
60 require 'win32/service'
66 if ENV["MC_STARTTYPE"] =~ /auto/i
67 start_type = Service::AUTO_START
69 start_type = Service::DEMAND_START
73 :service_name => options[:name],
74 :display_name => options[:display_name],
75 :description => options[:description],
76 :binary_path_name => options[:command],
77 :service_type => Service::SERVICE_WIN32_OWN_PROCESS,
78 :start_type => start_type
81 puts "Service %s installed" % [options[:name]]
84 Service.stop(options[:name]) unless Service.status(options[:name]).current_state == 'stopped'
86 while Service.status(options[:name]).current_state != 'stopped'
87 puts "Waiting for service %s to stop" % [options[:name]]
91 Service.delete(options[:name])
93 puts "Service %s removed" % [options[:name]]