Module: FPM::Fry::Plugin::Init

Defined in:
lib/fpm/fry/plugin/init.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.detect_init(variables) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fpm/fry/plugin/init.rb', line 4

def self.detect_init(variables)
  if variables[:init]
    return variables[:init]
  end
  d = variables[:distribution]
  v = variables[:distribution_version].split('.').map(&:to_i)
  case(d)
  when 'debian'
    if v[0] < 8
      return 'sysv'
    else
      return 'systemd'
    end
  when 'ubuntu'
    if v[0] <= 14 && v[1] < 10
      return 'upstart'
    else
      return 'systemd'
    end
  when 'centos','redhat'
    if v[0] <= 5
      return 'sysv'
    elsif v[0] == 6
      return 'upstart'
    else
      return 'systemd'
    end
  else
    raise "Unknown init system for #{d} #{v.join '.'}"
  end
end

Instance Method Details

#init(*inits) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fpm/fry/plugin/init.rb', line 36

def init(*inits)
  inits = inits.flatten.map(&:to_s)
  actual = FPM::Fry::Plugin::Init.detect_init(variables)
  if inits.none?
    return actual
  elsif inits.include? actual
    if block_given?
      yield
    else
      return true
    end
  else
    return false
  end
end