module Anyt::Command

Runs system command (websocket server)

Attributes

process[R]

Public Class Methods

restart() click to toggle source

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

# File lib/anyt/command.rb, line 37
def restart
  return unless running?

  AnyCable.logger.debug "Restarting command PID: #{process.pid}"

  stop
  process.wait

  run
end
run() click to toggle source

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

# File lib/anyt/command.rb, line 11
def run
  return if running?

  raise "Please, specify command via -c (--command) option" unless Anyt.config.command

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

  @process = ChildProcess.build(*Anyt.config.command.split(/\s+/))

  process.io.inherit! if AnyCable.config.debug

  process.detach = true

  process.environment["ANYCABLE_DEBUG"] = "1" if AnyCable.config.debug?
  process.environment["ANYT_REMOTE_CONTROL_PORT"] = Anyt.config.remote_control_port

  process.start

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

  sleep Anyt.config.wait_command
  raise "Command failed to start" unless running?
end
running?() click to toggle source
# File lib/anyt/command.rb, line 56
def running?
  process&.alive?
end
stop() click to toggle source
# File lib/anyt/command.rb, line 48
def stop
  return unless running?

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

  process.stop
end