Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Krattan406 patch 3 #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 50 additions & 42 deletions 2_Tomcat/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
# Install and Configure Apache Tomcat
# Usage

Assumption: You have a virtualbox with centOs7 and ChefDk 2.4.17

1) Login your virtualbox as super user from terminal.
2) Copy the cookbook directory to a base directory
3) Change working directory to <base dir>/cookbooks
4) Run the tomcat installation cookbook:
sudo chef-client --local-mode --runlist 'recipe[tomcat-chef]'

Result -
[2018-02-14T17:11:39-05:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 13.6.4
resolving cookbooks for run list: ["tomcat-chef"]
Synchronizing Cookbooks:
- tomcat-chef (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 13 resources
Recipe: tomcat-chef::default
* yum_package[java-1.7.0-open
 -- etc - Truncated


## Test

root@osboxes cookbooks]# curl localhost/

Result:
If tomcat has been sucessfully installed and started using the cookbook then output of above curl is :

<html>
<body>
<h1>hello world</h1>
</body>
</html>

## References
* https://docs.chef.io/resource_template.html
* https://docs.chef.io/resource_chef_client.html
* https://docs.chef.io/resource_remote_file.html
* https://docs.chef.io/resource_rpm_package.html
* https://docs.chef.io/resource_cookbook_file.html
* https://docs.chef.io/resource_service.html
* https://docs.chef.io/resource_chef_client.html
* https://www.youtube.com/watch?v=FOYc_SGWE-0
* https://learn.chef.io/modules/learn-the-basics/rhel/virtualbox/make-your-recipe-more-manageable#/
* https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7
* https://files.fosswire.com/2007/08/fwunixref.pdf
* https://linux.die.net

The [Apache Tomcat®](http://tomcat.apache.org/) software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket specifications are developed under the Java Community Process.

## Goal

Use Chef to successfully install and configure tomcat on a RHEL7-based target system.

## Success Criteria

You should be prepared and able to demonstrate the following:

* Your Chef cookbook successfully executes on your target node without errors
* Your Chef cookbook is portable and can be run by Chef to validate your work. Please include any instructions or assumptions needed to successfully execute your cookbook.
* You can interact with the default tomcat site in a browser or successfully `curl localhost` on the target system
* You can run `chef-client` multiple times without failures
* Your GitHub.com source code repository shows the history of your work

You should be able to explain the following:

* Steps taken to achieve the end result
* Build and test process of Chef code
* Tools and resources used in the process

>Note: You are NOT required to use Chef Server for this exercise, but you may if that is your preference.

## Instructions

* Translate the Tomcat installation instructions from `INSTRUCTIONS.rb` into Chef code that completes the installation and configuration
* Use the Chef [Resources Reference](https://docs.chef.io/resources.html) to find the most appropriate Chef resources to use for each task
* Once you feel you have met the success criteria outlined above, send a link to your GitHub.com repo to the person coordinating these workshops on your behalf
* Provide instructions for us to run your cookbook so that we can test your work.

There are a couple of ways that you can write, test and run your cookbook.

* Write and test your cookbook locally using Test Kitchen via Vagrant + Virtual Box, or the cloud platform of your choice.
* Steps for this option are outlined [here](https://learn.chef.io/tutorials/local-development/)
* Develop directly on your RHEL-based virtual machine
* Write your cookbook in vim, nano or emacs, and run `chef-client` in `--local-mode`
* The ChefDK or Chef Client must be installed on the VM first

## Suggested Resources

* Use the [Chef Documentation](http://docs.chef.io) to identify and use resources that will help you model the desired state of your infrastructure.
* [Tomcat Installation Instructions](https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7)
4 changes: 4 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true
source 'https://supermarket.chef.io'

metadata
3 changes: 3 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Copyright 2018 The Authors

All rights reserved, do not redistribute.
4 changes: 4 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# tomcat-chef

TODO: Enter the cookbook description here.

107 changes: 107 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/chefignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Put files/directories that should be ignored in this file when uploading
# to a chef-server or supermarket.
# Lines that start with '# ' are comments.

# OS generated files #
######################
.DS_Store
Icon?
nohup.out
ehthumbs.db
Thumbs.db

# SASS #
########
.sass-cache

# EDITORS #
###########
\#*
.#*
*~
*.sw[a-z]
*.bak
REVISION
TAGS*
tmtags
*_flymake.*
*_flymake
*.tmproj
.project
.settings
mkmf.log

## COMPILED ##
##############
a.out
*.o
*.pyc
*.so
*.com
*.class
*.dll
*.exe
*/rdoc/

# Testing #
###########
.watchr
.rspec
spec/*
spec/fixtures/*
test/*
features/*
examples/*
Guardfile
Procfile
.kitchen*
.rubocop.yml
spec/*
Rakefile
.travis.yml
.foodcritic
.codeclimate.yml

# SCM #
#######
.git
*/.git
.gitignore
.gitmodules
.gitconfig
.gitattributes
.svn
*/.bzr/*
*/.hg/*
*/.svn/*

# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp

# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json

# Cookbooks #
#############
CONTRIBUTING*
CHANGELOG*
TESTING*
MAINTAINERS.toml

# Strainer #
############
Colanderfile
Strainerfile
.colander
.strainer

# Vagrant #
###########
.vagrant
Vagrantfile
20 changes: 20 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name 'tomcat-chef'
maintainer 'The Authors'
maintainer_email '[email protected]'
license ''
description 'Installs/Configures tomcat-chef'
long_description 'Installs/Configures tomcat-chef'
version '0.1.0'
chef_version '>= 12.1' if respond_to?(:chef_version)

# The `issues_url` points to the location where issues for this cookbook are
# tracked. A `View Issues` link will be displayed on this cookbook's page when
# uploaded to a Supermarket.
#
# issues_url 'https://github.com/<insert_org_here>/tomcat-chef/issues'

# The `source_url` points to the development repository for this cookbook. A
# `View Source` link will be displayed on this cookbook's page when uploaded to
# a Supermarket.
#
# source_url 'https://github.com/<insert_org_here>/tomcat-chef'
61 changes: 61 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

package 'java-1.7.0-openjdk-devel'

group 'tomcat'

user 'tomcat' do
manage_home false
shell '/bin/nologin'
group 'tomcat'
home '/opt/tomcat'
end


remote_file 'apache-tomcat-8.5.20.tar.gz' do
source 'https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz'
end

directory '/opt/tomcat' do
mode '0777'
group 'tomcat'
end

execute 'tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1'


execute "manage permissions conf" do
command "chgrp -R tomcat /opt/tomcat/conf && chmod g+r /opt/tomcat/conf/*"
end

directory '/opt/tomcat/conf' do
mode '0777'
end

execute "manage permissions bin" do
command "chgrp -R tomcat /opt/tomcat/bin && chmod g+r /opt/tomcat/bin"
end

directory '/opt/tomcat/bin' do
mode '0777'
end

execute 'chmod -R g+r /opt/tomcat/conf/*'

execute 'chown some files: work, temp, logs' do
command 'chown -R tomcat /opt/tomcat/work /opt/tomcat/temp /opt/tomcat/logs'
end


template '/etc/systemd/system/tomcat.service' do
source 'tomcat.service.erb'
end

execute 'systemctl daemon-reload'

service 'tomcat' do
action [:start, :enable]
end




3 changes: 3 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true
require 'chefspec'
require 'chefspec/berkshelf'
35 changes: 35 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Cookbook:: tomcat-chef
# Spec:: default
#
# Copyright:: 2018, The Authors, All Rights Reserved.

require 'spec_helper'

describe 'tomcat-chef::default' do
context 'When all attributes are default, on Ubuntu 16.04' do
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
runner.converge(described_recipe)
end

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end

context 'When all attributes are default, on CentOS 7.4.1708' do
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
runner = ChefSpec::ServerRunner.new(platform: 'centos', version: '7.4.1708')
runner.converge(described_recipe)
end

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
26 changes: 26 additions & 0 deletions 2_Tomcat/cookbooks/tomcat-chef/templates/tomcat.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
Loading