default.rb 2.43 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-2016, 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 29
      force_dist '6' if platform?('amazon')
      type 'rpm' if platform?('amazon')
30
    end
Tim Smith's avatar
Tim Smith committed
31
  end
32

33
  package 'runit'
Tim Smith's avatar
Tim Smith committed
34
when 'debian'
35 36
  # debian 9+ ship with runit-systemd which includes only what you need for process supervision and not
  # what is necessary for running runit as pid 1, which we don't care about.
Tim Smith's avatar
Tim Smith committed
37 38 39
  pkg_name = platform?('debian') && node['platform_version'].to_i >= 9 ? 'runit-systemd' : 'runit'

  package pkg_name do
Adam Jacob's avatar
Adam Jacob committed
40
    action :install
Tim Smith's avatar
Tim Smith committed
41
    response_file 'runit.seed'
Adam Jacob's avatar
Adam Jacob committed
42
  end
43 44 45
else
  raise 'The cookbook only supports Debian/RHEL based Linux distributions. If you believe further platform support is possible pleae open a pull request.'
end
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

# we need to make sure we start the runit service so that runit services can be started up at boot
# or when they fail
service_name = case node['platform_family']
               when 'debian'
                 if platform?('ubuntu') && node['platform_version'].to_f < 16.04
                   'runsvdir'
                 else
                   'runit'
                 end
               when 'rhel'
                 if node['platform_version'].to_i >= 7
                   'runsvdir-start'
                 else
                   'runsvdir'
                 end
               end

service service_name do
  action [:start, :enable]
  # this might seem crazy, but RHEL 6 is in fact Upstart and the runit service is upstart there
  provider Chef::Provider::Service::Upstart if platform?('amazon') || platform_family?('rhel') && node['platform_version'].to_i == 6
Adam Jacob's avatar
Adam Jacob committed
68
end