Module: Anyt::Command

Defined in:
lib/anyt/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/anyt/command.rb', line 7

def running
  @running
end

Class Method Details

.runObject

rubocop: disable Metrics/MethodLength rubocop: disable Metrics/AbcSize



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

def run
  return if @running

  AnyCable.logger.debug "Running command: #{Anyt.config.command}"

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

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

  Process.detach(@pid)

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

  @running = true

  sleep Anyt.config.wait_command
end

.running?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/anyt/command.rb', line 45

def running?
  @running == true
end

.stopObject

rubocop: enable Metrics/MethodLength rubocop: enable Metrics/AbcSize



35
36
37
38
39
40
41
42
43
# File 'lib/anyt/command.rb', line 35

def stop
  return unless @running

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

  Process.kill("SIGKILL", @pid)

  @running = false
end