Module: Anycablebility::Command

Defined in:
lib/anycablebility/command.rb

Overview

Runs system command (websocket server)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.runningObject

Returns the value of attribute running.



7
8
9
# File 'lib/anycablebility/command.rb', line 7

def running
  @running
end

Class Method Details

.runObject

rubocop: disable Metrics/MethodLength



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/anycablebility/command.rb', line 10

def run
  return if @running

  Anycable.logger.debug "Running command: #{Anycablebility.config.command}"

  out = Anycable.config.debug ? STDOUT : IO::NULL

  @pid = Process.spawn(
    Anycablebility.config.command,
    out: out,
    err: out
  )

  Process.detach(@pid)

  Anycable.logger.debug "Command PID: #{@pid}"

  @running = true

  sleep Anycablebility.config.wait_command
end

.running?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/anycablebility/command.rb', line 43

def running?
  @running == true
end

.stopObject

rubocop: enable Metrics/MethodLength



33
34
35
36
37
38
39
40
41
# File 'lib/anycablebility/command.rb', line 33

def stop
  return unless @running

  Anycable.logger.debug "Terminate PID: #{@pid}"

  Process.kill("SIGKILL", @pid)

  @running = false
end