default.rb 3.2 KB
Newer Older
Adam Jacob's avatar
Adam Jacob committed
1
#
Tim Smith's avatar
Tim Smith committed
2
# Cookbook:: runit
Adam Jacob's avatar
Adam Jacob committed
3 4
# Recipe:: default
#
Tim Smith's avatar
Tim Smith committed
5
# Copyright:: 2008-2019, Chef Software, Inc.
Adam Jacob's avatar
Adam Jacob committed
6
#
7
# Licensed under the Apache License, Version 2.0 (the 'License');
Adam Jacob's avatar
Adam Jacob committed
8 9
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
10
#
Adam Jacob's avatar
Adam Jacob committed
11
#     http://www.apache.org/licenses/LICENSE-2.0
12
#
Adam Jacob's avatar
Adam Jacob committed
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an 'AS IS' BASIS,
Adam Jacob's avatar
Adam Jacob committed
15 16 17 18
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
19
case node['platform_family']
Tim Smith's avatar
Tim Smith committed
20
when 'rhel', 'amazon'
21

Tim Smith's avatar
Tim Smith committed
22 23 24 25
  # add the necessary repos unless prefer_local_yum is set
  unless node['runit']['prefer_local_yum']
    include_recipe 'yum-epel' if node['platform_version'].to_i < 7

26
    packagecloud_repo 'imeyer/runit' do
27
      force_os 'rhel' if platform?('oracle', 'amazon') # ~FC024
Tim Smith's avatar
Tim Smith committed
28
      force_dist '6' if platform?('amazon')
29
      force_dist '7' if platform?('amazon') && node['platform_version'].to_i == 2
Tim Smith's avatar
Tim Smith committed
30
      type 'rpm' if platform?('amazon')
31
    end
Tim Smith's avatar
Tim Smith committed
32
  end
33

34
  package 'runit'
Tim Smith's avatar
Tim Smith committed
35
when 'debian'
Tim Smith's avatar
Tim Smith committed
36
  # debian 9+ ships with runit-systemd which includes only what you need for process supervision and not
37
  # what is necessary for running runit as pid 1, which we don't care about.
38 39 40 41 42 43 44
  pv = node['platform_version']
  pkg_name = if (platform?('debian') && pv.to_i >= 9) || \
                (platform?('ubuntu') && Gem::Version.new(pv) >= Gem::Version.new('17.10'))
               'runit-systemd'
             else
               'runit'
             end
Tim Smith's avatar
Tim Smith committed
45 46

  package pkg_name do
Adam Jacob's avatar
Adam Jacob committed
47
    action :install
Tim Smith's avatar
Tim Smith committed
48
    response_file 'runit.seed'
Adam Jacob's avatar
Adam Jacob committed
49
  end
50
else
Tim Smith's avatar
Tim Smith committed
51
  raise 'The cookbook only supports Debian/RHEL based Linux distributions. If you believe further platform support is possible please open a pull request.'
52
end
53 54 55

# we need to make sure we start the runit service so that runit services can be started up at boot
# or when they fail
56 57 58 59 60 61 62
plat_specific_sv_name = case node['platform_family']
                        when 'debian'
                          if platform?('ubuntu') && node['platform_version'].to_f < 16.04
                            'runsvdir'
                          else
                            'runit'
                          end
63
                        when 'rhel', 'amazon'
Tim Smith's avatar
Tim Smith committed
64
                          if node['platform_version'].to_i >= 7 && !platform?('amazon')
65
                            'runsvdir-start'
66 67
                          elsif node['platform_version'].to_i == 2 && platform?('amazon')
                            'runsvdir-start'
68 69 70 71 72 73
                          else
                            'runsvdir'
                          end
                        else
                          'runsvdir'
                        end
74

75
service plat_specific_sv_name do
76 77
  action [:start, :enable]
  # this might seem crazy, but RHEL 6 is in fact Upstart and the runit service is upstart there
jonathan.pirro's avatar
jonathan.pirro committed
78
  provider Chef::Provider::Service::Upstart if (platform?('amazon') && node['platform_version'].to_i != 2) || (platform_family?('rhel') && node['platform_version'].to_i == 6)
79
  not_if { platform?('debian') && node['platform_version'].to_i < 8 } # there's no init script on debian 7...for reasons
Adam Jacob's avatar
Adam Jacob committed
80
end