Skip to content

Commit

Permalink
rubocop and foodcritic - dir creation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Hendren committed Oct 29, 2016
1 parent f7dcac4 commit b623947
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 134 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
amzapache CHANGELOG
====================

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

0.1.0
-----
- [phendren] - 12.04.2014 - Initial release of amzapache
12.04.2014 - Initial release of amzapache

0.1.1
-----
- [phendren] - 12.08.2014 - Released with basic fixes
12.08.2014 - Released with basic fixes

0.1.2
-----
- [phendren] - 02.13.2016 - small fixes to format and adding test kitchen
02.13.2016 - small fixes to format and adding test kitchen

0.1.3
-----
10.29.2016 - rubocop/foodcritic and small refactor


- - -
51 changes: 25 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
amzapache Cookbook
===================
This is a relatively straightforward Chef cookbook for installing Apache Web server w/ mod ssl on Amazon Linux
I have not tested this cookbook on CentOS or RHE but it should (in theory) work the same.
amzapache is a Chef cookbook for installing Apache Web server w/ mod ssl on Amazon Linux.
I have not tested this cookbook on CentOS or RHEL.

Requirements
------------
This cookbook was written for use with AWS OpsWorks (Chef 11) for building a custom
web server layer running Amazon Linux.

I wrote it for use with AWS OpsWorks for building a custom layer using Amazon Linux.
Tested with Chef 11.4 with AWS OpsWorks - http://aws.amazon.com/opsworks/
http://aws.amazon.com/opsworks/

Attributes
----------
amzapache attributes: Are all related to the included httpd.conf configuration template and are configured as default attributes

`default[:amzapache][:document_root]` - Document root - default: /var/www/html<br>
`default[:amzapache][:dir]` - Apache config directory - default: /etc/httpd<br>
`default[:amzapache][:log_dir]` - Apache log directory - default: /var/log/httpd<br>
`default[:amzapache][:user]` - User Apache will run as - default: apache<br>
`default[:amzapache][:group]` - Group Apache will run as - default: apache<br>
`default[:amzapache][:binary]` - Where binary will live - default: /usr/sbin/httpd<br>
`default[:amzapache][:icondir]` - Apache icon directory - default: /var/www/icons/<br>
`default[:amzapache][:init_script]` - Apache init script - default: /etc/init.d/httpd<br>
`default[:amzapache][:http_port]` - Port apache will listen on - default: 80<br>
`default[:amzapache][:ssl_port]` - Port SSL will use - default: 443<br>
`default[:amzapache][:contact]` - [email protected]<br>
`default[:amzapache][:servhost]` - Domain you want for your default hostname<br>
`default[:amzapache][:timeout]` - Apache timeout - default: 120<br>
`default[:amzapache][:keepalive]` - Apache keepalive - default: off<br>
`default[:amzapache][:keepaliverequests]` - Apache keep alive requests - default: 100<br>
`default[:amzapache][:keepalivetimeout]` - Apache keepalive timeout - default: 3<br>
`default['amzapache']['document_root']` - Document root - default: /var/www/html<br>
`default['amzapache']['dir']` - Apache config directory - default: /etc/httpd<br>
`default['amzapache']['log_dir']` - Apache log directory - default: /var/log/httpd<br>
`default['amzapache']['user']` - User Apache will run as - default: apache<br>
`default['amzapache']['group']` - Group Apache will run as - default: apache<br>
`default['amzapache']['binary']` - Where binary will live - default: /usr/sbin/httpd<br>
`default['amzapache']['icon_dir']` - Apache icon directory - default: /var/www/icons/<br>
`default['amzapache']['init_script']` - Apache init script - default: /etc/init.d/httpd<br>
`default['amzapache']['http_port']` - Port apache will listen on - default: 80<br>
`default['amzapache']['ssl_port']` - Port SSL will use - default: 443<br>
`default['amzapache']['contact']` - [email protected]<br>
`default['amzapache']['servhost']` - Domain you want for your default hostname<br>
`default['amzapache']['timeout']` - Apache timeout - default: 120<br>
`default['amzapache']['keepalive']` - Apache keepalive - default: off<br>
`default['amzapache']['keepaliverequests']` - Apache keep alive requests - default: 100<br>
`default['amzapache']['keepalivetimeout']` - Apache keepalive timeout - default: 3<br>

Usage
-----
#### amzapache::default
Installs Apache using the settings as configured in the attributes. This cookbooks is setup to function in combo
with php-pkg (installs PHP) and deployer (which can be used to easily deploy applications from github).
with php-pkg (installs PHP) and deployer (which can easily deploy PHP applications from a repo on github).

To use with OpsWorks - Create a custom layer - add amzapache::default as a custom cookbook to the "setup" event.
To use with OpsWorks (Chef 11) - Create a custom layer - add amzapache::default as a custom cookbook to the "setup" event.

Contributing
------------

1. Fork the repository on Github
2. Create a named feature branch (like `add_component_x`)
3. Write your change
4. Write tests for your change (if applicable)
5. Run the tests, ensuring they all pass
5. Run the tests via test kitchen, ensuring they all pass
6. Submit a Pull Request using Github

