Skip to content

Commit

Permalink
Merge pull request #4 from bossato/feature/update_version
Browse files Browse the repository at this point in the history
Feature/update version
  • Loading branch information
bossato committed Apr 3, 2014
2 parents beba949 + f0852cb commit f0cbc5e
Show file tree
Hide file tree
Showing 25 changed files with 1,071 additions and 458 deletions.
118 changes: 117 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,118 @@
chef
====
============

RubyとChefのインストール
--

ライブラリインストール

```
$ yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libffi-devel openssl-devel git vim tmux
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz
$ tar xvzf yaml-0.1.5.tar.gz
$ cd yaml-0.1.5
$ ./configure
$ make
$ make install
$ whereis libyaml
libyaml: /usr/local/lib/libyaml.la /usr/local/lib/libyaml.a /usr/local/lib/libyaml.so
```

Ruby1.9インストール

```
$ wget http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p545.tar.gz
$ tar xvzf ruby-1.9.3-p545.tar.gz
$ cd ruby-1.9.3-p545
$ ./configure --with-opt-dir=/usr/lib --disable-install-doc
$ make
$ make install
$ ruby -v
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]
```

Chefインストール

```
$ gem install rdoc
$ gem install chef
$ gem install knife-solo
$ chef-solo -v
Chef: 11.10.4
```

knife設定
--

knifeコマンドの初期設定を行う。

```
$ knife configure
// この後は基本Enterを押せばOK
```

solo.rb作成
--

chef-soloコマンドの設定ファイルでリポジトリ直下に作成する。各パスは適時書き換える。

```
$ cat solo.rb
file_cache_path "/tmp/chef-repo"
data_bag_path "/root/chef-repo/data_bags"
encrypted_data_bag_secret "/root/chef-repo/data_bag_key"
cookbook_path [ "/root/chef-repo/site-cookbooks",
"/root/chef-repo/cookbooks" ]
role_path "/root/chef-repo/roles"
```

nodeの変更
--

必要なクックブックを記述する。

```
$ cat nodes/localhost.json
// localhost.json
{
"run_list": [
//"recipe[apache]"
//"recipe[mysql]"
"recipe[php]"
]
}
```

attributesの変更
--

各クックブックのattributesを変更してミドルウェアの設定ファイルを変更する。

例)MySQLのメモリサイズ

```
$ cat site-cookbooks/mysql/attributes/default.rb | grep size
default['mysql']['thread_cache_size'] = 0
default['mysql']['max_heap_table_size'] = "16M"
default['mysql']['sort_buffer_size'] = "2M"
default['mysql']['read_buffer_size'] = "128K"
default['mysql']['read_rnd_buffer_size'] = "256K"
default['mysql']['join_buffer_size'] = "128M"
default['mysql']['query_cache_size'] = 0
default['mysql']['innodb_buffer_pool_size'] = "128M"
default['mysql']['innodb_log_file_size'] = "5M"
default['mysql']['innodb_log_buffer_size'] = "8M"
```

chef-soloの実行
--

chef-soloコマンドで指定したクックブックを実行する。

```
$ chef-solo -c solo.rb -j nodes/localhost.json
// 実行ログがひたすら流れる
```
9 changes: 8 additions & 1 deletion nodes/localhost.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{ "run_list": [ "recipe[apache]", "recipe[php]" ]}
// localhost.json
{
"run_list": [
"recipe[apache]",
"recipe[mysql]",
"recipe[php]"
]
}
11 changes: 6 additions & 5 deletions site-cookbooks/apache/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# CHANGELOG for apache
apache CHANGELOG
================

This file is used to list changes made in each version of apache.
This file is used to list changes made in each version of the apache cookbook.

## 0.1.0:

* Initial release of apache
0.1.0
-----
- [your_name] - Initial release of apache

- - -
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
Expand Down
6 changes: 3 additions & 3 deletions site-cookbooks/apache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apache Cookbook
TODO: Enter the cookbook description here.

e.g.
This cookbook makes your favorite breakfast sandwhich.
This cookbook makes your favorite breakfast sandwich.

Requirements
------------
Expand All @@ -15,7 +15,7 @@ e.g.

Attributes
----------
TODO: List you cookbook attributes here.
TODO: List your cookbook attributes here.

e.g.
#### apache::default
Expand Down Expand Up @@ -58,7 +58,7 @@ TODO: (optional) If this is a public cookbook, detail the process for contributi
e.g.
1. Fork the repository on Github
2. Create a named feature branch (like `add_component_x`)
3. Write you change
3. Write your change
4. Write tests for your change (if applicable)
5. Run the tests, ensuring they all pass
6. Submit a Pull Request using Github
Expand Down
31 changes: 19 additions & 12 deletions site-cookbooks/apache/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
###
# Install Settings
###
## Install Settings
####

## Version
default['apache']['version'] = "httpd-2.4.7"

# Version
default['apache']['version'] = "httpd-2.2.24"
## File
default['apache']['file_name'] = "#{default['apache']['version']}.tar.gz"
default['apache']['remote_uri'] = "http://ftp.meisei-u.ac.jp/mirror/apache/dist//httpd/#{default['apache']['file_name']}"

