Class: AgentsControl::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/agents_control/service.rb

Overview

Autostarting the daemon: launchd on macOS, systemd on Linux.

Everything here is built around one rule: absolute paths. The service starts not from an interactive shell but from a system manager, where PATH is completely different and can't be relied on.

Defined Under Namespace

Classes: Launchd, Systemd

Constant Summary collapse

LABEL =
"com.agents-control.daemon"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby: nil, script: nil, logger: $stdout) ⇒ Service

The interpreter isn't looked up on PATH, it's the one running this code right now: a PATH search could find a version manager's broken shim ahead of the working Ruby. RbConfig.ruby by definition points at the live interpreter.



23
24
25
26
27
# File 'lib/agents_control/service.rb', line 23

def initialize(ruby: nil, script: nil, logger: $stdout)
  @ruby = ruby || RbConfig.ruby
  @script = script || default_script
  @logger = logger
end

Instance Attribute Details

#rubyObject (readonly)

Returns the value of attribute ruby.



29
30
31
# File 'lib/agents_control/service.rb', line 29

def ruby
  @ruby
end

#scriptObject (readonly)

Returns the value of attribute script.



29
30
31
# File 'lib/agents_control/service.rb', line 29

def script
  @script
end

Class Method Details

.for_platform(**args) ⇒ Object



15
16
17
# File 'lib/agents_control/service.rb', line 15

def self.for_platform(**args)
  RUBY_PLATFORM.include?("darwin") ? Launchd.new(**args) : Systemd.new(**args)
end

Instance Method Details

#log_pathObject



31
# File 'lib/agents_control/service.rb', line 31

def log_path = File.expand_path("~/Library/Logs/agents_control.log")