Class: Service

Inherits:
Unit
  • Object
show all
Defined in:
lib/tomo/testing/systemctl.rb

Instance Method Summary collapse

Methods inherited from Unit

#enable, find, #initialize

Constructor Details

This class inherits a constructor from Unit

Instance Method Details

#is_activeObject

rubocop:disable Naming/PredicatePrefix



124
125
126
127
# File 'lib/tomo/testing/systemctl.rb', line 124

def is_active # rubocop:disable Naming/PredicatePrefix
  exit(false) unless started?
  puts "active"
end

#restartObject



151
152
153
154
155
# File 'lib/tomo/testing/systemctl.rb', line 151

def restart
  super
  stop if started?
  start
end

#startObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/tomo/testing/systemctl.rb', line 129

def start
  super
  raise "#{name} is already running" if started?

  working_dir, executable = parse

  if (pid = Process.fork)
    with_persistent_state { |state| state[:pid] = pid }
    Process.detach(pid)
    return
  end

  with_detached_io { Dir.chdir(working_dir) { Process.exec(executable) } }
end

#statusObject



157
158
159
160
# File 'lib/tomo/testing/systemctl.rb', line 157

def status
  super
  puts "   Active: active (running)" if started?
end

#stopObject



144
145
146
147
148
149
# File 'lib/tomo/testing/systemctl.rb', line 144

def stop
  with_persistent_state do |state|
    pid = state.delete(:pid)
    Process.kill("TERM", pid) unless pid.nil?
  end
end