Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add bluepill cookbook

  • Loading branch information...
commit 0bf34685c1e13fb04baf9f36fbee3ee4019d9b6c 1 parent e48bbef
@jtimberman jtimberman authored
View
81 bluepill/README.md
@@ -0,0 +1,81 @@
+Description
+===========
+
+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.
+
+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.
+
+ 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:
+
+ template "/etc/bluepill/my_app" 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 and Author
+==================
+
+Author:: Joshua Timberman (<joshua@opscode.com>)
+
+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.
View
29 bluepill/attributes/default.rb
@@ -0,0 +1,29 @@
+# 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"] = "#{languages[:ruby][:bin_dir]}/bluepill"
+default["bluepill"]["logfile"] = "/var/log/bluepill.log"
+default["bluepill"]["conf_dir"] = "/etc/bluepill"
+default["bluepill"]["pid_dir"] = "/var/run/bluepill"
+default["bluepill"]["state_dir"] = "/var/lib/bluepill"
+
+case platform
+when "arch"
+ default["bluepill"]["init_dir"] = "/etc/rc.d"
+else
+ default["bluepill"]["init_dir"] = "/etc/init.d"
+end
View
30 bluepill/metadata.json
@@ -0,0 +1,30 @@
+{
+ "name": "bluepill",
+ "description": "Installs bluepill gem and configures to manage services, includes bluepill_service LWRP",
+ "long_description": "Description\n===========\n\nInstalls bluepill RubyGem and configures it to manage services. Also includes a LWRP.\n\nRequirements\n============\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\nAttributes\n==========\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\nResources/Providers\n===================\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 service \"my_app\" do\n provider bluepill_service\n action [:enable, :load, :start]\n end\n\n bluepill_service \"my_app\" do\n action [:enable, :load, :start]\n end\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\nUsage\n=====\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 template \"/etc/bluepill/my_app\" do\n source \"my_app.pill.erb\"\n end\n\n Bluepill.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\n end\n\nSee bluepill's documentation for more information on creating pill templates.\n \n\nLicense and Author\n==================\n\nAuthor:: Joshua Timberman (<joshua@opscode.com>)\n\nCopyright 2010, 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",
+ "maintainer": "Opscode, Inc.",
+ "maintainer_email": "cookbooks@opscode.com",
+ "license": "Apache 2.0",
+ "platforms": {
+ },
+ "dependencies": {
+ },
+ "recommendations": {
+ },
+ "suggestions": {
+ },
+ "conflicting": {
+ },
+ "providing": {
+ },
+ "replacing": {
+ },
+ "attributes": {
+ },
+ "groupings": {
+ },
+ "recipes": {
+ "bluepill::default": "Installs bluepill rubygem and set up management directories"
+ },
+ "version": "0.1.0"
+}
View
7 bluepill/metadata.rb
@@ -0,0 +1,7 @@
+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 "0.1.0"
+recipe "bluepill::default", "Installs bluepill rubygem and set up management directories"
View
88 bluepill/providers/service.rb
@@ -0,0 +1,88 @@
+#
+# Cookbook Name:: bluepill
+# Provider:: 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.
+#
+
+require 'chef/mixin/command'
+require 'chef/mixin/language'
+include Chef::Mixin::Command
+
+action :enable do
+ unless @bp.enabled
+ link "#{node['bluepill']['init_dir']}/#{new_resource.service_name}" do
+ to node['bluepill']['bin']
+ only_if { ::File.exists?("#{node['bluepill']['conf_dir']}/#{new_resource.service_name}.pill") }
+ end
+ end
+end
+
+action :load do
+ unless @bp.running
+ execute "#{node['bluepill']['bin']} load #{node['bluepill']['conf_dir']}/#{new_resource.service_name}.pill"
+ end
+end
+
+action :start do
+ unless @bp.running
+ execute "#{node['bluepill']['bin']} start #{new_resource.service_name}"
+ end
+end
+
+action :disable do
+ if @bp.enabled
+ 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
+
+action :stop do
+ if @bp.running
+ execute "#{node['bluepill']['bin']} stop #{new_resource.service_name}"
+ end
+end
+
+action :restart do
+ if @bp.running
+ execute "#{node['bluepill']['bin']} restart #{new_resource.service_name}"
+ end
+end
+
+def load_current_resource
+ @bp = Chef::Resource::BluepillService.new(new_resource.name)
+ @bp.service_name(new_resource.service_name)
+
+ Chef::Log.debug("Checking status of service #{new_resource.service_name}")
+
+ begin
+ if run_command_with_systems_locale(:command => "#{node['bluepill']['bin']} status #{new_resource.service_name}") == 0
+ @bp.running(true)
+ end
+ rescue Chef::Exceptions::Exec
+ @bp.running(false)
+ nil
+ end
+
+ if ::File.exists?("#{node['bluepill']['conf_dir']}/#{new_resource.service_name}.pill") && ::File.symlink?("#{node['bluepill']['init_dir']}/#{new_resource.service_name}")
+ @bp.enabled(true)
+ else
+ @bp.enabled(false)
+ end
+end
View
31 bluepill/recipes/default.rb
@@ -0,0 +1,31 @@
+#
+# 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 "bluepill"
+
+[
+ node["bluepill"]["conf_dir"],
+ node["bluepill"]["pid_dir"],
+ node["bluepill"]["state_dir"]
+].each do |dir|
+ directory dir do
+ owner "root"
+ group "root"
+ end
+end
View
26 bluepill/resources/service.rb
@@ -0,0 +1,26 @@
+#
+# 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
+
+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 }
Please sign in to comment.
Something went wrong with that request. Please try again.