Skip to content

Commit

Permalink
Add Supervisor service support for non-Systemd platforms
Browse files Browse the repository at this point in the history
This is a first crack at supporting the otherwise-supported pre-Systemd
platforms in the `hab_sup` resource. My init config fu was pretty atrophied,
but things seem to function after cribbing bits and pieces from the chef-client
and docker cookbooks.

The Upstart resource covers Ubuntu 14.04, CentOS 6, and Amazon Linux while the
Sysvinit resource covers Debian 7 (at least, until support for Debian 7 is
dropped).

All the `sup` suite's integration tests pass, in both Vagrant and Dokken.

Signed-off-by: Jonathan Hartman <j@hartman.io>
  • Loading branch information
hartmantis committed Nov 28, 2017
1 parent 95f3a16 commit 86a2888
Show file tree
Hide file tree
Showing 16 changed files with 592 additions and 169 deletions.
15 changes: 0 additions & 15 deletions .kitchen.dokken.yml
Expand Up @@ -83,22 +83,7 @@ suites:
run_list: test::package
- name: sup
run_list: test::sup
# these platforms don't have systemd as the default init system
excludes:
- debian-7
- centos-6
- ubuntu-14.04
- name: service
run_list: test::service
# these platforms don't have systemd as the default init system
excludes:
- debian-7
- centos-6
- ubuntu-14.04
- name: config
run_list: test::config
# these platforms don't have systemd as the default init system
excludes:
- centos-6.9
- debian-7.11
- ubuntu-14.04
15 changes: 0 additions & 15 deletions .kitchen.yml
Expand Up @@ -29,22 +29,7 @@ suites:
run_list: test::package
- name: service
run_list: test::service
# these platforms don't have systemd as the default init system
excludes:
- centos-6
- debian-7
- ubuntu-14.04
- name: sup
run_list: test::sup
# these platforms don't have systemd as the default init system
excludes:
- centos-6
- debian-7
- ubuntu-14.04
- name: config
run_list: test::config
# these platforms don't have systemd as the default init system
excludes:
- centos-6.9
- debian-7.11
- ubuntu-14.04
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -27,9 +27,17 @@ env:
- INSTANCE=package-ubuntu-1604
- INSTANCE=package-centos-6
- INSTANCE=package-centos-7
- INSTANCE=service-ubuntu-1404
- INSTANCE=service-ubuntu-1604
- INSTANCE=service-centos-6
- INSTANCE=service-centos-7
- INSTANCE=sup-ubuntu-1404
- INSTANCE=sup-ubuntu-1604
- INSTANCE=sup-centos-6
- INSTANCE=sup-centos-7
- INSTANCE=config-ubuntu-1404
- INSTANCE=config-ubuntu-1604
- INSTANCE=config-centos-6
- INSTANCE=config-centos-7

