Module: PleaseRun::Detector
- Defined in:
- lib/pleaserun/detector.rb
Overview
Detect the service platform that’s most likely to be successful on the running machine.
See the ‘detect` method.
Defined Under Namespace
Classes: UnknownSystem
Class Method Summary collapse
- .detect ⇒ Object
- .detect_launchd ⇒ Object
-
.detect_platform ⇒ Object
def self.detect.
- .detect_runit ⇒ Object
- .detect_systemd ⇒ Object
- .detect_sysv ⇒ Object
- .detect_upstart ⇒ Object
- .execute(command) ⇒ Object
Class Method Details
.detect ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/pleaserun/detector.rb', line 13 def detect return @system unless @system.nil? @logger ||= Cabin::Channel.get @system = detect_platform raise UnknownSystem, "Unable to detect which service platform to use" if @system.nil? return @system end |
.detect_launchd ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pleaserun/detector.rb', line 58 def detect_launchd return false unless File.directory?("/Library/LaunchDaemons") out, status = execute(["launchctl", "version"]) return false unless status.success? # TODO(sissel): Version? version = out.split("\n").first.split(":").first.split(/\s+/).last ["launchd", version] end |
.detect_platform ⇒ Object
def self.detect
22 23 24 |
# File 'lib/pleaserun/detector.rb', line 22 def detect_platform detect_systemd || detect_upstart || detect_launchd || detect_runit || detect_sysv end |
.detect_runit ⇒ Object
69 70 71 72 73 |
# File 'lib/pleaserun/detector.rb', line 69 def detect_runit return false unless File.directory?("/service") # TODO(sissel): Do more tests for runit end |
.detect_systemd ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pleaserun/detector.rb', line 26 def detect_systemd # Expect a certain directory return false unless File.directory?("/lib/systemd/system") # Check the version. If `systemctl` fails, systemd isn't available. out, status = execute([ "systemctl", "--version" ]) return false unless status.success? # version is the last word on the first line of the --version output version = out.split("\n").first.split(/\s+/).last ["systemd", version] end |
.detect_sysv ⇒ Object
51 52 53 54 55 56 |
# File 'lib/pleaserun/detector.rb', line 51 def detect_sysv return false unless File.directory?("/etc/init.d") # TODO(sissel): Do more specific testing. ["sysv", "lsb-3.1"] end |
.detect_upstart ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pleaserun/detector.rb', line 39 def detect_upstart # Expect a certain directory return false unless File.directory?("/etc/init") # Check the version. If `initctl` fails, upstart isn't available. out, status = execute(["initctl", "--version"]) return false unless status.success? version = out.split("\n").first.tr("()", "").split(/\s+/).last ["upstart", version] end |
.execute(command) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/pleaserun/detector.rb', line 75 def execute(command) Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr| stdin.close out = stdout.read stderr.close exit_status = wait_thr.value return out, exit_status end end |