Module: Anyt::Command
- Defined in:
- lib/anyt/command.rb
Overview
Runs system command (websocket server)
Class Method Summary collapse
-
.restart ⇒ Object
rubocop: enable Metrics/MethodLength rubocop: enable Metrics/AbcSize.
- .run ⇒ Object
- .running? ⇒ Boolean
- .stop ⇒ Object
Class Method Details
.restart ⇒ Object
rubocop: enable Metrics/MethodLength rubocop: enable Metrics/AbcSize
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/anyt/command.rb', line 35 def restart return unless running? AnyCable.logger.debug "Restarting command PID: #{process.pid}" stop process.wait run end |
.run ⇒ Object
9 10 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 9 def run return if running? return 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? ⇒ Boolean
54 55 56 |
# File 'lib/anyt/command.rb', line 54 def running? process&.alive? end |
.stop ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/anyt/command.rb', line 46 def stop return unless running? AnyCable.logger.debug "Terminate PID: #{process.pid}" process.stop end |