pleaserun 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84a11be503460d6af5609596f83c4995f278c920
4
- data.tar.gz: 3ace8d7cac212d0406fd4fe4df71c1870d1509c7
3
+ metadata.gz: 1607c72a99aa0a0bb5f3513e132c32c4ed64b340
4
+ data.tar.gz: 5aa785212a00ed91a9dfe31a09a63da531c4d1a8
5
5
  SHA512:
6
- metadata.gz: 32f25ee793d36fe24e4c117f17982ddf83003d7d407cababa6af80403b6f61438a6d828469d2eac32ac7e57ca702620c1c6cb5921f94e792a89d134f32fde0a7
7
- data.tar.gz: 8d1014835d3efe304e9c6524c7d634e1e5cf4af3f4449150780954255674fde584c2e9f7ce54a57c89c50abcd7a151ae88ad1c053f7ffd81146fa0aba52243eb
6
+ metadata.gz: 5d3279e7c1bf924033659d3a11ab28fca8688208df956199a641f5e234fbf11d36d818375a091eeafadc353d397e2a0b1ad0b65f58ee592e9908b8cec630c086
7
+ data.tar.gz: 105778d5a15040001808f335a4737b98e9ff70860e06b323b113a19119f6ff98eb3b4912cf0ff387e4817480c969708f4fdb05dc786015ca292cbc60dbf17447
data/CHANGELOG.asciidoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = Pleaserun Changes and Releases
2
2
 
3
+ == 0.0.21 (May 16, 2016)
4
+ * Platform detection mechanism now looks for evidence that a given platform
5
+ is available (files, executables, etc). The previous mechanism used facter
6
+ or ohai to figure out the operating system version and had a mapping of OS to
7
+ platform.
8
+
3
9
  == 0.0.20 (May 13, 2016)
4
10
  * The --install-prefix flag now sets the write path for both --install and --no-install (default) modes
5
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pleaserun (0.0.19)
4
+ pleaserun (0.0.20)
5
5
  cabin (> 0)
6
6
  clamp
7
7
  insist
@@ -1,102 +1,84 @@
1
1
  require "cabin"
2
+ require "open3"
2
3
 
3
- # Detect the operating system and version, and based on that information,
4
- # choose the most appropriate runner platform.
5
- # TODO(sissel): Make this a module, not a class.
6
- class PleaseRun::Detector
4
+ # Detect the service platform that's most likely to be successful on the
5
+ # running machine.
6
+ #
7
+ # See the `detect` method.
8
+ module PleaseRun::Detector
7
9
  class UnknownSystem < StandardError; end
8
10
 
9
- # A mapping of of [os, version] => [runner, version]
10
- MAPPING = {
11
- ["amazon", "2014.09"] => ["upstart", "0.6.5"],
12
- ["arch", "rolling"] => ["systemd", "default"],
13
- ["centos", "5"] => ["sysv", "lsb-3.1"],
14
- ["centos", "6"] => ["upstart", "0.6.5"],
15
- ["centos", "7"] => ["systemd", "default"],
16
- ["debian", "6"] => ["sysv", "lsb-3.1"],
17
- ["debian", "7"] => ["sysv", "lsb-3.1"],
18
- ["debian", "8"] => ["systemd", "default"],
19
- ["fedora", "18"] => ["systemd", "default"],
20
- ["fedora", "19"] => ["systemd", "default"],
21
- ["fedora", "20"] => ["systemd", "default"],
22
- ["fedora", "21"] => ["systemd", "default"],
23
- ["fedora", "22"] => ["systemd", "default"],
24
- ["fedora", "23"] => ["systemd", "default"],
25
- ["mac_os_x", "10.11"] => ["launchd", "10.9"],
26
- ["mac_os_x", "10.10"] => ["launchd", "10.9"],
27
- ["mac_os_x", "10.8"] => ["launchd", "10.9"],
28
- ["mac_os_x", "10.9"] => ["launchd", "10.9"],
29
- ["opensuse", "12"] => ["sysv", "lsb-3.1"],
30
- ["opensuse", "13"] => ["systemd", "default"],
31
- ["ubuntu", "12.04"] => ["upstart", "1.5"],
32
- ["ubuntu", "12.10"] => ["upstart", "1.5"],
33
- ["ubuntu", "13.04"] => ["upstart", "1.5"],
34
- ["ubuntu", "13.10"] => ["upstart", "1.5"],
35
- ["ubuntu", "14.04"] => ["upstart", "1.5"],
36
- ["ubuntu", "14.10"] => ["upstart", "1.5"],
37
- ["ubuntu", "15.04"] => ["systemd", "default"],
38
- ["ubuntu", "15.10"] => ["systemd", "default"],
39
- ["ubuntu", "16.04"] => ["systemd", "default"]
40
- }
41
-
42
- def self.detect
11
+ module_function
12
+
13
+ def detect
43
14
  return @system unless @system.nil?
44
15
 
45
16
  @logger ||= Cabin::Channel.get