License and Authors
-------------------
Apache 2.0 License - written by Phil Hendren - github: phendren
gocodeyourself[at]gmail.com

philip.hendren[at]gmail.com
34 changes: 17 additions & 17 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# amzapache attributes

default[:amzapache][:document_root] = '/var/www/html'
default[:amzapache][:dir] = '/etc/httpd'
default[:amzapache][:log_dir] = '/var/log/httpd'
default[:amzapache][:user] = 'apache'
default[:amzapache][:group] = 'apache'
default[:amzapache][:binary] = '/usr/sbin/httpd'
default[:amzapache][:icondir] = '/var/www/icons/'
default[:amzapache][:init_script] = '/etc/init.d/httpd'
default[:amzapache][:http_port] = 80
default[:amzapache][:ssl_port] = 443
default[:amzapache][:contact] = '[email protected]'
default[:amzapache][:servhost] = 'yourdomain.com'
default[:amzapache][:timeout] = 120
default[:amzapache][:keepalive] = 'Off'
default[:amzapache][:keepaliverequests] = 100
default[:amzapache][:keepalivetimeout] = 3

default['amzapache']['document_root'] = '/var/www/html'
default['amzapache']['dir'] = '/etc/httpd'
default['amzapache']['log_dir'] = '/var/log/httpd'
default['amzapache']['user'] = 'apache'
default['amzapache']['group'] = 'apache'
default['amzapache']['binary'] = '/usr/sbin/httpd'
default['amzapache']['icon_dir'] = '/var/www/icons'
default['amzapache']['ssl_dir'] = '/etc/httpd/ssl'
default['amzapache']['init_script'] = '/etc/init.d/httpd'
default['amzapache']['http_port'] = 80
default['amzapache']['ssl_port'] = 443
default['amzapache']['contact'] = 'you@yourdomain.com'
default['amzapache']['servhost'] = 'yourdomain.com'
default['amzapache']['timeout'] = 120
default['amzapache']['keepalive'] = false
default['amzapache']['keepaliverequests'] = 100
default['amzapache']['keepalivetimeout'] = 3
6 changes: 4 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
maintainer 'phendren'
maintainer_email '[email protected]'
license 'Apache License 2.0'
description 'Installs/Configures default apache httpd package on Amazon Linux'
description 'Installs default apache httpd package on Amazon Linux'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.2'
version '0.1.3'

supports 'amazon'
65 changes: 34 additions & 31 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,52 @@
#

package 'httpd' do
package_name 'httpd'
action :install
end

package 'mod_ssl' do
package_name 'mod_ssl'
action :install
end

cookbook_file "/etc/httpd/conf.d/ssl.conf" do
source "ssl.conf.txt"
mode '0644'
owner 'root'
group 'root'
end

service 'httpd' do
stop_command '/etc/init.d/httpd stop'
start_command '/etc/init.d/httpd start'
restart_command '/etc/init.d/httpd restart'
action :enable
end

directory "/etc/httpd/ssl" do
# Make sure directories exist
%w(
node['amzapache']['document_root']
node['amzapache']['icon_dir']
node['amzapache']['ssl_dir']
).each do |dir|
directory dir do
owner 'root'
group 'root'
mode 0755
action :create
end
end

cookbook_file '/etc/httpd/conf.d/ssl.conf' do
source 'ssl.conf.txt'
mode '0644'
owner 'root'
group 'root'
mode '0755'
action :create
end

# This is some simple bash-fu for creating a module listing
bash "module-listing" do
cwd "/etc/httpd"
user "root"
# Simple bash-fu for creating a module listing
bash 'module-listing' do
cwd '/etc/httpd'
user 'root'
code <<-EOH
build="# dynamic module listing\n"
build='# dynamic module listing\n'
build+='# ordered by filename length'
echo $build > /tmp/modules.txt.erb
cd /etc/httpd/modules;
for list in $(ls); do
base=$(basename $list .so
for list in $(ls |awk '{print length($0)"\t"$0}' |sort -n |cut --complement -f1); do
base=$(basename $list .so)
name=$(echo $base | sed -r 's/^.{4}//')
part="_module"
echo "LoadModule $name$part modules/$list" >> /tmp/modules.txt.erb
Expand All @@ -51,23 +60,17 @@
end

template 'httpd.conf' do
path "/etc/httpd/conf/httpd.conf"
path '/etc/httpd/conf/httpd.conf'
source 'httpd.conf.erb'
owner 'root'
group 'root'
mode '0644'
mode 0644
end

cookbook_file "/var/www/html/index.html" do
source "index.html.txt"
mode "0644"
cookbook_file '/var/www/html/index.html' do
source 'index.html.txt'
mode 0644
owner 'apache'
group 'apache'
end

service "httpd" do
stop_command "/etc/init.d/httpd stop"
start_command "/etc/init.d/httpd start"
restart_command "/etc/init.d/httpd restart"
action :restart
notifies :restart, 'service[httpd]'
end
Loading

0 comments on commit b623947

Please sign in to comment.