Class: Anyt::Command
- Inherits:
-
Object
- Object
- Anyt::Command
- Defined in:
- lib/anyt/command.rb
Overview
Runs system command (websocket server)
Class Attribute Summary collapse
-
.instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(cmd = Anyt.config.command) ⇒ Command
constructor
A new instance of Command.
-
#restart ⇒ Object
rubocop: enable Metrics/MethodLength rubocop: enable Metrics/AbcSize.
- #run ⇒ Object (also: #start)
- #running? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
Class Attribute Details
.instance ⇒ Object (readonly)
Returns the value of attribute instance.
9 10 11 |
# File 'lib/anyt/command.rb', line 9 def instance @instance end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
20 21 22 |
# File 'lib/anyt/command.rb', line 20 def cmd @cmd end |
Class Method Details
.default ⇒ Object
11 12 13 |
# File 'lib/anyt/command.rb', line 11 def default @instance ||= new end |
.restart ⇒ Object
15 16 17 |
# File 'lib/anyt/command.rb', line 15 def restart instance&.restart end |
Instance Method Details
#restart ⇒ Object
rubocop: enable Metrics/MethodLength rubocop: enable Metrics/AbcSize
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/anyt/command.rb', line 56 def restart return unless running? AnyCable.logger.debug "Restarting command PID: #{process.pid}" stop process.wait run end |
#run ⇒ Object Also known as: start
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/anyt/command.rb', line 26 def run return if running? return unless cmd AnyCable.logger.debug "Running command: #{cmd}" @process = ChildProcess.build(*cmd.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.environment["ACTION_CABLE_ADAPTER"] = "any_cable" unless Anyt.config.use_action_cable process.start AnyCable.logger.debug "Command PID: #{process.pid}" sleep Anyt.config.wait_command raise "Command failed to start" unless running? end |
#running? ⇒ Boolean
76 77 78 |
# File 'lib/anyt/command.rb', line 76 def running? process&.alive? end |
#stop ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/anyt/command.rb', line 68 def stop return unless running? AnyCable.logger.debug "Terminate PID: #{process.pid}" process.stop end |