46
- begin
47
- platform, version = detect_ohai
48
- rescue LoadError => e
49
- @logger.debug("Failed to load ohai", :exception => e)
50
- begin
51
- platform, version = detect_facter
52
- rescue LoadError
53
- raise UnknownSystem, "Could not detect because neither ohai nor facter libraries are found"
54
- end
55
- end
56
-
57
- @system = lookup([platform, version])
58
- raise UnknownSystem, "#{platform} #{version}" if @system.nil?
17
+ @system = detect_platform
18
+ raise UnknownSystem, "Unable to detect which service platform to use" if @system.nil?
59
19
  return @system
60
20
  end # def self.detect
61
21
 
62
- def self.lookup(platform_and_version)
63
- return MAPPING[platform_and_version]
64
- end # def self.lookup
65
-
66
- def self.detect_ohai
67
- require "ohai/system"
68
- ohai = Ohai::System.new
69
- # TODO(sissel): Loading all plugins takes a long time (seconds).
70
- # TODO(sissel): Figure out how to load just the platform plugin correctly.
71
- ohai.all_plugins
72
-
73
- platform = ohai["platform"]
74
- version = ohai["platform_version"]
75
-
76
- return platform, normalize_version(platform, version)
77
- end # def detect_ohai
78
-
79
- def self.detect_facter
80
- require "facter"
81
-
82
- platform = Facter.value(:operatingsystem).downcase
83
- version = Facter.value(:operatingsystemrelease)
84
- return platform, normalize_version(platform, version)
85
- end # def detect_facter
86
-
87
- def self.normalize_version(platform, version)
88
- case platform
89
- # Take '6.0.8' and make it just '6' since debian never makes major
90
- # changes in a minor release
91
- when "debian", "centos"
92
- return version[/^[0-9]+/] # First digit is the 'major' version
93
- when "mac_os_x"
94
- return version[/^[0-9]+\.[0-9]+/] # 10.x
95
- when "arch"
96
- return "rolling"
97
- # TODO(sissel): Any other edge cases?
98
- end
99
- return version
22
+ def detect_platform
23
+ detect_systemd || detect_upstart || detect_launchd || detect_runit || detect_sysv
24
+ end
25
+
26
+ def detect_systemd
27
+ # Expect a certain directory
28
+ return false unless File.directory?("/lib/systemd/system")
29
+
30
+ # Check the version. If `systemctl` fails, systemd isn't available.
31
+ out, status = execute([ "systemctl", "--version" ])
32
+ return false unless status.success?
33
+
34
+ # version is the last word on the first line of the --version output
35
+ version = out.split("\n").first.split(/\s+/).last
36
+ ["systemd", version]
37
+ end
38
+
39
+ def detect_upstart
40
+ # Expect a certain directory
41
+ return false unless File.directory?("/etc/init")
42
+
43
+ # Check the version. If `initctl` fails, upstart isn't available.
44
+ out, status = execute(["initctl", "--version"])
45
+ return false unless status.success?
46
+
47
+ version = out.split("\n").first.tr("()", "").split(/\s+/).last
48
+ ["upstart", version]
100
49
  end
101
50
 
51
+ def detect_sysv
52
+ return false unless File.directory?("/etc/init.d")
53
+
54
+ # TODO(sissel): Do more specific testing.
55
+ ["sysv", "lsb-3.1"]
56
+ end
57
+
58
+ def detect_launchd
59
+ return false unless File.directory?("/Library/LaunchDaemons")
60
+
61
+ out, status = execute(["launchctl", "version"])
62
+ return false unless status.success?
63
+
64
+ # TODO(sissel): Version?
65
+ version = out.split("\n").first.split(":").first.split(/\s+/).last
66
+ ["launchd", version]
67
+ end
68
+
69
+ def detect_runit
70
+ return false unless File.directory?("/service")
71
+
72
+ # TODO(sissel): Do more tests for runit
73
+ end
74
+
75
+ def execute(command)
76
+ Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|
77
+ stdin.close
78
+ out = stdout.read
79
+ stderr.close
80
+ exit_status = wait_thr.value
81
+ return out, exit_status
82
+ end
83
+ end
102
84
  end
data/pleaserun.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |spec|
2
2
  files = File.read(__FILE__)[/^__END__$.*/m].split("\n")[1..-1]
3
3
 
4
4
  spec.name = "pleaserun"
5
- spec.version = "0.0.20"
5
+ spec.version = "0.0.21"
6
6
  spec.summary = "pleaserun"
7
7
  spec.description = "pleaserun"
8
8
  spec.license = "Apache 2.0"
@@ -7,8 +7,11 @@ Description={{{ description }}}
7
7
  Type=simple
8
8
  User={{{ user }}}
9
9
  Group={{{ group }}}
10
- EnvironmentFile=/etc/default/{{{name}}}
11
- EnvironmentFile=/etc/sysconfig/{{{name}}}
10
+ # Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
11
+ # Prefixing the path with '-' makes it try to load, but if the file doesn't
12
+ # exist, it continues onward.
13
+ EnvironmentFile=-/etc/default/{{{name}}}
14
+ EnvironmentFile=-/etc/sysconfig/{{{name}}}
12
15
  ExecStart={{{program}}} {{{shell_args}}}
13
16
  {{#prestart}}
14
17
  ExecStartPre=/lib/systemd/system/{{{name}}}-prestart.sh
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pleaserun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Sissel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-13 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cabin