Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Supervisor service support for non-Systemd platforms
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
1 parent
95f3a16
commit 86a2888
Showing
16 changed files
with
592 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.