From 10a4ba010272799bf243c0e9103cde042f8c28d7 Mon Sep 17 00:00:00 2001 From: David Golden Date: Thu, 19 Jan 2012 21:11:44 -0500 Subject: [PATCH] first attempt at perlbrew_service --- cookbooks/perlbrew/providers/service.rb | 46 +++++++++++++++++++ cookbooks/perlbrew/resources/service.rb | 33 +++++++++++++ .../default/sv-perlbrew-service-run.erb | 6 +++ 3 files changed, 85 insertions(+) create mode 100644 cookbooks/perlbrew/providers/service.rb create mode 100644 cookbooks/perlbrew/resources/service.rb create mode 100644 cookbooks/perlbrew/templates/default/sv-perlbrew-service-run.erb diff --git a/cookbooks/perlbrew/providers/service.rb b/cookbooks/perlbrew/providers/service.rb new file mode 100644 index 0000000..b7082a6 --- /dev/null +++ b/cookbooks/perlbrew/providers/service.rb @@ -0,0 +1,46 @@ +# +# Author:: David A. Golden +# Cookbook Name:: perlbrew +# Provider:: perlbrew_service +# +# Copyright:: 2012, David A. Golden +# +# 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 + +include_recipe "runit" + +# XXX must be a fully qualified 'perl-5.X.Y@libname' style name +action :create do + perlbrew_env = { + 'PERLBREW_ROOT' => node['perlbrew']['perlbrew_root'], + 'PERLBREW_HOME' => node['perlbrew']['perlbrew_root'] + } + + runit_service new_resource.name do + template_name 'perlbrew-service' + cookbook 'perlbrew' + options( + :perlbrew_root => node['perlbrew']['perlbrew_root'], + :resource => new_resource + ) + env new_resource.environment.merge(perlbrew_env) + run_restart false + end +end + +# :enable :disable :nothing :start :stop :restart :reload} diff --git a/cookbooks/perlbrew/resources/service.rb b/cookbooks/perlbrew/resources/service.rb new file mode 100644 index 0000000..5b7a0d4 --- /dev/null +++ b/cookbooks/perlbrew/resources/service.rb @@ -0,0 +1,33 @@ +# +# Author:: David A. Golden +# Cookbook Name:: perlbrew +# Resource:: perlbrew_service +# +# Copyright:: 2012, David A. Golden +# +# 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 :create + +def initialize(*args) + super + @action = :create +end + +attribute :perlbrew, :kind_of => String, :required => true +attribute :command, :kind_of => String, :required => true +attribute :user, :kind_of => String, :default => "nobody" +attribute :group, :kind_of => String, :default => "nobody" +attribute :cwd, :kind_of => String, :default "/" +attribute :environment, :kind_of => Hash, :default => {} diff --git a/cookbooks/perlbrew/templates/default/sv-perlbrew-service-run.erb b/cookbooks/perlbrew/templates/default/sv-perlbrew-service-run.erb new file mode 100644 index 0000000..8075aaa --- /dev/null +++ b/cookbooks/perlbrew/templates/default/sv-perlbrew-service-run.erb @@ -0,0 +1,6 @@ +#!/bin/bash +source <%= @options[:perlbrew_root] %>/etc/bashrc +cd <%= @options[:resource].cwd %> +perlbrew use <%= @options[:resource].perlbrew %> +exec chpst -u <%= @options[:resource].user %>:<%= @options[:resource].group %> <%= @options[:resource].command %> +