Class: LogTwuncator::Service

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

Instance Method Summary collapse

Instance Method Details

#binary_path_nameObject



125
126
127
128
129
130
131
# File 'lib/log_twuncator/service.rb', line 125

def binary_path_name
  path = "#{Config::CONFIG['bindir']}/rubyw #{Config::CONFIG['bindir']}/log_twuncator_daemon"
  path << " -c #{@options[:config]}"      
  path << " -d #{@options[:delay]}"
  path << " -l #{@options[:log]}"
  path
end

#installObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/log_twuncator/service.rb', line 82

def install
  if Win32::Service.exists?(@options[:name])
    puts "Service name '#{@options[:name]}' already exists."
    return
  end
  
  Win32::Service.new({
    :service_name => @options[:name],
    :display_name => @options[:name],
    :binary_path_name => binary_path_name
  })
  
  puts "Log Twuncator service '#{@options[:name]}' installed."
rescue Win32::Service::Error => e
  puts "Service '#{@options[:name]}' failed to install due to error: #{e.message}"
end

#removeObject



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/log_twuncator/service.rb', line 113

def remove
  begin
    Win32::Service.stop(@options[:name])
  rescue
  end

  Win32::Service.delete(@options[:name])
  puts "'#{@options[:name]}' service removed."
rescue Win32::Service::Error => e
  puts "Service '#{@options[:name]}' failed to be removed due to error: #{e.message}"
end

#run(args) ⇒ Object



133
134
135
136
137
# File 'lib/log_twuncator/service.rb', line 133

def run(args)
  command = LogTwuncator::ServiceCommand.new
  @options = command.run(args)      
  send(command.command.to_sym)
end

#startObject



99
100
101
102
103
104
# File 'lib/log_twuncator/service.rb', line 99

def start
  Win32::Service.start(@options[:name])
  puts "'#{@options[:name]}' service started."
rescue Win32::Service::Error => e
  puts "Service '#{@options[:name]}' failed to start due to error: #{e.message}"
end

#stopObject



106
107
108
109
110
111
# File 'lib/log_twuncator/service.rb', line 106

def stop
  Win32::Service.stop(@options[:name])
  puts "'#{@options[:name]}' service stopped."
rescue Win32::Service::Error => e
  puts "Service '#{@options[:name]}' failed to stop due to error: #{e.message}"      
end