Class: Shrub::ServiceInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/ShrubServiceInstaller.rb

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ShrubServiceInstaller.rb', line 9

def self.run(argv)
	service_name = 'Shrub Server'
	ruby_bin = Config::CONFIG['bindir']
	file_dir = File.dirname(File.expand_path(__FILE__))
	@@ruby_exe = File.join("#{ruby_bin}", "ruby.exe")

	file_path = File.join(File.dirname(File.expand_path(__FILE__)), 'ShrubService.rb')
	cmd = "#{@@ruby_exe} \"#{file_path}\" #{@@ruby_exe}"

	if argv[0] == 'install'
		puts "Creating service for #{cmd}"

		Win32::Service.new(service_name, nil,
			:display_name     => service_name,
			:desired_access   => Win32::Service::ALL_ACCESS,
			:service_type     => Win32::Service::WIN32_OWN_PROCESS,
			:start_type       => Win32::Service::DEMAND_START,
			:error_control    => Win32::Service::ERROR_IGNORE,
			:binary_path_name => cmd,
			:load_order_group => 'Network',
			:dependencies     => nil,
			:description      => 'Executes ruby code sent from another machine'
		)
		exit
	elsif argv[0] == 'uninstall'
		Win32::Service.delete(service_name)
		exit
	elseif argv.length > 0
		puts 'I can\'t understand the command.'
		exit
	end
end