From 5ad4bd279420debf8d732409388e8acd0b355e9f Mon Sep 17 00:00:00 2001 From: whitestar Date: Thu, 5 Nov 2015 19:26:04 +0900 Subject: [PATCH] add crond and httpd recipes to the commons cookbook. --- cookbooks/commons/README.md | 8 ++++++- cookbooks/commons/libraries/package_utils.rb | 16 ++++++++++++++ cookbooks/commons/metadata.rb | 2 +- cookbooks/commons/recipes/crond.rb | 32 ++++++++++++++++++++++++++++ cookbooks/commons/recipes/httpd.rb | 32 ++++++++++++++++++++++++++++ roles/chef-client.rb | 3 ++- 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 cookbooks/commons/recipes/crond.rb create mode 100644 cookbooks/commons/recipes/httpd.rb diff --git a/cookbooks/commons/README.md b/cookbooks/commons/README.md index be6cd70..2c92364 100644 --- a/cookbooks/commons/README.md +++ b/cookbooks/commons/README.md @@ -6,7 +6,7 @@ This cookbook contains common utility libraries. Requirements ------------ -Nothing. +- OS: Debian family or Red Hat Enterprise Linux family. Attributes ---------- @@ -17,10 +17,16 @@ Usage ----- #### libraries - `Commons::PackageUtils::get_cron_pkg_name` +- `Commons::PackageUtils::get_cron_serv_name` - `Commons::PackageUtils::get_httpd_pkg_name` +- `Commons::PackageUtils::get_httpd_serv_name` - `Commons::PackageUtils::get_jsvc_pkg_name` - `Commons::PackageUtils::get_libbz2_pkg_name` +#### recipes +- `commons::crond` - installs cron package and enables & starts the service. +- `commons::httpd` - installs httpd package and enables & starts the service. + License and Authors ------------------- - Author:: whitestar at osdn.jp diff --git a/cookbooks/commons/libraries/package_utils.rb b/cookbooks/commons/libraries/package_utils.rb index d9b6088..e42b4ab 100644 --- a/cookbooks/commons/libraries/package_utils.rb +++ b/cookbooks/commons/libraries/package_utils.rb @@ -27,6 +27,14 @@ module Commons end + def get_cron_serv_name + case node[:platform_family] + when 'debian'then return 'cron' + when 'rhel' then return 'crond' + end + end + + def get_httpd_pkg_name case node[:platform_family] when 'debian'then return 'apache2' @@ -35,6 +43,14 @@ module Commons end + def get_httpd_serv_name + case node[:platform_family] + when 'debian'then return 'apache2' + when 'rhel' then return 'httpd' + end + end + + def get_jsvc_pkg_name case node[:platform_family] when 'debian' then return 'jsvc' diff --git a/cookbooks/commons/metadata.rb b/cookbooks/commons/metadata.rb index ef28cd9..bdabdfe 100644 --- a/cookbooks/commons/metadata.rb +++ b/cookbooks/commons/metadata.rb @@ -4,4 +4,4 @@ maintainer_email '' license 'Apache 2.0' description 'Installs/Configures commons' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.0' +version '0.2.0' diff --git a/cookbooks/commons/recipes/crond.rb b/cookbooks/commons/recipes/crond.rb new file mode 100644 index 0000000..c160e69 --- /dev/null +++ b/cookbooks/commons/recipes/crond.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: commons +# Recipe:: crond +# +# Copyright 2015, whitestar +# +# 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. +# + +::Chef::Recipe.send(:include, Commons::PackageUtils) + +pkg = get_cron_pkg_name +resources(:package => pkg) rescue package pkg do + action :install +end + +serv = get_cron_serv_name +resources(:service => serv) rescue service serv do + action [:enable, :start] + supports :status => true, :restart => true, :reload => false +end + diff --git a/cookbooks/commons/recipes/httpd.rb b/cookbooks/commons/recipes/httpd.rb new file mode 100644 index 0000000..413f533 --- /dev/null +++ b/cookbooks/commons/recipes/httpd.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: commons +# Recipe:: httpd +# +# Copyright 2015, whitestar +# +# 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. +# + +::Chef::Recipe.send(:include, Commons::PackageUtils) + +pkg = get_httpd_pkg_name +resources(:package => pkg) rescue package pkg do + action :install +end + +serv = get_httpd_serv_name +resources(:service => serv) rescue service serv do + action [:enable, :start] + supports :status => true, :restart => true, :reload => false +end + diff --git a/roles/chef-client.rb b/roles/chef-client.rb index f4af85c..89390f5 100644 --- a/roles/chef-client.rb +++ b/roles/chef-client.rb @@ -18,7 +18,8 @@ name 'chef-client' description 'Chef Client' run_list( - 'recipe[chef-client::cron]' + 'recipe[commons::crond]', + 'recipe[chef-client::cron]', ) #env_run_lists() -- 2.11.0