before_script:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -13,8 +13,8 @@ This cookbook provides resources for working with [Habitat](https://habitat.sh).

### Platforms

- RHEL 7+
- Ubuntu 16.04+
- RHEL 6+
- Ubuntu 14.04+

### Habitat

Expand Down Expand Up @@ -175,7 +175,7 @@ hab_service 'acme/apps'

Runs a Habitat Supervisor for one or more Habitat Services. This requires [Habitat version 0.20 or higher](https://forums.habitat.sh/t/habitat-0-20-0-released/317). It is used in conjunction with `hab_service` which will manage the services loaded and started within the supervisor.

The `run` action handles installing Habitat using the `hab_install` resource, ensures that the `core/hab-sup` package is installed using `hab_package`, and then drops off the appropriate init system definitions and manages the service. At this time, only systemd is supported.
The `run` action handles installing Habitat using the `hab_install` resource, ensures that the `core/hab-sup` package is installed using `hab_package`, and then drops off the appropriate init system definitions and manages the service.

#### Actions

Expand Down
59 changes: 59 additions & 0 deletions libraries/resource_hab_sup.rb
@@ -0,0 +1,59 @@
#
# Copyright:: Copyright (c) 2017 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

require 'chef/resource'

class Chef
class Resource
class HabSup < Resource
provides :hab_sup do |_node|
false
end

property :permanent_peer, [true, false], default: false
property :listen_gossip, String
property :listen_http, String
property :override_name, String, default: 'default'
property :org, String, default: 'default'
property :peer, String
property :ring, String
property :hab_channel, String

action :run do
hab_install new_resource.name do
channel new_resource.hab_channel if new_resource.hab_channel
end

hab_package 'core/hab-sup'
end

action_class do
def exec_start_options
opts = []
opts << '--permanent-peer' if new_resource.permanent_peer
opts << "--listen-gossip #{new_resource.listen_gossip}" if new_resource.listen_gossip
opts << "--listen-http #{new_resource.listen_http}" if new_resource.listen_http
opts << "--override-name #{new_resource.override_name}" unless new_resource.override_name == 'default'
opts << "--org #{new_resource.org}" unless new_resource.org == 'default'
opts << "--peer #{new_resource.peer}" if new_resource.peer
opts << "--ring #{new_resource.ring}" if new_resource.ring
opts.join(' ')
end
end
end
end
end
52 changes: 52 additions & 0 deletions libraries/resource_hab_sup_systemd.rb
@@ -0,0 +1,52 @@
#
# Copyright:: Copyright (c) 2017 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

require_relative 'resource_hab_sup'

class Chef
class Resource
class HabSupSystemd < HabSup
provides :hab_sup_systemd
provides :hab_sup do |_node|
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
end

action :run do
super()

systemd_unit "hab-sup-#{new_resource.override_name}.service" do
content(Unit: {
Description: 'The Habitat Supervisor',
},
Service: {
ExecStart: "/bin/hab sup run #{exec_start_options}",
Restart: 'on-failure',
},
Install: {
WantedBy: 'default.target',
})
action :create
end

service "hab-sup-#{new_resource.override_name}" do
subscribes :restart, "systemd_unit[hab-sup-#{new_resource.override_name}.service]"
action :start
end
end
end
end
end
50 changes: 50 additions & 0 deletions libraries/resource_hab_sup_sysvinit.rb
@@ -0,0 +1,50 @@
#
# Copyright:: Copyright (c) 2017 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

require_relative 'resource_hab_sup'

class Chef
class Resource
class HabSupSysvinit < HabSup
provides :hab_sup_sysvinit
provides :hab_sup do |node|
provs = Chef::Platform::ServiceHelpers.service_resource_providers
node['platform_family'] == 'debian' && !provs.include?(:systemd) && !provs.include?(:upstart)
end

action :run do
super()

template "/etc/init.d/hab-sup-#{new_resource.override_name}" do
source "sysvinit/hab-sup-#{node['platform_family']}.erb"
cookbook 'habitat'
owner 'root'
group 'root'
mode '0755'
variables(name: "hab-sup-#{new_resource.override_name}",
exec_start_options: exec_start_options)
action :create
end

service "hab-sup-#{new_resource.override_name}" do
subscribes :restart, "template[/etc/init.d/hab-sup-#{new_resource.override_name}]"
action :start
end
end
end
end
end
51 changes: 51 additions & 0 deletions libraries/resource_hab_sup_upstart.rb
@@ -0,0 +1,51 @@
#
# Copyright:: Copyright (c) 2017 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#

require_relative 'resource_hab_sup'

class Chef
class Resource
class HabSupUpstart < HabSup
provides :hab_sup_upstart
provides :hab_sup do |_node|
provs = Chef::Platform::ServiceHelpers.service_resource_providers
!provs.include?(:systemd) && provs.include?(:upstart)
end

action :run do
super()

template "/etc/init/hab-sup-#{new_resource.override_name}.conf" do
source 'upstart/hab-sup.conf.erb'
cookbook 'habitat'
owner 'root'
group 'root'
mode '0644'
variables exec_start_options: exec_start_options
action :create
end

service "hab-sup-#{new_resource.override_name}" do
# RHEL 6 includes Upstart but Chef won't use it unless we specify the provider.
provider Chef::Provider::Service::Upstart
subscribes :restart, "template[/etc/init/hab-sup-#{new_resource.override_name}.conf]"
action :start
end
end
end
end
end
73 changes: 0 additions & 73 deletions resources/sup_systemd.rb

This file was deleted.

0 comments on commit 86a2888

Please sign in to comment.