Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
bluepill Cookbook CHANGELOG
===========================
This file is used to list changes made in each version of the bluepill cookbook.
v2.3.1
------
### New Feature
- **[COOK-3705](https://tickets.opscode.com/browse/COOK-3705)** - Add init.d script with LSB style
v2.3.0
------
### Improvement
- **[COOK-3503](https://tickets.opscode.com/browse/COOK-3503)** - Add why-run support
v2.2.2
------
- [COOK-2507] - stringify language attributes
v2.2.0
------
- [COOK-547] - Add `load` action to provider to reload services when template changes.
v2.1.0
------
- [COOK-1295] - The bluepill cookbook does not create the default log file
- [COOK-1840] - Enable bluepill to log to rsyslog
v2.0.0
------
This version uses platform_family attribute (in the provider), making the cookbook incompatible with older versions of Chef/Ohai, hence the major version bump.
- [COOK-1644] - Bluepill cookbook fails on Redhat due to missing default or redhat template directory.
- [COOK-1920] - init script should have a template file named after platform_family instead of using file specificity
v1.1.2
------
- [COOK-1730] - Add ability to specify which version of bluepill to install
v1.1.0
------
- [COOK-1592] - use mixlib-shellout instead of execute, add test-kitchen
v1.0.6
------
- [COOK-1304] - support amazon linux
- [COOK-1427] - resolve foodcritic warnings
v1.0.4
------
- [COOK-1106] - fix chkconfig loader for CentOS 5
- [COOK-1107] - use integer for GID instead of string
v1.0.2
------
- [COOK-1043] - Bluepill cookbook fails on OS X because it tries to use root group
v1.0.0
------
- [COOK-943] - add init script for freebsd
v0.3.0
------
- [COOK-867] - enable bluepill service on RHEL family
- [COOK-550] - add freebsd support
v0.2.2
------
- Fixes COOK-524, COOK-632

View File

@@ -0,0 +1,87 @@
bluepill Cookbook
=================
Installs bluepill RubyGem and configures it to manage services. Also includes a LWRP.
Requirements
------------
Bluepill is a pure Ruby service management tool/library, so this cookbook should work on any system. The attributes do set up paths based on FHS locations, see below.
Attributes
----------
Default locations for bluepill are in "FHS compliant" locations.
* `node["bluepill"]["bin"]` - Path to bluepill program, default is 'bluepill' in the RubyGems binary directory.
* `node["bluepill"]["logfile"]` - Location of the bluepill log file, default "/var/log/bluepill.log".
* `node["bluepill"]["conf_dir"]` - Location of service config files (pills), default "/etc/bluepill".
* `node["bluepill"]["pid_dir"]` - Location of pidfiles, default "/var/run/bluepill"
* `node["bluepill"]["state_dir"]` - Location of state directory, default "/var/lib/bluepill"
* `node["bluepill"]["init_dir"]` - Location of init script directory, default selected by platform.
* `node["bluepill"]["version"]` - Version of bluepill to install, default is latest.
* `node["bluepill"]["use_rsyslog"]` - Enable configuration and use of rsyslog for bluepill.
Resources/Providers
-------------------
This cookbook contains an LWRP, `bluepill_service`. This can be used with the normal Chef service resource, by using the `provider` parameter, or by specifying the `bluepill_service` shortcut. These two resources are equivalent.
```ruby
service 'my_app' do
provider bluepill_service
action [:enable, :load, :start]
end
bluepill_service 'my_app' do
action [:enable, :load, :start]
end
```
The load action should probably always be specified, to ensure that if bluepill isn't running already it gets started. The
The recipe using the service must contain a template resource for the pill and it must be named `my_app.pill.erb`, where `my_app` is the service name passed to the bluepill service resource.
Usage
-----
Be sure to include the bluepill recipe in the run list to ensure that the gem and bluepill-related directories are created. This will also make the cookbook available on the system and other cookbooks won't need to explicitly depend on it in the metadata.
If the default directory locations in the attributes/default.rb aren't what you want, change them by setting them either in the attributes file itself, or create attributes in a role applied to any systems that will use bluepill.
Example pill template resource and .erb file:
```ruby
template '/etc/bluepill/my_app.pill' do
source 'my_app.pill.erb'
end
Bluepill.application('my_app') do |app|
app.process('my_app') do |process|
process.pid_file = '/var/run/my_app.pid'
process.start_command = '/usr/bin/my_app'
end
end
```
See bluepill's documentation for more information on creating pill templates.
License & Authors
-----------------
- Author:: Joshua Timberman (<joshua@opscode.com>)
```text
Copyright 2010-2013, Opscode, Inc.
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.
```

View File

@@ -0,0 +1,35 @@
# Cookbook Name:: bluepill
# Attributes:: default
#
# Copyright 2010, Opscode, Inc.
#
# 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.
default["bluepill"]["bin"] = "#{node['languages']['ruby']['bin_dir']}/bluepill"
default["bluepill"]["logfile"] = "/var/log/bluepill.log"
default["bluepill"]["pid_dir"] = "/var/run/bluepill"
default["bluepill"]["state_dir"] = "/var/lib/bluepill"
default["bluepill"]["group"] = 0
default["bluepill"]["use_rsyslog"] = false
case platform
when "arch"
default["bluepill"]["init_dir"] = "/etc/rc.d"
default["bluepill"]["conf_dir"] = "/etc/bluepill"
when "freebsd"
default["bluepill"]["init_dir"] = "/usr/local/etc/rc.d"
default["bluepill"]["conf_dir"] = "/usr/local/etc/bluepill"
else
default["bluepill"]["init_dir"] = "/etc/init.d"
default["bluepill"]["conf_dir"] = "/etc/bluepill"
end

View File

@@ -0,0 +1,31 @@
{
"name": "bluepill",
"version": "2.3.1",
"description": "Installs bluepill gem and configures to manage services, includes bluepill_service LWRP",
"long_description": "bluepill Cookbook\n=================\nInstalls bluepill RubyGem and configures it to manage services. Also includes a LWRP.\n\n\nRequirements\n------------\nBluepill is a pure Ruby service management tool/library, so this cookbook should work on any system. The attributes do set up paths based on FHS locations, see below.\n\n\nAttributes\n----------\nDefault locations for bluepill are in \"FHS compliant\" locations.\n\n* `node[\"bluepill\"][\"bin\"]` - Path to bluepill program, default is 'bluepill' in the RubyGems binary directory.\n* `node[\"bluepill\"][\"logfile\"]` - Location of the bluepill log file, default \"/var/log/bluepill.log\".\n* `node[\"bluepill\"][\"conf_dir\"]` - Location of service config files (pills), default \"/etc/bluepill\".\n* `node[\"bluepill\"][\"pid_dir\"]` - Location of pidfiles, default \"/var/run/bluepill\"\n* `node[\"bluepill\"][\"state_dir\"]` - Location of state directory, default \"/var/lib/bluepill\"\n* `node[\"bluepill\"][\"init_dir\"]` - Location of init script directory, default selected by platform.\n* `node[\"bluepill\"][\"version\"]` - Version of bluepill to install, default is latest.\n* `node[\"bluepill\"][\"use_rsyslog\"]` - Enable configuration and use of rsyslog for bluepill.\n\n\nResources/Providers\n-------------------\nThis cookbook contains an LWRP, `bluepill_service`. This can be used with the normal Chef service resource, by using the `provider` parameter, or by specifying the `bluepill_service` shortcut. These two resources are equivalent.\n\n```ruby\nservice 'my_app' do\n provider bluepill_service\n action [:enable, :load, :start]\nend\n\nbluepill_service 'my_app' do\n action [:enable, :load, :start]\nend\n```\n\nThe load action should probably always be specified, to ensure that if bluepill isn't running already it gets started. The\n\nThe recipe using the service must contain a template resource for the pill and it must be named `my_app.pill.erb`, where `my_app` is the service name passed to the bluepill service resource.\n\n\nUsage\n-----\nBe sure to include the bluepill recipe in the run list to ensure that the gem and bluepill-related directories are created. This will also make the cookbook available on the system and other cookbooks won't need to explicitly depend on it in the metadata.\n\nIf the default directory locations in the attributes/default.rb aren't what you want, change them by setting them either in the attributes file itself, or create attributes in a role applied to any systems that will use bluepill.\n\nExample pill template resource and .erb file:\n\n```ruby\ntemplate '/etc/bluepill/my_app.pill' do\n source 'my_app.pill.erb'\nend\n\nBluepill.application('my_app') do |app|\n app.process('my_app') do |process|\n process.pid_file = '/var/run/my_app.pid'\n process.start_command = '/usr/bin/my_app'\n end\nend\n```\n\nSee bluepill's documentation for more information on creating pill templates.\n\n\nLicense & Authors\n-----------------\n- Author:: Joshua Timberman (<joshua@opscode.com>)\n\n```text\nCopyright 2010-2013, Opscode, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n",
"maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com",
"license": "Apache 2.0",
"platforms": {
},
"dependencies": {
"rsyslog": ">= 0.0.0"
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
},
"groupings": {
},
"recipes": {
"bluepill::default": "Installs bluepill rubygem and set up management directories"
}
}

View File

@@ -0,0 +1,10 @@
name "bluepill"
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs bluepill gem and configures to manage services, includes bluepill_service LWRP"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "2.3.1"
recipe "bluepill::default", "Installs bluepill rubygem and set up management directories"
depends "rsyslog"

View File

@@ -0,0 +1,175 @@
#
# Cookbook Name:: bluepill
# Provider:: service
#
# Copyright 2010, Opscode, Inc.
# Copyright 2012, Heavy Water Operations, LLC
#
# 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/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut
def whyrun_supported?
true
end
action :enable do
config_file = ::File.join(node['bluepill']['conf_dir'],
"#{new_resource.service_name}.pill")
unless @current_resource.enabled
converge_by("enable #{ @new_resource }") do
link "#{node['bluepill']['init_dir']}/#{new_resource.service_name}" do
to node['bluepill']['bin']
only_if { ::File.exists?(config_file) }
end
template_suffix = case node['platform_family']
when "rhel", "fedora", "freebsd" then node['platform_family']
when 'debian' then 'lsb'
else nil
end
template "#{node['bluepill']['init_dir']}/bluepill-#{new_resource.service_name}" do
source "bluepill_init.#{template_suffix}.erb"
cookbook "bluepill"
owner "root"
group node['bluepill']['group']
mode "0755"
variables(
:service_name => new_resource.service_name,
:config_file => config_file
)
end if template_suffix
service "bluepill-#{new_resource.service_name}" do
action [ :enable ]
end
end
end
end
action :load do
unless @current_resource.running
converge_by("load #{ @new_resource }") do
shell_out!(load_command)
end
end
end
action :reload do
converge_by("reload #{ @new_resource }") do
shell_out!(stop_command) if @current_resource.running
shell_out!(load_command)
end
end
action :start do
unless @current_resource.running
converge_by("start #{ @new_resource }") do
shell_out!(start_command)
end
end
end
action :disable do
if @current_resource.enabled
converge_by("disable #{ @new_resource }") do
file "#{node['bluepill']['conf_dir']}/#{new_resource.service_name}.pill" do
action :delete
end
link "#{node['bluepill']['init_dir']}/#{new_resource.service_name}" do
action :delete
end
end
end
end
action :stop do
if @current_resource.running
converge_by("stop #{ @new_resource }") do
shell_out!(stop_command)
end
end
end
action :restart do
if @current_resource.running
converge_by("restart #{ @new_resource }") do
Chef::Log.debug "Restarting #{new_resource.service_name}"
shell_out!(restart_command)
Chef::Log.debug "Restarted #{new_resource.service_name}"
end
end
end
def load_current_resource
@current_resource = Chef::Resource::BluepillService.new(new_resource.name)
@current_resource.service_name(new_resource.service_name)
Chef::Log.debug("Checking status of service #{new_resource.service_name}")
determine_current_status!
@current_resource
end
protected
def status_command
"#{node['bluepill']['bin']} #{new_resource.service_name} status"
end
def load_command
"#{node['bluepill']['bin']} load #{node['bluepill']['conf_dir']}/#{new_resource.service_name}.pill"
end
def start_command
"#{node['bluepill']['bin']} #{new_resource.service_name} start"
end
def stop_command
"#{node['bluepill']['bin']} #{new_resource.service_name} stop"
end
def restart_command
"#{node['bluepill']['bin']} #{new_resource.service_name} restart"
end
def determine_current_status!
service_running?
service_enabled?
end
def service_running?
begin
if shell_out(status_command).exitstatus == 0
@current_resource.running true
Chef::Log.debug("#{new_resource} is running")
end
rescue Mixlib::ShellOut::ShellCommandFailed, SystemCallError
@current_resource.running false
nil
end
end
def service_enabled?
if ::File.exists?("#{node['bluepill']['conf_dir']}/#{new_resource.service_name}.pill") &&
::File.symlink?("#{node['bluepill']['init_dir']}/#{new_resource.service_name}")
@current_resource.enabled true
else
@current_resource.enabled false
end
end

View File

@@ -0,0 +1,48 @@
#
# Cookbook Name:: bluepill
# Recipe:: default
#
# Copyright 2010, Opscode, Inc.
#
# 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.
#
gem_package "i18n" do
action :install
end
gem_package "bluepill" do
version node["bluepill"]["version"] if node["bluepill"]["version"]
action :install
end
[
node["bluepill"]["conf_dir"],
node["bluepill"]["pid_dir"],
node["bluepill"]["state_dir"]
].each do |dir|
directory dir do
recursive true
owner "root"
group node["bluepill"]["group"]
end
end
file node["bluepill"]["logfile"] do
owner "root"
group node["bluepill"]["group"]
mode "0755"
action :create_if_missing
end
include_recipe "bluepill::rsyslog" if node['bluepill']['use_rsyslog']

View File

@@ -0,0 +1,28 @@
#
# Cookbook Name:: bluepill
# Recipe:: rsyslog
#
# Copyright 2010, Opscode, Inc.
#
# 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.
#
include_recipe "rsyslog"
template "/etc/rsyslog.d/bluepill.conf" do
owner "root"
group "root"
mode 0644
source "bluepill_rsyslog.conf.erb"
notifies :restart, "service[rsyslog]"
end

View File

@@ -0,0 +1,27 @@
#
# Cookbook Name:: bluepill
# Resource:: service
#
# Copyright 2010, Opscode, Inc.
#
# 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.
#
actions :start, :stop, :enable, :disable, :load, :restart, :reload
default_action :start
attribute :service_name, :name_attribute => true
attribute :enabled, :default => false
attribute :running, :default => false
attribute :variables, :kind_of => Hash
attribute :supports, :default => { :restart => true, :status => true }

View File

@@ -0,0 +1,32 @@
#!/bin/sh
#
# Author: Jamie Winsor (<jamie@vialstudios.com>)
#
# chkconfig: 345 99 1
# Description: Bluepill loader for <%= @service_name %>
# Provides: <%= @service_name %>
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
BLUEPILL_BIN=<%= node['bluepill']['bin'] %>
BLUEPILL_CONFIG=<%= @config_file %>
SERVICE_NAME=<%= @service_name %>
case "$1" in
start)
echo "Loading bluepill configuration for $SERVICE_NAME "
$BLUEPILL_BIN load $BLUEPILL_CONFIG
;;
stop)
$BLUEPILL_BIN $SERVICE_NAME stop
$BLUEPILL_BIN $SERVICE_NAME quit
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

