Module: Contrast::Service

Extended by:
Rake::DSL
Includes:
Components::Interface
Defined in:
lib/contrast/tasks/service.rb

Overview

A Rake task designed to allow control of the Contrast Service as a stand alone executable rather than one managed by the Agent running in a process forked from the application

Class Method Summary collapse

Methods included from Components::Interface

included

Class Method Details

.start_serviceObject

Start the service if it is not already running



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/contrast/tasks/service.rb', line 18

def self.start_service
  puts 'Starting Contrast Service'
  service_log = CONTRAST_SERVICE.logger_path
  if File.writable?(service_log)
    spawn('contrast_service', out: File::NULL, err: service_log)
  else
    spawn('contrast_service', %i[out err] => File::NULL)
  end

  watcher = Contrast::Agent::Thread.new do
    sleep(0.05) until Contrast::Utils::OS.running?
  end
  watcher.join(1)
  puts Contrast::Utils::OS.running? ? 'Contrast Service started successfully.' : 'Contrast Service did not start.'
end

.stop_serviceObject

Stop the service if it is running



35
36
37
38
# File 'lib/contrast/tasks/service.rb', line 35

def self.stop_service
  pid = `ps aux | grep contrast-servic[e] | awk '{print $2}'`
  `kill #{ pid }` if pid
end