Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first attempt at perlbrew_service

  • Loading branch information...
commit 10a4ba010272799bf243c0e9103cde042f8c28d7 1 parent 2dc49c9
@dagolden authored
View
46 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}
View
33 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 => {}
View
6 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 %>
+
Please sign in to comment.
Something went wrong with that request. Please try again.