View File

@@ -0,0 +1,31 @@
#!/bin/sh
##
# PROVIDE: named
# REQUIRE: SERVERS cleanvar
# KEYWORD: shutdown
#
. /etc/rc.subr
name="<%= @service_name %>"
rcvar=`set_rcvar`
# Set some defaults
<%= @service_name %>_enable=${<%= @service_name %>_enable:-"NO"}
pidfile="/var/run/<%= @service_name %>.pid"
command="/usr/local/bin/bluepill"
start_precmd="${command} load <%= node['bluepill']['conf_dir'] %>/<%= @service_name %>.pill"
start_cmd="${command} ${name} start"
status_cmd="${command} ${name} status"
stop_cmd="${command} ${name} stop"
stop_postcmd="${command} ${name} quit"
load_rc_config ${name}
PATH="${PATH}:/usr/local/bin"
run_rc_command "$1"

View File

@@ -0,0 +1,34 @@
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: <%= @service_name %>
# Required-Start: bar
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 2 6
# Description: Bluepill loader for <%= @service_name %>
### END INIT INFO
BLUEPILL_BIN=<%= node['bluepill']['bin'] %>
BLUEPILL_CONFIG=<%= @config_file %>
SERVICE_NAME=<%= @service_name %>
case "$1" in
start)
echo "Loading bluepill configuration for $SERVICE_NAME "
$BLUEPILL_BIN load $BLUEPILL_CONFIG
;;
stop)
$BLUEPILL_BIN $SERVICE_NAME stop
$BLUEPILL_BIN $SERVICE_NAME quit
;;
restart)
$BLUEPILL_BIN $SERVICE_NAME restart
;;
status)
$BLUEPILL_BIN $SERVICE_NAME status
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

View File

@@ -0,0 +1,32 @@
#!/bin/sh
#
# Author: Jamie Winsor (<jamie@vialstudios.com>)
#
# chkconfig: 345 99 1
# Description: Bluepill loader for <%= @service_name %>
# Provides: <%= @service_name %>
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
BLUEPILL_BIN=<%= node['bluepill']['bin'] %>
BLUEPILL_CONFIG=<%= @config_file %>
SERVICE_NAME=<%= @service_name %>
case "$1" in
start)
echo "Loading bluepill configuration for $SERVICE_NAME "
$BLUEPILL_BIN load $BLUEPILL_CONFIG
;;
stop)
$BLUEPILL_BIN $SERVICE_NAME stop
$BLUEPILL_BIN $SERVICE_NAME quit
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

View File

@@ -0,0 +1 @@
local6.* <%= node["bluepill"]["logfile"] %>