Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Import runit version 0.15.0

  • Loading branch information...
commit f6e430ecd434bbc1f38f774be7067809d10a6172 1 parent a8ecd76
@phunehehe authored
View
3  runit/CHANGELOG.md
@@ -0,0 +1,3 @@
+## v0.15.0:
+
+* [COOK-1008] - Added parameters for names of different templates in runit
View
29 runit/CONTRIBUTING
@@ -0,0 +1,29 @@
+If you would like to contribute, please open a ticket in JIRA:
+
+* http://tickets.opscode.com
+
+Create the ticket in the COOK project and use the cookbook name as the
+component.
+
+For all code contributions, we ask that contributors sign a
+contributor license agreement (CLA). Instructions may be found here:
+
+* http://wiki.opscode.com/display/chef/How+to+Contribute
+
+When contributing changes to individual cookbooks, please do not
+modify the version number in the metadata.rb. Also please do not
+update the CHANGELOG.md for a new version. Not all changes to a
+cookbook may be merged and released in the same versions. Opscode will
+handle the version updates during the release process. You are welcome
+to correct typos or otherwise make updates documentation in the
+README.
+
+If a contribution adds new platforms or platform versions, indicate
+such in the body of the commit message(s), and update the relevant
+COOK ticket. When writing commit messages, it is helpful for others if
+you indicate the COOK ticket. For example:
+
+ git commit -m '[COOK-1041] Updated pool resource to correctly delete.'
+
+In the ticket itself, it is also helpful if you include log output of
+a successful Chef run, but this is not absolutely required.
View
201 runit/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+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
226 runit/README.md
@@ -0,0 +1,226 @@
+Description
+===========
+
+Installs runit and provides `runit_service` definition for managing new
+services under runit.
+
+This cookbook does not use runit to replace system init, nor are there
+plans to do so.
+
+For more information about runit:
+
+* http://smarden.org/runit/
+
+Requirements
+============
+
+## Platform:
+
+* Debian/Ubuntu
+* Gentoo
+
+Attributes
+==========
+
+See `attributes/default.rb` for defaults.
+
+* `node['runit']['sv_bin']` - Full path to the `sv` binary.
+* `node['runit']['chpst_bin']` - Full path to the `chpst` binary.
+* `node['runit']['service_dir']` - Full path to the default "services"
+ directory where enabled services are linked.
+* `node['runit']['sv_dir']` - Full path to the directory where the
+ service lives, which gets linked to `service_dir`.
+
+Recipes
+=======
+
+default
+-------
+
+Installs and sets up runit on the system. Assumes a package
+installation, so native package must exist. This recipe will make sure
+that the runsvdir process gets started, ensures that inittab is
+updated with the SV entry. The package will be preseeded on
+ubuntu/debian signal init, otherwise the appropriate action is chosen
+to notify the runsvdir command.
+
+Older versions of Ubuntu (<= 10.04) are supported, but support may be
+removed in a future version.
+
+Definitions
+===========
+
+The definition in this cookbook will be deprecated by an LWRP in a
+future version. See __Roadmap__.
+
+runit\_service
+--------------
+
+This definition includes `recipe[runit]` to ensure it is installed
+first. As LWRPs cannot use `include_recipe`, this will not be
+available in future versions, so runit will need to be in a role or
+node run list.
+
+Sets up a new service to be managed and supervised by runit. It will
+be created in the `node['runit']['sv_dir']` unless otherwise specified
+in the `directory` parameter (see below).
+
+### Parameters:
+
+* `name` - Name of the service. This will be used in the template file
+ names (see __Usage__), as well as the name of the service resource
+ created in the definition.
+* `directory` - the directory where the service's configuration and
+ scripts should be located. Default is `node['runit']['sv_dir']`.
+* `only_if` - unused, will be removed in a future version (won't be
+ present in lwrp). Default is false.
+* `finish_script` - if true, a finish script should be created.
+ Default is false. For more information see: [Description of runsv](http://smarden.org/runit/runsv.8.html).
+* `control` - Array of signals to create a control directory with
+ control scripts (e.g., `sv-SERVICE-control-SIGNAL.erb`, where
+ SERVICE is the name parameter for the service name, and SIGNAL is
+ the Unix signal to send. Default is an empty array. For more
+ information see:
+ [Customize Control](http://smarden.org/runit/runsv.8.html)
+* `run_restart` - if true, the service resource will subscribe to
+ changes to the run script and restart itself when it is modified.
+ Default is true.
+* `active_directory` - used for user-specific services. Default is
+ `node['runit']['service_dir']`.
+* `owner` - userid of the owner for the service's files, and should be
+ used in the run template with chpst to ensure the service runs as
+ that user. Default is root.
+* `group` - groupid of the group for the service's files, and should
+ be used in the run template with chpst to ensure the service runs as
+ that group. Default is root.
+* `template_name` - specify an alternate name for the templates
+ instead of basing them on the name parameter. Default is the name parameter.
+* `log_template_name` - specify an alternate name for the runit log template
+ instead of basing them on the template_name parameter. Default is the
+ template_name parameter.
+* `control_template_names` - specify alternate names for runit control signal
+ templates instead of basing them on the template_name parameter. Default
+ is the template_name parameter.
+* `finish_script_template_name` - specify an altername for the finish script
+ template. Default is the template_name parameter
+* `start_command` - The command used to start the service in
+ conjunction with the `sv` command and the `service_dir` name.
+ Default is `start`.
+* `stop_command` - The command used to stop the service in conjunction
+ with the `sv` command and the `service_dir` name. Default is `stop`.
+* `restart_command` - The command used to restart the service in
+ conjunction with the `sv` command and the `service_dir` name. You
+ may need to modify this to send an alternate signal to restart the
+ service depending on the nature of the process. Default is `restart`
+* `status_command` - The command used to check status for the service in
+ conjunction with the `sv` command and the `service_dir` name. This
+ is used by chef when checking the current resource state in managing
+ the service. Default is `status`.
+* `options` - a Hash of variables to pass into the run and log/run
+ templates with the template resource `variables` parameter.
+ Available inside the template(s) as `@options`. Default is an empty Hash.
+* `env` -
+
+### Examples:
+
+Create templates for `sv-myservice-run.erb` and
+`sv-myservice-log-run.erb` that have the commands for starting
+myservice and its logger.
+
+ runit_service "myservice"
+
+See __Usage__ for expanded examples.
+
+Resources/Providers
+===================
+
+None yet. See __Roadmap__.
+
+Usage
+=====
+
+To get runit installed on supported platforms, use `recipe[runit]`.
+Once it is installed, use the `runit_service` definition to set up
+services to be managed by runit. Do note that once
+[CHEF-154](http://tickets.opscode.com/browse/CHEF-154) is implemented,
+some of the usage/implementation here will change. In order to use the
+`runit_service` definition, two templates must be created for the
+service, `cookbook_name/templates/default/sv-SERVICE-run.erb` and
+`cookbook_name/templates/default/sv-SERVICE-log-run.erb`. Replace
+`SERVICE` with the name of the service you're managing. For more usage,
+see __Examples__.
+
+Examples
+--------
+
+We'll set up `chef-client` to run as a service under runit, such as is
+done in the `chef-client` cookbook. This example will be more simple
+than in that cookbook. First, create the required run template,
+`chef-client/templates/default/sv-chef-client-run.erb`.
+
+ #!/bin/sh
+ exec 2>&1
+ exec /usr/bin/env chef-client -i 1800 -s 30
+
+Then create the required log/run template,
+`chef-client/templates/default/sv-chef-client-run.erb`.
+
+ #!/bin/sh
+ exec svlogd -tt ./main
+
+__Note__ This will cause output of the running process to go to
+`/etc/sv/chef-client/log/main/current`.
+
+Finally, set up the service in the `chef-client` recipe with:
+
+ runit_service "chef-client"
+
+Next, let's set up memcached with some additional options. First, the
+`memcached/templates/default/sv-memcached-run.erb` template:
+
+ #!/bin/sh
+ exec 2>&1
+ exec chpst -u <%= @options[:user] %> /usr/bin/memcached -v -m <%= @options[:memory] %> -p <%= @options[:port] %>
+
+Note that the script uses chpst (which comes with runit) to set the
+user option, then starts memcached on the specified memory and port
+(see below).
+
+The log/run template,
+`memcached/templates/default/sv-memcached-log-run.erb`:
+
+ #!/bin/sh
+ exec svlogd -tt ./main
+
+Finally, the `runit_service` in our recipe:
+
+ runit_service "memcached" do
+ options({
+ :memory => node[:memcached][:memory],
+ :port => node[:memcached][:port],
+ :user => node[:memcached][:user]}.merge(params)
+ )
+ end
+
+This is where the user, port and memory options used in the run
+template are used.
+
+License and Author
+==================
+
+Author:: Adam Jacob <adam@opscode.com>
+Author:: Joshua Timberman <joshua@opscode.com>
+
+Copyright:: 2008-2011, 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
31 runit/attributes/default.rb
@@ -0,0 +1,31 @@
+#
+# Cookbook Name:: runit
+# Attribute File:: sv_bin
+#
+# Copyright 2008-2009, 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.
+#
+
+case platform
+when "ubuntu","debian"
+ set[:runit][:sv_bin] = "/usr/bin/sv"
+ set[:runit][:chpst_bin] = "/usr/bin/chpst"
+ set[:runit][:service_dir] = "/etc/service"
+ set[:runit][:sv_dir] = "/etc/sv"
+when "gentoo"
+ set[:runit][:sv_bin] = "/usr/bin/sv"
+ set[:runit][:chpst_bin] = "/usr/bin/chpst"
+ set[:runit][:service_dir] = "/etc/service"
+ set[:runit][:sv_dir] = "/var/service"
+end
View
164 runit/definitions/runit_service.rb
@@ -0,0 +1,164 @@
+#
+# Cookbook Name:: runit
+# Definition:: runit_service
+#
+# Copyright 2008-2009, 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.
+#
+
+define :runit_service, :directory => nil, :only_if => false, :finish_script => false, :control => [], :run_restart => true, :active_directory => nil, :owner => "root", :group => "root", :template_name => nil, :log_template_name => nil, :control_template_names => {}, :finish_script_template_name => nil, :start_command => "start", :stop_command => "stop", :restart_command => "restart", :status_command => "status", :options => Hash.new, :env => Hash.new do
+ include_recipe "runit"
+
+ params[:directory] ||= node[:runit][:sv_dir]
+ params[:active_directory] ||= node[:runit][:service_dir]
+ params[:template_name] ||= params[:name]
+ params[:log_template_name] ||= params[:template_name]
+ params[:control].each do |signal|
+ params[:control_template_names][signal] ||= params[:template_name]
+ end
+ params[:finish_script_template_name] ||= params[:template_name]
+
+ sv_dir_name = "#{params[:directory]}/#{params[:name]}"
+ service_dir_name = "#{params[:active_directory]}/#{params[:name]}"
+ params[:options].merge!(:env_dir => "#{sv_dir_name}/env") unless params[:env].empty?
+
+ directory sv_dir_name do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ action :create
+ end
+
+ directory "#{sv_dir_name}/log" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ action :create
+ end
+
+ directory "#{sv_dir_name}/log/main" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ action :create
+ end
+
+ template "#{sv_dir_name}/run" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ source "sv-#{params[:template_name]}-run.erb"
+ cookbook params[:cookbook] if params[:cookbook]
+ if params[:options].respond_to?(:has_key?)
+ variables :options => params[:options]
+ end
+ end
+
+ template "#{sv_dir_name}/log/run" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ source "sv-#{params[:log_template_name]}-log-run.erb"
+ cookbook params[:cookbook] if params[:cookbook]
+ if params[:options].respond_to?(:has_key?)
+ variables :options => params[:options]
+ end
+ end
+
+ unless params[:env].empty?
+ directory "#{sv_dir_name}/env" do
+ mode 0755
+ action :create
+ end
+
+ params[:env].each do |var, value|
+ file "#{sv_dir_name}/env/#{var}" do
+ content value
+ end
+ end
+ end
+
+ if params[:finish_script]
+ template "#{sv_dir_name}/finish" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ source "sv-#{params[:finish_script_template_name]}-finish.erb"
+ cookbook params[:cookbook] if params[:cookbook]
+ if params[:options].respond_to?(:has_key?)
+ variables :options => params[:options]
+ end
+ end
+ end
+
+ unless params[:control].empty?
+ directory "#{sv_dir_name}/control" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ action :create
+ end
+
+ params[:control].each do |signal|
+ template "#{sv_dir_name}/control/#{signal}" do
+ owner params[:owner]
+ group params[:group]
+ mode 0755
+ source "sv-#{params[:control_template_names][signal]}-control-#{signal}.erb"
+ cookbook params[:cookbook] if params[:cookbook]
+ if params[:options].respond_to?(:has_key?)
+ variables :options => params[:options]
+ end
+ end
+ end
+ end
+
+ if params[:active_directory] == node[:runit][:service_dir]
+ link "/etc/init.d/#{params[:name]}" do
+ to node[:runit][:sv_bin]
+ end
+ end
+
+ unless node[:platform] == "gentoo"
+ link service_dir_name do
+ to sv_dir_name
+ end
+ end
+
+ ruby_block "supervise_#{params[:name]}_sleep" do
+ block do
+ Chef::Log.debug("Waiting until named pipe #{sv_dir_name}/supervise/ok exists.")
+ (1..10).each {|i| sleep 1 unless ::FileTest.pipe?("#{sv_dir_name}/supervise/ok") }
+ end
+ not_if { FileTest.pipe?("#{sv_dir_name}/supervise/ok") }
+ end
+
+ service params[:name] do
+ control_cmd = node[:runit][:sv_bin]
+ if params[:owner]
+ control_cmd = "#{node[:runit][:chpst_bin]} -u #{params[:owner]} #{control_cmd}"
+ end
+ provider Chef::Provider::Service::Init
+ supports :restart => true, :status => true
+ start_command "#{control_cmd} #{params[:start_command]} #{service_dir_name}"
+ stop_command "#{control_cmd} #{params[:stop_command]} #{service_dir_name}"
+ restart_command "#{control_cmd} #{params[:restart_command]} #{service_dir_name}"
+ status_command "#{control_cmd} #{params[:status_command]} #{service_dir_name}"
+ if params[:run_restart]
+ subscribes :restart, resources(:template => "#{sv_dir_name}/run"), :delayed
+ end
+ action :nothing
+ end
+
+end
View
1  runit/files/default/runit.seed
@@ -0,0 +1 @@
+runit runit/signalinit boolean true
View
0  runit/files/default/runsvdir
No changes.
View
6 runit/files/ubuntu-6.10/runsvdir
@@ -0,0 +1,6 @@
+start on runlevel-2
+start on runlevel-3
+start on runlevel-4
+start on runlevel-5
+stop on shutdown
+respawn /usr/sbin/runsvdir-start
View
7 runit/files/ubuntu-7.04/runsvdir
@@ -0,0 +1,7 @@
+start on runlevel 2
+start on runlevel 3
+start on runlevel 4
+start on runlevel 5
+stop on shutdown
+respawn
+exec /usr/sbin/runsvdir-start
View
7 runit/files/ubuntu-7.10/runsvdir
@@ -0,0 +1,7 @@
+start on runlevel 2
+start on runlevel 3
+start on runlevel 4
+start on runlevel 5
+stop on shutdown
+respawn
+exec /usr/sbin/runsvdir-start
View
7 runit/files/ubuntu-8.04/runsvdir
@@ -0,0 +1,7 @@
+start on runlevel 2
+start on runlevel 3
+start on runlevel 4
+start on runlevel 5
+stop on shutdown
+respawn
+exec /usr/sbin/runsvdir-start
View
102 runit/metadata.json
@@ -0,0 +1,102 @@
+{
+ "name": "runit",
+ "description": "Installs runit and provides runit_service definition",
+ "long_description": "",
+ "maintainer": "Opscode, Inc.",
+ "maintainer_email": "cookbooks@opscode.com",
+ "license": "Apache 2.0",
+ "platforms": {
+ "ubuntu": ">= 0.0.0",
+ "debian": ">= 0.0.0",
+ "gentoo": ">= 0.0.0"
+ },
+ "dependencies": {
+ },
+ "recommendations": {
+ },
+ "suggestions": {
+ },
+ "conflicting": {
+ },
+ "providing": {
+ },
+ "replacing": {
+ },
+ "attributes": {
+ "runit": {
+ "display_name": "Runit",
+ "description": "Hash of runit attributes",
+ "type": "hash",
+ "choice": [
+
+ ],
+ "calculated": false,
+ "required": "optional",
+ "recipes": [
+
+ ]
+ },
+ "runit/sv_bin": {
+ "display_name": "Runit sv bin",
+ "description": "Location of the sv binary",
+ "default": "/usr/bin/sv",
+ "choice": [
+
+ ],
+ "calculated": false,
+ "type": "string",
+ "required": "optional",
+ "recipes": [
+
+ ]
+ },
+ "runit/chpst_bin": {
+ "display_name": "Runit chpst bin",
+ "description": "Location of the chpst binary",
+ "default": "/usr/bin/chpst",
+ "choice": [
+
+ ],
+ "calculated": false,
+ "type": "string",
+ "required": "optional",
+ "recipes": [
+
+ ]
+ },
+ "runit/service_dir": {
+ "display_name": "Runit service directory",
+ "description": "Symlinks to services managed under runit",
+ "default": "/etc/service",
+ "choice": [
+
+ ],
+ "calculated": false,
+ "type": "string",
+ "required": "optional",
+ "recipes": [
+
+ ]
+ },
+ "runit/sv_dir": {
+ "display_name": "Runit sv directory",
+ "description": "Location of services managed by runit",
+ "default": "/etc/sv",
+ "choice": [
+
+ ],
+ "calculated": false,
+ "type": "string",
+ "required": "optional",
+ "recipes": [
+
+ ]
+ }
+ },
+ "groupings": {
+ },
+ "recipes": {
+ "runit": "Installs and configures runit"
+ },
+ "version": "0.15.0"
+}
View
37 runit/metadata.rb
@@ -0,0 +1,37 @@
+maintainer "Opscode, Inc."
+maintainer_email "cookbooks@opscode.com"
+license "Apache 2.0"
+description "Installs runit and provides runit_service definition"
+version "0.15.0"
+
+recipe "runit", "Installs and configures runit"
+
+%w{ ubuntu debian gentoo }.each do |os|
+ supports os
+end
+
+attribute "runit",
+ :display_name => "Runit",
+ :description => "Hash of runit attributes",
+ :type => "hash"
+
+attribute "runit/sv_bin",
+ :display_name => "Runit sv bin",
+ :description => "Location of the sv binary",
+ :default => "/usr/bin/sv"
+
+attribute "runit/chpst_bin",
+ :display_name => "Runit chpst bin",
+ :description => "Location of the chpst binary",
+ :default => "/usr/bin/chpst"
+
+attribute "runit/service_dir",
+ :display_name => "Runit service directory",
+ :description => "Symlinks to services managed under runit",
+ :default => "/etc/service"
+
+attribute "runit/sv_dir",
+ :display_name => "Runit sv directory",
+ :description => "Location of services managed by runit",
+ :default => "/etc/sv"
+
View
72 runit/recipes/default.rb
@@ -0,0 +1,72 @@
+#
+# Cookbook Name:: runit
+# Recipe:: default
+#
+# Copyright 2008-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.
+#
+
+case node[:platform]
+when "debian","ubuntu", "gentoo"
+ execute "start-runsvdir" do
+ command value_for_platform(
+ "debian" => { "default" => "runsvdir-start" },
+ "ubuntu" => { "default" => "start runsvdir" },
+ "gentoo" => { "default" => "/etc/init.d/runit-start start" }
+ )
+ action :nothing
+ end
+
+ execute "runit-hup-init" do
+ command "telinit q"
+ only_if "grep ^SV /etc/inittab"
+ action :nothing
+ end
+
+ if platform? "gentoo"
+ template "/etc/init.d/runit-start" do
+ source "runit-start.sh.erb"
+ mode 0755
+ end
+ end
+
+ package "runit" do
+ action :install
+ if platform?("ubuntu", "debian")
+ response_file "runit.seed"
+ end
+ notifies value_for_platform(
+ "debian" => { "4.0" => :run, "default" => :nothing },
+ "ubuntu" => {
+ "default" => :nothing,
+ "9.04" => :run,
+ "8.10" => :run,
+ "8.04" => :run },
+ "gentoo" => { "default" => :run }
+ ), resources(:execute => "start-runsvdir"), :immediately
+ notifies value_for_platform(
+ "debian" => { "squeeze/sid" => :run, "default" => :nothing },
+ "default" => :nothing
+ ), resources(:execute => "runit-hup-init"), :immediately
+ end
+
+ if node[:platform] =~ /ubuntu/i && node[:platform_version].to_f <= 8.04
+ cookbook_file "/etc/event.d/runsvdir" do
+ source "runsvdir"
+ mode 0644
+ notifies :run, resources(:execute => "start-runsvdir"), :immediately
+ only_if do ::File.directory?("/etc/event.d") end
+ end
+ end
+end
View
32 runit/templates/gentoo/runit-start.sh.erb
@@ -0,0 +1,32 @@
+#!/sbin/runscript
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+depend() {
+ after net
+}
+
+start() {
+ ebegin "Starting runsvdir"
+ start-stop-daemon --start --exec /usr/bin/runsvdir \
+ --background --make-pidfile \
+ --pidfile /var/run/runsvdir.pid -- <%= node.runit.sv_dir %>
+ eend $?
+}
+
+stop() {
+ local ret1 ret2
+ ebegin "Stopping runsvdir"
+ start-stop-daemon --stop --oknodo --pidfile /var/run/runsvdir.pid
+ ret1=$?
+ eend ${ret1}
+
+ ebegin "Stopping services and logging"
+ sv shutdown -w 10 <%= node.runit.sv_dir %>/*
+ ret2=$?
+ eend ${ret2}
+
+ return $((ret1+ret2))
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.