Skip to content

Commit

Permalink
first attempt at perlbrew_service
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Jan 20, 2012
1 parent 2dc49c9 commit 10a4ba0
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cookbooks/perlbrew/providers/service.rb
@@ -0,0 +1,46 @@
#
# Author:: David A. Golden
# Cookbook Name:: perlbrew
# Provider:: perlbrew_service
#
# Copyright:: 2012, David A. Golden <dagolden@cpan.org>
#
# 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}
33 changes: 33 additions & 0 deletions cookbooks/perlbrew/resources/service.rb
@@ -0,0 +1,33 @@
#
# Author:: David A. Golden
# Cookbook Name:: perlbrew
# Resource:: perlbrew_service
#
# Copyright:: 2012, David A. Golden <dagolden@cpan.org>
#
# 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 => {}
@@ -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 %>

0 comments on commit 10a4ba0

Please sign in to comment.