# Directory
default['apache']['dir'] = "/usr/local/apache2/"
## Directory
default['apache']['dir'] = "/usr/local/apache2"
default['apache']['src_dir'] = "/usr/local/src/"

# User
## User
default['apache']['install_user'] = "root"
default['apache']['install_group'] = "root"

# Configure Options
## Configure Options
default['apache']['configure'] = "--prefix=#{default['apache']['dir']} --enable-ssl --with-ssl --enable-rewrite=shared --enable-headers=shared --enable-so --with-mpm=prefork"

# Include files
## Include files
default['apache']['include_files'] = [
"httpd-mpm",
"httpd-vhosts",
"httpd-ssl"
]

## Include library
include_attribute "apache::lib"


###
# Conf Settings
Expand All @@ -31,7 +38,7 @@
# General
default['apache']['port'] = 80
default['apache']['port_ssl'] = 443
default['apache']['directory_index'] = "index.php, index.html"
default['apache']['directory_index'] = "index.php index.html"

# User
default['apache']['user'] = "www"
Expand All @@ -43,8 +50,8 @@
default['apache']['document_root'] = "/usr/local/apache2/htdocs"

# Logs
default['apache']['access_log'] = "#{default['apache']['dir']}logs/access_log"
default['apache']['error_log'] = "#{default['apache']['dir']}logs/error_log"
default['apache']['access_log'] = "#{default['apache']['dir']}/logs/access_log"
default['apache']['error_log'] = "#{default['apache']['dir']}/logs/error_log"

# Prefork
default['apache']['prefork']['start_servers'] = 5
Expand Down
29 changes: 29 additions & 0 deletions site-cookbooks/apache/attributes/lib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
###
## APR Settings
####

## Version
default['apr']['version'] = "apr-1.5.0"
default['apr-util']['version'] = "apr-util-1.5.3"

## File
default['apr']['file_name'] = "#{default['apr']['version']}.tar.gz"
default['apr']['remote_uri'] = "http://ftp.tsukuba.wide.ad.jp/software/apache//apr/#{default['apr']['file_name']}"
default['apr']['configure'] = ""

default['apr-util']['file_name'] = "#{default['apr-util']['version']}.tar.gz"
default['apr-util']['remote_uri'] = "http://ftp.tsukuba.wide.ad.jp/software/apache//apr/#{default['apr-util']['file_name']}"
default['apr-util']['configure'] = "--with-apr=/usr/local/apr/"


###
## PCRE Settings
####

## Version
default['pcre']['version'] = "pcre-8.34"

## File
default['pcre']['file_name'] = "#{default['pcre']['version']}.tar.gz"
default['pcre']['remote_uri'] = "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/#{default['pcre']['file_name']}"
default['pcre']['configure'] = ""
30 changes: 22 additions & 8 deletions site-cookbooks/apache/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,50 @@
# Cookbook Name:: apache
# Recipe:: default
#
# Copyright 2013, Kazuya Sato
# Copyright 2014, Kazuya Sato
#
# All rights reserved - Do Not Redistribute
#
cookbook_file "#{node['apache']['src_dir']}#{node['apache']['version']}.tar.gz" do
mode 0644

# Install library
include_recipe "apache::lib"


# Get source file
remote_file "#{node['apache']['src_dir']}#{node['apache']['file_name']}" do
source "#{node['apache']['remote_uri']}"
end


# Install Apache
bash "install apache" do
user node['apache']['install_user']
cwd node['apache']['src_dir']
not_if "ls #{node['apache']['dir']}"
notifies :run, 'bash[start apache]', :immediately
code <<-EOH
tar xzf #{node['apache']['version']}.tar.gz
tar xzf #{node['apache']['file_name']}
cd #{node['apache']['version']}
./configure #{node['apache']['configure']}
make
make install
EOH
end

template "#{node['apache']['dir']}conf/httpd.conf" do

# Modify conf
template "#{node['apache']['dir']}/conf/httpd.conf" do
source "httpd.conf.erb"
owner node['apache']['install_user']
group node['apache']['install_group']
mode 00644
notifies :run, 'bash[restart apache]', :immediately
end


# Modify extra conf
for include_file in node['apache']['include_files']
template "#{node['apache']['dir']}conf/extra/#{include_file}.conf" do
template "#{node['apache']['dir']}/conf/extra/#{include_file}.conf" do
source "#{include_file}.conf.erb"
owner node['apache']['install_user']
group node['apache']['install_group']
Expand All @@ -42,12 +54,14 @@
end
end


# Bashs
bash "start apache" do
action :nothing
flags '-ex'
user node['apache']['install_user']
code <<-EOH
#{node['apache']['dir']}bin/apachectl start
#{node['apache']['dir']}/bin/apachectl start
EOH
end

Expand All @@ -56,6 +70,6 @@
flags '-ex'
user node['apache']['install_user']
code <<-EOH
#{node['apache']['dir']}bin/apachectl restart
#{node['apache']['dir']}/bin/apachectl restart
EOH
end
Loading

0 comments on commit f0cbc5e

Please sign in to comment.