Module: Beachcomber::Discovery

Defined in:
lib/beachcomber/discovery.rb

Overview

Discovers the Unix socket path for the beachcomber daemon.

Discovery order:

1. $XDG_RUNTIME_DIR/beachcomber/sock  (if set and the path exists)
2. $TMPDIR/beachcomber-<uid>/sock
3. /tmp/beachcomber-<uid>/sock

Class Method Summary collapse

Class Method Details

.socket_pathString

Returns the discovered or best-guess socket path.

Returns:

  • (String)

    the discovered or best-guess socket path



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/beachcomber/discovery.rb', line 12

def self.socket_path
  xdg = ENV['XDG_RUNTIME_DIR']
  if xdg && !xdg.empty?
    candidate = File.join(xdg, 'beachcomber', 'sock')
    return candidate if File.exist?(candidate)
  end

  uid  = Process.uid
  dir  = "beachcomber-#{uid}"
  base = ENV.fetch('TMPDIR', nil) || '/tmp'
  File.join(base, dir, 'sock')
end