Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[COOK-304] runit: support for user-specific services

- Also resolve merge conflicts from COOK-329 (jtimberman)
  • Loading branch information...
commit c6a011442f6322b602e6c1426cf54af8d7af71db 1 parent bf61e22
@akzhan akzhan authored jtimberman committed
View
1  attributes/default.rb
@@ -20,6 +20,7 @@
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"
end
View
44 definitions/runit_service.rb
@@ -17,30 +17,40 @@
# limitations under the License.
#
-define :runit_service, :directory => nil, :only_if => false, :finish_script => false, :control => [], :run_restart => true, :start_command => "start", :stop_command => "stop", :restart_command => "restart", :status_command => "status", :options => Hash.new do
+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, :start_command => "start", :stop_command => "stop", :restart_command => "restart", :status_command => "status", :options => Hash.new do
include_recipe "runit"
params[:directory] ||= node[:runit][:sv_dir]
+ params[:active_directory] ||= node[:runit][:service_dir]
+ params[:template_name] ||= params[:name]
sv_dir_name = "#{params[:directory]}/#{params[:name]}"
+ service_dir_name = "#{params[:active_directory]}/#{params[:name]}"
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
- params[:template_name] ||= params[:name]
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]
@@ -50,6 +60,8 @@
end
template "#{sv_dir_name}/log/run" do
+ owner params[:owner]
+ group params[:group]
mode 0755
source "sv-#{params[:template_name]}-log-run.erb"
cookbook params[:cookbook] if params[:cookbook]
@@ -60,6 +72,8 @@
if params[:finish_script]
template "#{sv_dir_name}/finish" do
+ owner params[:owner]
+ group params[:group]
mode 0755
source "sv-#{params[:template_name]}-finish.erb"
cookbook params[:cookbook] if params[:cookbook]
@@ -71,12 +85,16 @@
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[:template_name]}-control-#{signal}.erb"
cookbook params[:cookbook] if params[:cookbook]
@@ -87,12 +105,14 @@
end
end
- link "/etc/init.d/#{params[:name]}" do
- to node[:runit][:sv_bin]
+ if params[:active_directory] == node[:runit][:service_dir]
+ link "/etc/init.d/#{params[:name]}" do
+ to node[:runit][:sv_bin]
+ end
end
- link "#{node[:runit][:service_dir]}/#{params[:name]}" do
- to "#{sv_dir_name}"
+ link service_dir_name do
+ to sv_dir_name
end
ruby_block "supervise_#{params[:name]}_sleep" do
@@ -104,12 +124,16 @@
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 "#{node[:runit][:sv_bin]} #{params[:start_command]} #{params[:name]}"
- stop_command "#{node[:runit][:sv_bin]} #{params[:stop_command]} #{params[:name]}"
- restart_command "#{node[:runit][:sv_bin]} #{params[:restart_command]} #{params[:name]}"
- status_command "#{node[:runit][:sv_bin]} #{params[:status_command]} #{params[:name]}"
+ 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
View
170 metadata.json
@@ -1,91 +1,105 @@
{
- "recommendations": {
- },
- "attributes": {
- "runit/sv_dir": {
- "required": "optional",
- "calculated": false,
- "choice": [
+ "conflicting": {
+ },
+ "description": "Installs runit and provides runit_service definition",
+ "providing": {
+ },
+ "maintainer": "Opscode, Inc.",
+ "attributes": {
+ "runit/sv_dir": {
+ "required": "optional",
+ "calculated": false,
+ "choice": [
- ],
- "default": "/etc/sv",
- "type": "string",
- "recipes": [
+ ],
+ "default": "/etc/sv",
+ "type": "string",
+ "recipes": [
- ],
- "description": "Location of services managed by runit",
- "display_name": "Runit sv directory"
- },
- "runit/service_dir": {
- "required": "optional",
- "calculated": false,
- "choice": [
+ ],
+ "display_name": "Runit sv directory",
+ "description": "Location of services managed by runit"
+ },
+ "runit/service_dir": {
+ "required": "optional",
+ "calculated": false,
+ "choice": [
- ],
- "default": "/etc/service",
- "type": "string",
- "recipes": [
+ ],
+ "default": "/etc/service",
+ "type": "string",
+ "recipes": [
- ],
- "description": "Symlinks to services managed under runit",
- "display_name": "Runit service directory"
- },
- "runit": {
- "required": "optional",
- "calculated": false,
- "choice": [
+ ],
+ "display_name": "Runit service directory",
+ "description": "Symlinks to services managed under runit"
+ },
+ "runit": {
+ "required": "optional",
+ "calculated": false,
+ "choice": [
- ],
- "type": "hash",
- "recipes": [
+ ],
+ "type": "hash",
+ "recipes": [
- ],
- "description": "Hash of runit attributes",
- "display_name": "Runit"
- },
- "runit/sv_bin": {
- "required": "optional",
- "calculated": false,
- "choice": [
+ ],
+ "display_name": "Runit",
+ "description": "Hash of runit attributes"
+ },
+ "runit/sv_bin": {
+ "required": "optional",
+ "calculated": false,
+ "choice": [
- ],
- "default": "/usr/bin/sv",
- "type": "string",
- "recipes": [
+ ],
+ "default": "/usr/bin/sv",
+ "type": "string",
+ "recipes": [
- ],
- "description": "Location of the sv binary",
- "display_name": "Runit sv bin"
- }
- },
- "maintainer": "Opscode, Inc.",
- "suggestions": {
- },
- "dependencies": {
- },
- "maintainer_email": "cookbooks@opscode.com",
- "conflicting": {
+ ],
+ "display_name": "Runit sv bin",
+ "description": "Location of the sv binary"
},
- "platforms": {
- "debian": [
+ "runit/chpst_bin": {
+ "required": "optional",
+ "calculated": false,
+ "choice": [
],
- "ubuntu": [
+ "default": "/usr/bin/chpst",
+ "type": "string",
+ "recipes": [
- ]
- },
- "license": "Apache 2.0",
- "version": "0.13.0",
- "providing": {
- },
- "recipes": {
- "runit": "Installs and configures runit"
- },
- "replacing": {
- },
- "name": "runit",
- "description": "Installs runit and provides runit_service definition",
- "groupings": {
- },
- "long_description": ""
- }
+ ],
+ "display_name": "Runit chpst bin",
+ "description": "Location of the chpst binary"
+ }
+ },
+ "replacing": {
+ },
+ "dependencies": {
+ },
+ "maintainer_email": "cookbooks@opscode.com",
+ "groupings": {
+ },
+ "recommendations": {
+ },
+ "platforms": {
+ "debian": [
+
+ ],
+ "ubuntu": [
+
+ ]
+ },
+ "name": "runit",
+ "version": "0.13.0",
+ "recipes": {
+ "runit": "Installs and configures runit"
+ },
+ "license": "Apache 2.0",
+ "suggestions": {
+ },
+ "long_description": ""
+}
View
5 metadata.rb
@@ -20,6 +20,11 @@
: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",
Please sign in to comment.
Something went wrong with that request. Please try again.