From 817086ab85ca23cf20fd7ddc5554b2824d2764ea Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 21:07:28 +1000 Subject: [PATCH 01/38] add puppet config for: basic nginx basic unicorn simple-sinatra-app --- puppet/nginx/manifests/init.pp | 26 ++++++++ .../files/init/.simple-sinatra-init.conf.swp | Bin 0 -> 12288 bytes .../files/init/simple-sinatra-init.conf | 33 ++++++++++ .../files/nginx/simple-sinatra-nginx.conf | 13 ++++ puppet/simple-sinatra-app/manifests/init.pp | 61 ++++++++++++++++++ puppet/unicorn/manifests/init.pp | 17 +++++ 6 files changed, 150 insertions(+) create mode 100644 puppet/nginx/manifests/init.pp create mode 100644 puppet/simple-sinatra-app/files/init/.simple-sinatra-init.conf.swp create mode 100644 puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf create mode 100644 puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf create mode 100644 puppet/simple-sinatra-app/manifests/init.pp create mode 100644 puppet/unicorn/manifests/init.pp diff --git a/puppet/nginx/manifests/init.pp b/puppet/nginx/manifests/init.pp new file mode 100644 index 0000000..d334f1a --- /dev/null +++ b/puppet/nginx/manifests/init.pp @@ -0,0 +1,26 @@ +# == Class: nginx install nginx server +# to add OS version please add the OS package selection + +class nginx { + case $::operatingsystem { + 'Ubuntu': { + $packages = 'nginx' + $service = 'nginx' + } + default: { fail('Unrecognized operating system') } + } + File { + mode => '0644', + owner => 'root', + group => 'root', + } + package { + $packages: + ensure => latest; + } + service { + $service: + ensure => running, + hasstatus => true, + } +} diff --git a/puppet/simple-sinatra-app/files/init/.simple-sinatra-init.conf.swp b/puppet/simple-sinatra-app/files/init/.simple-sinatra-init.conf.swp new file mode 100644 index 0000000000000000000000000000000000000000..fad0300fd09b5c3bfaa83b8a2c2e5c97b6351eb4 GIT binary patch literal 12288 zcmeI2yKWOf6ow~MAP7NFBTXh2qFL|S5d;yrKwyHwiH#vpAd1a;3?tUF%kKDsxHU+W z@C5J_bUXk;f`$@AM?pzT1OMI(u~DEx0-dpb@9vp1XU=?cwy-=~&XvYGUnws$v;&O2 zd-dqz=RHT}c9$3nV$~0H(y?=kZw8U^rQ0j_l+iMdtG*h_vX-Xo4t^T?APZ=FL08(5 zbZx{BeQCu?yC!liHw^8b@?~r*t;}?9Vk>)r?)?;zZixU9_#*-X)3Z*@v*l{VN&J_@ zB0qF+^N)s-6A>T+M1Tko0U|&IhyW2F0{;gA6V9=RSjw(^Ig9yqZt9vp(uD{R0U|&I zhyW2F0z`la5CI}U1c(3;_y-BNUB>S3W$f@iB#;09i{Jlm7Z`g3y?~xW&!DH!6X-Ey zpcraEOV9%Jbw6Vtp!d*gXauc5pXM2R2|a@DKx61ObRJrQ7NBpK{|odHItnHEaEKZa zAOb{y2oM1xKm>>Y5g-D8iGb8y9($1r4dZBXEInRY+uUfJZgn=eWreC+6Qy?J%-Ke> zE@04ZU&69+YCU}%1<@@T#kJDaR_8*!a|s@USVr*Jyj1Tb18zjYAjI=pr?uHm3|&{^ z%rS2K;D(hP21aMIwN^}!SbaH^er9gguhg5#uq~yLN~O9|cJQg3EVWym%OcI%>vB;# z)o!0_t=H|$l&4dxrVfc~O`LEXC+o#@Y22Dnx))4rNeVS#58cQ{7IwPG?7NKT%q>Te zyF~-N%?-E&%XzXXw%*NPr1@wx0s-TmEN*x@UlM5ctaO@u|5jH;+zNl|Xk=`-1s0PP z%tqw*?(w_WXC%Xg4mj4u5ninF*aYD!3P2g|tn&Nm)RTw>U6GBS44>F{8n3ZCMM+^N zU2cuHS<;k#gq*mpPNx(`I7x2Y$P^_D#6zBxVol60RiwRX+0{frJ2NJ=Ic+PZ#m=IF zQ2?In+bBAFpp_RyIvbf+8JvP}=KOkcx*ZaXMKTUu?6$A^;8}6_vBJcd9EZ{~JbMlB w6C2z)-Un1bTK4>!bNo82$uhT@tINl(GuD+^c`5Y$V$nR$mMe`A+LMBP2NaEWQ~&?~ literal 0 HcmV?d00001 diff --git a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf new file mode 100644 index 0000000..e1484c4 --- /dev/null +++ b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf @@ -0,0 +1,33 @@ +description "simple-sinatra-app unicorn instance" + +start on runlevel [235] +stop on runlevel [06] + +expect daemon + +respawn +respawn limit 10 5 + +env APPHOME="/opt/simple-sinatra-app/app" +env GUNICORN="/use/local/bin/unicorn" +env USER="www-data" +env GROUP="www-data" +env NAME="simple-sinatra-app" + +pre-start script + test -n "$GUNICORN" -a -x "$GUNICORN" || { echo "no $GUNICORN";stop; exit 0; } + test -d "$APPHOME" || { echo "no $APPHOME"; stop; exit 0; } + test -d "/var/log/simple-sinatra-app || { echo "no log dir"; stop; exit 0; } + mkdir -p /var/run/simple-sinatra-app + chown www-data:www-data /var/run/simple-sinatra-app +end script + +script + PIDFILE="/var/run/$NAME/$NAME.pid" + LOGFILE="/var/log/$NAME/$NAME.log" + LOGLEVEL="info" + PORT="8000" + WORKERS=2 + cd "$APPHOME/" + exec $GUNICORN --pid="$PIDFILE" --name="$NAME" --workers=$WORKERS --user="$USER" --group="$GROUP" --daemon --log-file="$LOGFILE" --log-level="$LOGLEVEL" --bind="127.0.0.1:$PORT" +end script diff --git a/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf b/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf new file mode 100644 index 0000000..9991727 --- /dev/null +++ b/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf @@ -0,0 +1,13 @@ +# +# nginx proxy for simple-sinatra-app +# +server { + server_name simple-sinatra-app; + + location / { + proxy_pass http://localhost:9292; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp new file mode 100644 index 0000000..99bf5ad --- /dev/null +++ b/puppet/simple-sinatra-app/manifests/init.pp @@ -0,0 +1,61 @@ +# == Class: simple-sinatra-app install rea example app from GitHub +class simple-sinatra-app { + include nginx + include unicorn + case $::operatingsystem { + 'Ubuntu': { + $root_path = '/opt/simple-sinatra-app' + $owner = 'www-data' + $group = 'www-data' + } + default: { fail('Unrecognized operating system') } + } + File { + owner => $owner, + group => $group, + } + exec { + 'get_app': + command => "/usr/bin/git clone git://github.com/tnh/simple-sinatra-app.git ${root_path}/app", + refreshonly => true, + notify => Exec['install_gem']; + 'install_gem': + command => '/usr/bin/bundle install --gemfile=/opt/simple-sinatra-app/app/Gemfile --path=/opt/simple-sinatra-app/app/', + refreshonly => true, + require => [Exec['get_app'],Package['ruby-bundler']]; + } + file { + "${root_path}": + ensure => directory, + mode => '0755'; + "${root_path}/app": + ensure => directory, + mode => '0755', + notify => Exec['get_app']; + '/etc/init/simple-sinatra-app.conf': + ensure => present, + mode => '0644', + owner => 'root', + group => 'root', + #source => 'puppet:///modules/rea/init/simple-sinatra-init.conf', + require => Exec['get_app']; + '/etc/init.d/simple-sinatra-app': + ensure => symlink, + target => '/lib/init/upstart-job', + require => File['/etc/init/simple-sinatra-app.conf']; + '/etc/nginx/sites-available/simple-sinatra-app.conf': + ensure => present, + mode => '0644', + #source => 'puppet:///modules/rea/nginx/simple-sinatra-nginx.conf', + require => Package["${nginx::packages}", "${unicorn::packages}"]; + '/etc/nginx/sites-enabled/simple-sinatra-app.conf': + ensure => symlink, + target => '/etc/nginx/sites-available/simple-sinatra-app.conf', + notify => Service["${nginx::service}"]; + } + service { + 'simple-sinatra-app': + ensure => running, + hasstatus => true; + } +} diff --git a/puppet/unicorn/manifests/init.pp b/puppet/unicorn/manifests/init.pp new file mode 100644 index 0000000..42de717 --- /dev/null +++ b/puppet/unicorn/manifests/init.pp @@ -0,0 +1,17 @@ +# == Class: unicorn install unicorn gem package +# to add OS please edit the allowed OS +class unicorn { + case $::operatingsystem { + 'Ubuntu': { + $packages = 'ruby-bundler' + } + default: { fail('Unrecognized operating system') } + } + package { + 'unicorn': + ensure => latest, + provider => gem; + $packages: + ensure => latest; + } +} From e476617ce0ba706da97710bbd6268ee44b2132a3 Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 21:22:13 +1000 Subject: [PATCH 02/38] fix the upstart script for unicorn --- .../files/init/simple-sinatra-init.conf | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf index e1484c4..0682ce7 100644 --- a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf +++ b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf @@ -3,31 +3,20 @@ description "simple-sinatra-app unicorn instance" start on runlevel [235] stop on runlevel [06] -expect daemon - -respawn -respawn limit 10 5 - env APPHOME="/opt/simple-sinatra-app/app" -env GUNICORN="/use/local/bin/unicorn" +env GUNICORN="/usr/local/bin/unicorn" env USER="www-data" env GROUP="www-data" env NAME="simple-sinatra-app" +env CONFFILE="/opt/simple-sinatra-app/app/config.ru" pre-start script test -n "$GUNICORN" -a -x "$GUNICORN" || { echo "no $GUNICORN";stop; exit 0; } + test -f "$CONFFILE" || { echo "no unicorn config file: $CONFFILE";stop; exit 0; } test -d "$APPHOME" || { echo "no $APPHOME"; stop; exit 0; } - test -d "/var/log/simple-sinatra-app || { echo "no log dir"; stop; exit 0; } - mkdir -p /var/run/simple-sinatra-app - chown www-data:www-data /var/run/simple-sinatra-app end script script - PIDFILE="/var/run/$NAME/$NAME.pid" - LOGFILE="/var/log/$NAME/$NAME.log" - LOGLEVEL="info" - PORT="8000" - WORKERS=2 cd "$APPHOME/" - exec $GUNICORN --pid="$PIDFILE" --name="$NAME" --workers=$WORKERS --user="$USER" --group="$GROUP" --daemon --log-file="$LOGFILE" --log-level="$LOGLEVEL" --bind="127.0.0.1:$PORT" + exec $GUNICORN -c $CONFFILE -D end script From 3bffeafb4c1c64f0bb9f0a2591e3ed49d6367e22 Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 22:27:42 +1000 Subject: [PATCH 03/38] remove debug marks --- puppet/simple-sinatra-app/manifests/init.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp index 99bf5ad..dca9592 100644 --- a/puppet/simple-sinatra-app/manifests/init.pp +++ b/puppet/simple-sinatra-app/manifests/init.pp @@ -37,7 +37,7 @@ mode => '0644', owner => 'root', group => 'root', - #source => 'puppet:///modules/rea/init/simple-sinatra-init.conf', + source => 'puppet:///modules/rea/init/simple-sinatra-init.conf', require => Exec['get_app']; '/etc/init.d/simple-sinatra-app': ensure => symlink, @@ -46,7 +46,7 @@ '/etc/nginx/sites-available/simple-sinatra-app.conf': ensure => present, mode => '0644', - #source => 'puppet:///modules/rea/nginx/simple-sinatra-nginx.conf', + source => 'puppet:///modules/rea/nginx/simple-sinatra-nginx.conf', require => Package["${nginx::packages}", "${unicorn::packages}"]; '/etc/nginx/sites-enabled/simple-sinatra-app.conf': ensure => symlink, From 5ca4b7784463a081979d0bab1e905183fa61059d Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 23:09:23 +1000 Subject: [PATCH 04/38] fix duble daemon mod --- puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf index 0682ce7..710258d 100644 --- a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf +++ b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf @@ -8,7 +8,7 @@ env GUNICORN="/usr/local/bin/unicorn" env USER="www-data" env GROUP="www-data" env NAME="simple-sinatra-app" -env CONFFILE="/opt/simple-sinatra-app/app/config.ru" +env CONFFILE="/opt/simple-sinatra-app/app/config.rb" pre-start script test -n "$GUNICORN" -a -x "$GUNICORN" || { echo "no $GUNICORN";stop; exit 0; } @@ -18,5 +18,5 @@ end script script cd "$APPHOME/" - exec $GUNICORN -c $CONFFILE -D + exec $GUNICORN -c $CONFFILE end script From 1b59af0780ff6108669efd81813ea47b2403e112 Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 23:14:07 +1000 Subject: [PATCH 05/38] add log folders and unicorn config --- puppet/simple-sinatra-app/manifests/init.pp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp index dca9592..884bef5 100644 --- a/puppet/simple-sinatra-app/manifests/init.pp +++ b/puppet/simple-sinatra-app/manifests/init.pp @@ -23,6 +23,10 @@ command => '/usr/bin/bundle install --gemfile=/opt/simple-sinatra-app/app/Gemfile --path=/opt/simple-sinatra-app/app/', refreshonly => true, require => [Exec['get_app'],Package['ruby-bundler']]; + 'set_unicorn': + command => "cd ${root_path}/app && rails new unicorn", + refreshonly => true, + require => Exec['get_app', 'install_gem']; } file { "${root_path}": @@ -52,6 +56,14 @@ ensure => symlink, target => '/etc/nginx/sites-available/simple-sinatra-app.conf', notify => Service["${nginx::service}"]; + "${root_path}/app/unicorn.rb": + ensure => present, + mode => '0644', + source => 'puppet:///modules/rea/opt/unicorn.rb', + require => Exec['set_unicorn']; + '/var/log/simple-sinatra-app/': + ensure => directory, + mode =>'0755'; } service { 'simple-sinatra-app': From 69af3a7a55582742b79ac01f4b7c7577381fba73 Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 23:17:08 +1000 Subject: [PATCH 06/38] update port --- puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf b/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf index 9991727..e7a6b99 100644 --- a/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf +++ b/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf @@ -5,7 +5,7 @@ server { server_name simple-sinatra-app; location / { - proxy_pass http://localhost:9292; + proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; From 17ff632bdb8987825cf65c0ea00ac245a8596500 Mon Sep 17 00:00:00 2001 From: simonoded Date: Sat, 4 May 2013 23:18:02 +1000 Subject: [PATCH 07/38] add unicorn config file --- .../simple-sinatra-app/files/opt/unicorn.rb | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 puppet/simple-sinatra-app/files/opt/unicorn.rb diff --git a/puppet/simple-sinatra-app/files/opt/unicorn.rb b/puppet/simple-sinatra-app/files/opt/unicorn.rb new file mode 100644 index 0000000..d0ac3d4 --- /dev/null +++ b/puppet/simple-sinatra-app/files/opt/unicorn.rb @@ -0,0 +1,104 @@ +# Sample verbose configuration file for Unicorn (not Rack) +# +# This configuration file documents many features of Unicorn +# that may not be needed for some applications. See +# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb +# for a much simpler configuration file. +# +# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete +# documentation. + +# Use at least one worker per core if you're on a dedicated server, +# more will usually help for _short_ waits on databases/caches. +worker_processes 4 + +# Since Unicorn is never exposed to outside clients, it does not need to +# run on the standard HTTP port (80), there is no reason to start Unicorn +# as root unless it's from system init scripts. +# If running the master process as root and the workers as an unprivileged +# user, do this to switch euid/egid in the workers (also chowns logs): +# user "unprivileged_user", "unprivileged_group" + +# Help ensure your application will always spawn in the symlinked +# "current" directory that Capistrano sets up. +#working_directory "/path/to/app/current" # available in 0.94.0+ +working_directory "/opt/simple-sinatra-app/app" # available in 0.94.0+ + +# listen on both a Unix domain socket and a TCP port, +# we use a shorter backlog for quicker failover when busy +listen "/tmp/.sock", :backlog => 64 +listen 8080, :tcp_nopush => true + +# nuke workers after 30 seconds instead of 60 seconds (the default) +timeout 30 + +# feel free to point this anywhere accessible on the filesystem +#pid "/path/to/app/shared/pids/unicorn.pid" +pid "/var/run/simple-sinatra-app.pid" + +# By default, the Unicorn logger will write to stderr. +# Additionally, ome applications/frameworks log to stderr or stdout, +# so prevent them from going to /dev/null when daemonized here: +stderr_path "/var/log/simple-sinatra-app/unicorn.stderr.log" +stdout_path "/var/log/simple-sinatra-app/unicorn.stdout.log" + +# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings +# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow +preload_app true +GC.respond_to?(:copy_on_write_friendly=) and + GC.copy_on_write_friendly = true + +# Enable this flag to have unicorn test client connections by writing the +# beginning of the HTTP headers before calling the application. This +# prevents calling the application for connections that have disconnected +# while queued. This is only guaranteed to detect clients on the same +# host unicorn runs on, and unlikely to detect disconnects even on a +# fast LAN. +check_client_connection false + +before_fork do |server, worker| + # the following is highly recomended for Rails + "preload_app true" + # as there's no need for the master process to hold a connection + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! + + # The following is only recommended for memory/DB-constrained + # installations. It is not needed if your system can house + # twice as many worker_processes as you have configured. + # + # # This allows a new master process to incrementally + # # phase out the old master process with SIGTTOU to avoid a + # # thundering herd (especially in the "preload_app false" case) + # # when doing a transparent upgrade. The last worker spawned + # # will then kill off the old master process with a SIGQUIT. + # old_pid = "#{server.config[:pid]}.oldbin" + # if old_pid != server.pid + # begin + # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU + # Process.kill(sig, File.read(old_pid).to_i) + # rescue Errno::ENOENT, Errno::ESRCH + # end + # end + # + # Throttle the master from forking too quickly by sleeping. Due + # to the implementation of standard Unix signal handlers, this + # helps (but does not completely) prevent identical, repeated signals + # from being lost when the receiving process is busy. + # sleep 1 +end + +after_fork do |server, worker| + # per-process listener ports for debugging/admin/migrations + # addr = "127.0.0.1:#{9293 + worker.nr}" + # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true) + + # the following is *required* for Rails + "preload_app true", + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection + + # if preload_app is true, then you may also want to check and + # restart any other shared sockets/descriptors such as Memcached, + # and Redis. TokyoCabinet file handles are safe to reuse + # between any number of forked children (assuming your kernel + # correctly implements pread()/pwrite() system calls) +end From 4c1c88e5ba332ed4de7e5d031c5c97d3db37d0e7 Mon Sep 17 00:00:00 2001 From: simonoded Date: Sun, 5 May 2013 08:11:14 +1000 Subject: [PATCH 08/38] fix styling issues to match puppet style guide --- .../files/init/.simple-sinatra-init.conf.swp | Bin 12288 -> 0 bytes puppet/simple-sinatra-app/manifests/init.pp | 8 ++++---- puppet/unicorn/manifests/init.pp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 puppet/simple-sinatra-app/files/init/.simple-sinatra-init.conf.swp diff --git a/puppet/simple-sinatra-app/files/init/.simple-sinatra-init.conf.swp b/puppet/simple-sinatra-app/files/init/.simple-sinatra-init.conf.swp deleted file mode 100644 index fad0300fd09b5c3bfaa83b8a2c2e5c97b6351eb4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2yKWOf6ow~MAP7NFBTXh2qFL|S5d;yrKwyHwiH#vpAd1a;3?tUF%kKDsxHU+W z@C5J_bUXk;f`$@AM?pzT1OMI(u~DEx0-dpb@9vp1XU=?cwy-=~&XvYGUnws$v;&O2 zd-dqz=RHT}c9$3nV$~0H(y?=kZw8U^rQ0j_l+iMdtG*h_vX-Xo4t^T?APZ=FL08(5 zbZx{BeQCu?yC!liHw^8b@?~r*t;}?9Vk>)r?)?;zZixU9_#*-X)3Z*@v*l{VN&J_@ zB0qF+^N)s-6A>T+M1Tko0U|&IhyW2F0{;gA6V9=RSjw(^Ig9yqZt9vp(uD{R0U|&I zhyW2F0z`la5CI}U1c(3;_y-BNUB>S3W$f@iB#;09i{Jlm7Z`g3y?~xW&!DH!6X-Ey zpcraEOV9%Jbw6Vtp!d*gXauc5pXM2R2|a@DKx61ObRJrQ7NBpK{|odHItnHEaEKZa zAOb{y2oM1xKm>>Y5g-D8iGb8y9($1r4dZBXEInRY+uUfJZgn=eWreC+6Qy?J%-Ke> zE@04ZU&69+YCU}%1<@@T#kJDaR_8*!a|s@USVr*Jyj1Tb18zjYAjI=pr?uHm3|&{^ z%rS2K;D(hP21aMIwN^}!SbaH^er9gguhg5#uq~yLN~O9|cJQg3EVWym%OcI%>vB;# z)o!0_t=H|$l&4dxrVfc~O`LEXC+o#@Y22Dnx))4rNeVS#58cQ{7IwPG?7NKT%q>Te zyF~-N%?-E&%XzXXw%*NPr1@wx0s-TmEN*x@UlM5ctaO@u|5jH;+zNl|Xk=`-1s0PP z%tqw*?(w_WXC%Xg4mj4u5ninF*aYD!3P2g|tn&Nm)RTw>U6GBS44>F{8n3ZCMM+^N zU2cuHS<;k#gq*mpPNx(`I7x2Y$P^_D#6zBxVol60RiwRX+0{frJ2NJ=Ic+PZ#m=IF zQ2?In+bBAFpp_RyIvbf+8JvP}=KOkcx*ZaXMKTUu?6$A^;8}6_vBJcd9EZ{~JbMlB w6C2z)-Un1bTK4>!bNo82$uhT@tINl(GuD+^c`5Y$V$nR$mMe`A+LMBP2NaEWQ~&?~ diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp index 884bef5..16a9679 100644 --- a/puppet/simple-sinatra-app/manifests/init.pp +++ b/puppet/simple-sinatra-app/manifests/init.pp @@ -29,7 +29,7 @@ require => Exec['get_app', 'install_gem']; } file { - "${root_path}": + $root_path: ensure => directory, mode => '0755'; "${root_path}/app": @@ -51,12 +51,12 @@ ensure => present, mode => '0644', source => 'puppet:///modules/rea/nginx/simple-sinatra-nginx.conf', - require => Package["${nginx::packages}", "${unicorn::packages}"]; + require => Package[$nginx::packages, $unicorn::packages]; '/etc/nginx/sites-enabled/simple-sinatra-app.conf': ensure => symlink, target => '/etc/nginx/sites-available/simple-sinatra-app.conf', - notify => Service["${nginx::service}"]; - "${root_path}/app/unicorn.rb": + notify => Service[$nginx::service]; + "${root_path}/app/unicorn.rb": ensure => present, mode => '0644', source => 'puppet:///modules/rea/opt/unicorn.rb', diff --git a/puppet/unicorn/manifests/init.pp b/puppet/unicorn/manifests/init.pp index 42de717..58fcb26 100644 --- a/puppet/unicorn/manifests/init.pp +++ b/puppet/unicorn/manifests/init.pp @@ -4,8 +4,8 @@ case $::operatingsystem { 'Ubuntu': { $packages = 'ruby-bundler' - } - default: { fail('Unrecognized operating system') } + } + default: { fail('Unrecognized operating system') } } package { 'unicorn': From ee1cd11847cdda8543f99436b16c9f98f3c7cb6f Mon Sep 17 00:00:00 2001 From: simonoded Date: Sun, 5 May 2013 08:40:39 +1000 Subject: [PATCH 09/38] fix rails path --- puppet/simple-sinatra-app/manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp index 16a9679..55f4416 100644 --- a/puppet/simple-sinatra-app/manifests/init.pp +++ b/puppet/simple-sinatra-app/manifests/init.pp @@ -24,7 +24,7 @@ refreshonly => true, require => [Exec['get_app'],Package['ruby-bundler']]; 'set_unicorn': - command => "cd ${root_path}/app && rails new unicorn", + command => "/usr/bin/rails ${root_path}/app", refreshonly => true, require => Exec['get_app', 'install_gem']; } From 458e74ae3620cc8d21688c19e34994c41a5b59aa Mon Sep 17 00:00:00 2001 From: simonoded Date: Sun, 5 May 2013 12:12:35 +1000 Subject: [PATCH 10/38] add rails package to the needed list --- puppet/unicorn/manifests/init.pp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/puppet/unicorn/manifests/init.pp b/puppet/unicorn/manifests/init.pp index 58fcb26..7540872 100644 --- a/puppet/unicorn/manifests/init.pp +++ b/puppet/unicorn/manifests/init.pp @@ -4,6 +4,7 @@ case $::operatingsystem { 'Ubuntu': { $packages = 'ruby-bundler' + $rails = rails } default: { fail('Unrecognized operating system') } } @@ -13,5 +14,7 @@ provider => gem; $packages: ensure => latest; + $rails: + ensure => latest; } } From 58e866feace4dd4b9b63ba22c8ff961a37e0063f Mon Sep 17 00:00:00 2001 From: osimon Date: Tue, 7 May 2013 13:20:30 +1000 Subject: [PATCH 11/38] add call for theset_unicorncomman --- puppet/simple-sinatra-app/manifests/init.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp index 55f4416..43a644b 100644 --- a/puppet/simple-sinatra-app/manifests/init.pp +++ b/puppet/simple-sinatra-app/manifests/init.pp @@ -22,6 +22,7 @@ 'install_gem': command => '/usr/bin/bundle install --gemfile=/opt/simple-sinatra-app/app/Gemfile --path=/opt/simple-sinatra-app/app/', refreshonly => true, + notify => Exec['set_unicorn'], require => [Exec['get_app'],Package['ruby-bundler']]; 'set_unicorn': command => "/usr/bin/rails ${root_path}/app", From 7f63905c68834c5235761ce62242b4aa4338709d Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Wed, 2 Apr 2014 21:26:27 +1100 Subject: [PATCH 12/38] remove not working puppet module --- puppet/nginx/manifests/init.pp | 26 ----- .../files/init/simple-sinatra-init.conf | 22 ---- .../files/nginx/simple-sinatra-nginx.conf | 13 --- .../simple-sinatra-app/files/opt/unicorn.rb | 104 ------------------ puppet/simple-sinatra-app/manifests/init.pp | 74 ------------- puppet/unicorn/manifests/init.pp | 20 ---- 6 files changed, 259 deletions(-) delete mode 100644 puppet/nginx/manifests/init.pp delete mode 100644 puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf delete mode 100644 puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf delete mode 100644 puppet/simple-sinatra-app/files/opt/unicorn.rb delete mode 100644 puppet/simple-sinatra-app/manifests/init.pp delete mode 100644 puppet/unicorn/manifests/init.pp diff --git a/puppet/nginx/manifests/init.pp b/puppet/nginx/manifests/init.pp deleted file mode 100644 index d334f1a..0000000 --- a/puppet/nginx/manifests/init.pp +++ /dev/null @@ -1,26 +0,0 @@ -# == Class: nginx install nginx server -# to add OS version please add the OS package selection - -class nginx { - case $::operatingsystem { - 'Ubuntu': { - $packages = 'nginx' - $service = 'nginx' - } - default: { fail('Unrecognized operating system') } - } - File { - mode => '0644', - owner => 'root', - group => 'root', - } - package { - $packages: - ensure => latest; - } - service { - $service: - ensure => running, - hasstatus => true, - } -} diff --git a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf b/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf deleted file mode 100644 index 710258d..0000000 --- a/puppet/simple-sinatra-app/files/init/simple-sinatra-init.conf +++ /dev/null @@ -1,22 +0,0 @@ -description "simple-sinatra-app unicorn instance" - -start on runlevel [235] -stop on runlevel [06] - -env APPHOME="/opt/simple-sinatra-app/app" -env GUNICORN="/usr/local/bin/unicorn" -env USER="www-data" -env GROUP="www-data" -env NAME="simple-sinatra-app" -env CONFFILE="/opt/simple-sinatra-app/app/config.rb" - -pre-start script - test -n "$GUNICORN" -a -x "$GUNICORN" || { echo "no $GUNICORN";stop; exit 0; } - test -f "$CONFFILE" || { echo "no unicorn config file: $CONFFILE";stop; exit 0; } - test -d "$APPHOME" || { echo "no $APPHOME"; stop; exit 0; } -end script - -script - cd "$APPHOME/" - exec $GUNICORN -c $CONFFILE -end script diff --git a/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf b/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf deleted file mode 100644 index e7a6b99..0000000 --- a/puppet/simple-sinatra-app/files/nginx/simple-sinatra-nginx.conf +++ /dev/null @@ -1,13 +0,0 @@ -# -# nginx proxy for simple-sinatra-app -# -server { - server_name simple-sinatra-app; - - location / { - proxy_pass http://localhost:8080; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } -} diff --git a/puppet/simple-sinatra-app/files/opt/unicorn.rb b/puppet/simple-sinatra-app/files/opt/unicorn.rb deleted file mode 100644 index d0ac3d4..0000000 --- a/puppet/simple-sinatra-app/files/opt/unicorn.rb +++ /dev/null @@ -1,104 +0,0 @@ -# Sample verbose configuration file for Unicorn (not Rack) -# -# This configuration file documents many features of Unicorn -# that may not be needed for some applications. See -# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb -# for a much simpler configuration file. -# -# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete -# documentation. - -# Use at least one worker per core if you're on a dedicated server, -# more will usually help for _short_ waits on databases/caches. -worker_processes 4 - -# Since Unicorn is never exposed to outside clients, it does not need to -# run on the standard HTTP port (80), there is no reason to start Unicorn -# as root unless it's from system init scripts. -# If running the master process as root and the workers as an unprivileged -# user, do this to switch euid/egid in the workers (also chowns logs): -# user "unprivileged_user", "unprivileged_group" - -# Help ensure your application will always spawn in the symlinked -# "current" directory that Capistrano sets up. -#working_directory "/path/to/app/current" # available in 0.94.0+ -working_directory "/opt/simple-sinatra-app/app" # available in 0.94.0+ - -# listen on both a Unix domain socket and a TCP port, -# we use a shorter backlog for quicker failover when busy -listen "/tmp/.sock", :backlog => 64 -listen 8080, :tcp_nopush => true - -# nuke workers after 30 seconds instead of 60 seconds (the default) -timeout 30 - -# feel free to point this anywhere accessible on the filesystem -#pid "/path/to/app/shared/pids/unicorn.pid" -pid "/var/run/simple-sinatra-app.pid" - -# By default, the Unicorn logger will write to stderr. -# Additionally, ome applications/frameworks log to stderr or stdout, -# so prevent them from going to /dev/null when daemonized here: -stderr_path "/var/log/simple-sinatra-app/unicorn.stderr.log" -stdout_path "/var/log/simple-sinatra-app/unicorn.stdout.log" - -# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings -# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow -preload_app true -GC.respond_to?(:copy_on_write_friendly=) and - GC.copy_on_write_friendly = true - -# Enable this flag to have unicorn test client connections by writing the -# beginning of the HTTP headers before calling the application. This -# prevents calling the application for connections that have disconnected -# while queued. This is only guaranteed to detect clients on the same -# host unicorn runs on, and unlikely to detect disconnects even on a -# fast LAN. -check_client_connection false - -before_fork do |server, worker| - # the following is highly recomended for Rails + "preload_app true" - # as there's no need for the master process to hold a connection - defined?(ActiveRecord::Base) and - ActiveRecord::Base.connection.disconnect! - - # The following is only recommended for memory/DB-constrained - # installations. It is not needed if your system can house - # twice as many worker_processes as you have configured. - # - # # This allows a new master process to incrementally - # # phase out the old master process with SIGTTOU to avoid a - # # thundering herd (especially in the "preload_app false" case) - # # when doing a transparent upgrade. The last worker spawned - # # will then kill off the old master process with a SIGQUIT. - # old_pid = "#{server.config[:pid]}.oldbin" - # if old_pid != server.pid - # begin - # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU - # Process.kill(sig, File.read(old_pid).to_i) - # rescue Errno::ENOENT, Errno::ESRCH - # end - # end - # - # Throttle the master from forking too quickly by sleeping. Due - # to the implementation of standard Unix signal handlers, this - # helps (but does not completely) prevent identical, repeated signals - # from being lost when the receiving process is busy. - # sleep 1 -end - -after_fork do |server, worker| - # per-process listener ports for debugging/admin/migrations - # addr = "127.0.0.1:#{9293 + worker.nr}" - # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true) - - # the following is *required* for Rails + "preload_app true", - defined?(ActiveRecord::Base) and - ActiveRecord::Base.establish_connection - - # if preload_app is true, then you may also want to check and - # restart any other shared sockets/descriptors such as Memcached, - # and Redis. TokyoCabinet file handles are safe to reuse - # between any number of forked children (assuming your kernel - # correctly implements pread()/pwrite() system calls) -end diff --git a/puppet/simple-sinatra-app/manifests/init.pp b/puppet/simple-sinatra-app/manifests/init.pp deleted file mode 100644 index 43a644b..0000000 --- a/puppet/simple-sinatra-app/manifests/init.pp +++ /dev/null @@ -1,74 +0,0 @@ -# == Class: simple-sinatra-app install rea example app from GitHub -class simple-sinatra-app { - include nginx - include unicorn - case $::operatingsystem { - 'Ubuntu': { - $root_path = '/opt/simple-sinatra-app' - $owner = 'www-data' - $group = 'www-data' - } - default: { fail('Unrecognized operating system') } - } - File { - owner => $owner, - group => $group, - } - exec { - 'get_app': - command => "/usr/bin/git clone git://github.com/tnh/simple-sinatra-app.git ${root_path}/app", - refreshonly => true, - notify => Exec['install_gem']; - 'install_gem': - command => '/usr/bin/bundle install --gemfile=/opt/simple-sinatra-app/app/Gemfile --path=/opt/simple-sinatra-app/app/', - refreshonly => true, - notify => Exec['set_unicorn'], - require => [Exec['get_app'],Package['ruby-bundler']]; - 'set_unicorn': - command => "/usr/bin/rails ${root_path}/app", - refreshonly => true, - require => Exec['get_app', 'install_gem']; - } - file { - $root_path: - ensure => directory, - mode => '0755'; - "${root_path}/app": - ensure => directory, - mode => '0755', - notify => Exec['get_app']; - '/etc/init/simple-sinatra-app.conf': - ensure => present, - mode => '0644', - owner => 'root', - group => 'root', - source => 'puppet:///modules/rea/init/simple-sinatra-init.conf', - require => Exec['get_app']; - '/etc/init.d/simple-sinatra-app': - ensure => symlink, - target => '/lib/init/upstart-job', - require => File['/etc/init/simple-sinatra-app.conf']; - '/etc/nginx/sites-available/simple-sinatra-app.conf': - ensure => present, - mode => '0644', - source => 'puppet:///modules/rea/nginx/simple-sinatra-nginx.conf', - require => Package[$nginx::packages, $unicorn::packages]; - '/etc/nginx/sites-enabled/simple-sinatra-app.conf': - ensure => symlink, - target => '/etc/nginx/sites-available/simple-sinatra-app.conf', - notify => Service[$nginx::service]; - "${root_path}/app/unicorn.rb": - ensure => present, - mode => '0644', - source => 'puppet:///modules/rea/opt/unicorn.rb', - require => Exec['set_unicorn']; - '/var/log/simple-sinatra-app/': - ensure => directory, - mode =>'0755'; - } - service { - 'simple-sinatra-app': - ensure => running, - hasstatus => true; - } -} diff --git a/puppet/unicorn/manifests/init.pp b/puppet/unicorn/manifests/init.pp deleted file mode 100644 index 7540872..0000000 --- a/puppet/unicorn/manifests/init.pp +++ /dev/null @@ -1,20 +0,0 @@ -# == Class: unicorn install unicorn gem package -# to add OS please edit the allowed OS -class unicorn { - case $::operatingsystem { - 'Ubuntu': { - $packages = 'ruby-bundler' - $rails = rails - } - default: { fail('Unrecognized operating system') } - } - package { - 'unicorn': - ensure => latest, - provider => gem; - $packages: - ensure => latest; - $rails: - ensure => latest; - } -} From d8f5f19775e531af36cb3bcdb36d1c4c1b2b06be Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Wed, 2 Apr 2014 21:28:44 +1100 Subject: [PATCH 13/38] adding new install for rea using apache and passanger --- puppet/manifests/init.pp | 7 +++ puppet/manifests/passanger.pp | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 puppet/manifests/init.pp create mode 100644 puppet/manifests/passanger.pp diff --git a/puppet/manifests/init.pp b/puppet/manifests/init.pp new file mode 100644 index 0000000..b632c31 --- /dev/null +++ b/puppet/manifests/init.pp @@ -0,0 +1,7 @@ +# Class: rea +# This module is installing test ruby app from rea test + +class rea { + #call the parts + incluse rea::passanger +} diff --git a/puppet/manifests/passanger.pp b/puppet/manifests/passanger.pp new file mode 100644 index 0000000..6b7c1bb --- /dev/null +++ b/puppet/manifests/passanger.pp @@ -0,0 +1,82 @@ +#class rea::passanger +#Install the passanger and it needed packages + +class rea::passanger { + FILE { + owner => 'root', + group => 'root', + } + + case $::operatingsystem { + 'CentOS', 'RedHat': { + exec { + 'import_stealthy_monkeys_gpg_key': + command => '/bin/rpm --import http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc', + creates => '/etc/yum.repos.d/stealthymonkeys.puppet', + refreshonly => true; + 'install_stealthymonkeys_repo': + command => '/usr/bin/yum install http://passenger.stealthymonkeys.com/rhel/6/passenger-release.noarch.rpm', + refreshonly => true, + creates => '/etc/yum.repos.d/passenger.repo', + require => Exec['import_stealthy_monkeys_gpg_key']; + 'install_httpd_module': + command => '/usr/bin/passenger-install-apache2-module', + refreshonly => true; + require => Package['mod_passenger']; + } + package { + ['git', 'ruby', 'rubygems', 'ruby-devel', 'gcc-c++', 'curl-devel', 'openssl-devel', 'zlib-devel', 'httpd-devel', 'apr-devel', 'apr-util-devel', 'httpd']: + ensure => latest; + 'mod_passenger': + ensure => latest, + require => Exec['install_stealthymonkeys_repo'], + notify => Exec['install_httpd_module']; + 'bundle': + ensure => latest, + require => Package['rubygems'], + provider => 'gem'; + } + service { + 'httpd': + ensure => running, + require => Package['httpd']; + } + } + 'Ubuntu': { + exec { + 'import_stealthy_monkeys_gpg_key': + command => '/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7', + creates => '/etc/apt/sources.list.d/stealthymonkeys.puppet', + refreshonly => true; + 'refresh_package_list': + command => '/usr/bin/apt-get update', + refreshonly => true; + require => File['/etc/apt/sources.list.d/passenger.list']; + } + file { + '/etc/apt/sources.list.d/passenger.list': + ensure => present, + mode => '0644', + content => "deb https://oss-binaries.phusionpassenger.com/apt/passenger $::lsbdistcodename main", + notify => Exec['refresh_package_list']; + } + package { + ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common']: + ensure => latest; + 'libapache2-mod-passenger': + ensure => latest; + require => File['/etc/apt/sources.list.d/passenger.list']; + 'bundle': + ensure => latest, + require => Package['rubygems'], + provider => 'gem'; + } + service { + 'apache2': + ensure => running, + require => Package['apache2.2-bin']; + } + } + default: { fail('Unrecognized operating system') } + } +} From d7570d0544771f9d36a14d636df61b3692c3fe0e Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Wed, 2 Apr 2014 21:33:36 +1100 Subject: [PATCH 14/38] enclosing the var in line 60 with {} --- puppet/manifests/passanger.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/manifests/passanger.pp b/puppet/manifests/passanger.pp index 6b7c1bb..e3f91fa 100644 --- a/puppet/manifests/passanger.pp +++ b/puppet/manifests/passanger.pp @@ -57,7 +57,7 @@ '/etc/apt/sources.list.d/passenger.list': ensure => present, mode => '0644', - content => "deb https://oss-binaries.phusionpassenger.com/apt/passenger $::lsbdistcodename main", + content => "deb https://oss-binaries.phusionpassenger.com/apt/passenger ${::lsbdistcodename} main", notify => Exec['refresh_package_list']; } package { From f4b035686bb5eca28152d1614a429fb2cc2f5c42 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Wed, 2 Apr 2014 21:35:48 +1100 Subject: [PATCH 15/38] add git package to Ubuntu OS package list --- puppet/manifests/passanger.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/manifests/passanger.pp b/puppet/manifests/passanger.pp index e3f91fa..0518902 100644 --- a/puppet/manifests/passanger.pp +++ b/puppet/manifests/passanger.pp @@ -61,7 +61,7 @@ notify => Exec['refresh_package_list']; } package { - ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common']: + ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common', 'git']: ensure => latest; 'libapache2-mod-passenger': ensure => latest; From 30524aa5ab2796c6f7e342c6607cfee995d5b182 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Wed, 2 Apr 2014 22:23:03 +1100 Subject: [PATCH 16/38] fix spelling mistake and change the sub module call to rea::simple-sinatra-app --- puppet/manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/manifests/init.pp b/puppet/manifests/init.pp index b632c31..3db5599 100644 --- a/puppet/manifests/init.pp +++ b/puppet/manifests/init.pp @@ -3,5 +3,5 @@ class rea { #call the parts - incluse rea::passanger + include rea::simple-sinatra-app } From 0f8d49b142675d6580e8c0251c4ae2bd9a32aeae Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Wed, 2 Apr 2014 22:23:48 +1100 Subject: [PATCH 17/38] add the install of simple-sinatra-app module --- puppet/manifests/simple-sinatra-app.pp | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 puppet/manifests/simple-sinatra-app.pp diff --git a/puppet/manifests/simple-sinatra-app.pp b/puppet/manifests/simple-sinatra-app.pp new file mode 100644 index 0000000..1b5c7ec --- /dev/null +++ b/puppet/manifests/simple-sinatra-app.pp @@ -0,0 +1,58 @@ +#class rea::simple-sinatra-app +#download and install simple-sinatra-app from rea + +class rea::simple-sinatra-app { + FILE { + owner => 'root', + group => 'root', + } + include rea::passanger + exec { + 'clone_rea': + command => '/usr/bin/git clone https://github.com/tnh/simple-sinatra-app.git /opt/simple-sinatra-app' + refreshonly => true, + require => Package['git'], + notify => Exec['install_rea']; + 'install rea': + command => 'bundle install --gemfile /opt/simple-sinatra-app/Gemfile', + refreshonly => true, + require => [Package['bundle'],Exec['clone_rea']]; + } + file { + '/var/www/simple-sinatra-app': + ensure => directory, + mode => '0755'; + '/var/www/simple-sinatra-app/public': + ensure => symlink, + target => '/opt/simple-sinatra-app/' + require => File['/var/www/simple-sinatra-app'], + notify => Exec['clone_rea']; + } + case $::operatingsystem { + 'CentOS', 'RedHat': { + file { + '/etc/httpd/conf.d/rea.conf': + ensure => present, + mode => '0644', + require => [Package['httpd'],File['/var/www/simple-sinatra-app/public']], + content => template('rea/httpd/rea.erb'), + notify => Service['httpd']; + } + } + 'Ubuntu':{ + file { + '/etc/apache2/sites-available/rea.conf': + ensure => present, + mode => '0644', + require => [Package['apache2.2-bin'],File['/var/www/simple-sinatra-app/public']], + content => template('rea/httpd/rea.erb'); + '/etc/apache2/sites-enabled/rea.conf' + ensure => symlink, + target => '/etc/apache2/sites-available/rea.conf', + require => File['/etc/apache2/sites-available/rea.conf'], + notify => Service['httpd']; + } + } + default: { fail('Unrecognized operating system') } + } +} From 3f38f450e4a1c16fcc6a400b3539dbda5e4de269 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 00:08:19 +1100 Subject: [PATCH 18/38] add httpd conf template --- puppet/templates/rea.erb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 puppet/templates/rea.erb diff --git a/puppet/templates/rea.erb b/puppet/templates/rea.erb new file mode 100644 index 0000000..9eb9420 --- /dev/null +++ b/puppet/templates/rea.erb @@ -0,0 +1,9 @@ +PassengerAppRoot /var/www/simple-sinatra-app/public + + ServerName <%= @fqdn %> + DocumentRoot /var/www/simple-sinatra-app/public + + AllowOverride all + Options -MultiViews + + From 43279cfb573120690aa772cfd6cb601d496f13e5 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 08:30:23 +1100 Subject: [PATCH 19/38] add apache reload command for apache serice restart --- puppet/manifests/passanger.pp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/puppet/manifests/passanger.pp b/puppet/manifests/passanger.pp index 0518902..f9af81a 100644 --- a/puppet/manifests/passanger.pp +++ b/puppet/manifests/passanger.pp @@ -39,6 +39,7 @@ service { 'httpd': ensure => running, + restart => '/sbin/service httpd reload', require => Package['httpd']; } } @@ -74,6 +75,7 @@ service { 'apache2': ensure => running, + restart => '/usr/sbin/service apache2 reload', require => Package['apache2.2-bin']; } } From d084ce7244f22d8217c8213f08cb1248b56bd8ff Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 09:07:03 +1100 Subject: [PATCH 20/38] moving the folders to the corect folder name and adding firewall rules --- puppet/rea/files/firewall/iptables.redhat | 10 ++++ puppet/rea/files/firewall/iptables.ubuntu | 14 +++++ puppet/rea/files/firewall/iptablesload.ubuntu | 3 ++ puppet/rea/files/firewall/iptablessave.ubuntu | 6 +++ puppet/rea/manifests/firewall.pp | 52 +++++++++++++++++++ puppet/{ => rea}/manifests/init.pp | 0 puppet/{ => rea}/manifests/passanger.pp | 0 .../{ => rea}/manifests/simple-sinatra-app.pp | 0 puppet/{ => rea}/templates/rea.erb | 0 9 files changed, 85 insertions(+) create mode 100644 puppet/rea/files/firewall/iptables.redhat create mode 100644 puppet/rea/files/firewall/iptables.ubuntu create mode 100644 puppet/rea/files/firewall/iptablesload.ubuntu create mode 100644 puppet/rea/files/firewall/iptablessave.ubuntu create mode 100644 puppet/rea/manifests/firewall.pp rename puppet/{ => rea}/manifests/init.pp (100%) rename puppet/{ => rea}/manifests/passanger.pp (100%) rename puppet/{ => rea}/manifests/simple-sinatra-app.pp (100%) rename puppet/{ => rea}/templates/rea.erb (100%) diff --git a/puppet/rea/files/firewall/iptables.redhat b/puppet/rea/files/firewall/iptables.redhat new file mode 100644 index 0000000..6b3a3e5 --- /dev/null +++ b/puppet/rea/files/firewall/iptables.redhat @@ -0,0 +1,10 @@ +*filter +:INPUT DROP [13:2613] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [49:5900] +-A INPUT -i lo -j ACCEPT +-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -p icmp -j ACCEPT +-A INPUT -p tcp -m tcp -m state --state NEW --dport 22 -j LOG +-A INPUT -p tcp -m tcp -m multiport --dports 22,80 -j ACCEPT +COMMIT diff --git a/puppet/rea/files/firewall/iptables.ubuntu b/puppet/rea/files/firewall/iptables.ubuntu new file mode 100644 index 0000000..c5eb34e --- /dev/null +++ b/puppet/rea/files/firewall/iptables.ubuntu @@ -0,0 +1,14 @@ +#!/bin/bash + +iptables -F INPUT +iptables -F OUTPUT +iptables -F FORWARD +iptables -P INPUT DROP +iptables -P OUTPUT ACCEPT +iptables -P FORWARD DROP + +iptables -A INPUT -i lo -j ACCEPT +iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT +iptables -A INPUT -p icmp -j ACCEPT +iptables -A INPUT -p tcp -m tcp -m state --state NEW --dport 22 -j LOG +iptables -A INPUT -p tcp -m tcp -m multiport --dports 22,80 -j ACCEPT diff --git a/puppet/rea/files/firewall/iptablesload.ubuntu b/puppet/rea/files/firewall/iptablesload.ubuntu new file mode 100644 index 0000000..6fb1ab0 --- /dev/null +++ b/puppet/rea/files/firewall/iptablesload.ubuntu @@ -0,0 +1,3 @@ +#!/bin/sh +iptables-restore < /etc/iptables.rules +exit 0 diff --git a/puppet/rea/files/firewall/iptablessave.ubuntu b/puppet/rea/files/firewall/iptablessave.ubuntu new file mode 100644 index 0000000..c74ee17 --- /dev/null +++ b/puppet/rea/files/firewall/iptablessave.ubuntu @@ -0,0 +1,6 @@ +#!/bin/sh +iptables-save -c > /etc/iptables.rules +if [ -f /etc/iptables.downrules ]; then + iptables-restore < /etc/iptables.downrules +fi +exit 0 diff --git a/puppet/rea/manifests/firewall.pp b/puppet/rea/manifests/firewall.pp new file mode 100644 index 0000000..0a979b3 --- /dev/null +++ b/puppet/rea/manifests/firewall.pp @@ -0,0 +1,52 @@ +#class rea::firewall +#This class will configure the firewall for the server + +class rea::firewall { + FILE { + owner => 'root', + group => 'root', + } + case $::operatingsystem { + 'CentOS', 'RedHat': { + file { + '/etc/sysconfig/iptables': + ensure => present, + mode => '0600', + source => 'file:///modules/rea/firewall/iptables.redhat', + notify => Service['iptables']; + } + service { + 'iptables': + ensure => running, + hasrestart => true; + } + } + 'Ubuntu': { + exec { + 'fix_rule': + command => 'sh -x /etc/iptables', + refreshonly => true, + notify => Exec['save_rules']; + 'save_rules': + command => 'sh -c "iptables-save > /etc/iptables.rules"', + refreshonly => true; + } + file { + '/etc/iptables': + ensure => present, + mode => '0600', + source => 'file:///modules/rea/firewall/iptables.ubuntu', + notify => Exec['fix_rule']; + '/etc/network/if-pre-up.d/iptablesload': + ensure => present, + mode => '0755', + source => 'file:///modules/rea/firewall/iptablesload.ubuntu'; + '/etc/network/if-post-down.d/iptablessave': + ensure => present, + mode => '0755', + source => 'file:///modules/rea/firewall/iptablessave.ubuntu'; + } + } + default: { fail('Unrecognized operating system') } + } +} diff --git a/puppet/manifests/init.pp b/puppet/rea/manifests/init.pp similarity index 100% rename from puppet/manifests/init.pp rename to puppet/rea/manifests/init.pp diff --git a/puppet/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp similarity index 100% rename from puppet/manifests/passanger.pp rename to puppet/rea/manifests/passanger.pp diff --git a/puppet/manifests/simple-sinatra-app.pp b/puppet/rea/manifests/simple-sinatra-app.pp similarity index 100% rename from puppet/manifests/simple-sinatra-app.pp rename to puppet/rea/manifests/simple-sinatra-app.pp diff --git a/puppet/templates/rea.erb b/puppet/rea/templates/rea.erb similarity index 100% rename from puppet/templates/rea.erb rename to puppet/rea/templates/rea.erb From b21b1ad6e979bfa4a26dbaed72054fb4ee85fa58 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 10:31:44 +1100 Subject: [PATCH 21/38] fix syntax --- puppet/rea/manifests/passanger.pp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/puppet/rea/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp index f9af81a..e2099e9 100644 --- a/puppet/rea/manifests/passanger.pp +++ b/puppet/rea/manifests/passanger.pp @@ -21,7 +21,7 @@ require => Exec['import_stealthy_monkeys_gpg_key']; 'install_httpd_module': command => '/usr/bin/passenger-install-apache2-module', - refreshonly => true; + refreshonly => true, require => Package['mod_passenger']; } package { @@ -39,7 +39,6 @@ service { 'httpd': ensure => running, - restart => '/sbin/service httpd reload', require => Package['httpd']; } } @@ -51,7 +50,7 @@ refreshonly => true; 'refresh_package_list': command => '/usr/bin/apt-get update', - refreshonly => true; + refreshonly => true, require => File['/etc/apt/sources.list.d/passenger.list']; } file { @@ -65,7 +64,7 @@ ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common', 'git']: ensure => latest; 'libapache2-mod-passenger': - ensure => latest; + ensure => latest, require => File['/etc/apt/sources.list.d/passenger.list']; 'bundle': ensure => latest, @@ -75,7 +74,6 @@ service { 'apache2': ensure => running, - restart => '/usr/sbin/service apache2 reload', require => Package['apache2.2-bin']; } } From d1e6141bd76ccdfe4957ae9ac9c7fac822cc3810 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 10:43:11 +1100 Subject: [PATCH 22/38] move the template to the correct location --- puppet/rea/templates/{ => httpd}/rea.erb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename puppet/rea/templates/{ => httpd}/rea.erb (100%) diff --git a/puppet/rea/templates/rea.erb b/puppet/rea/templates/httpd/rea.erb similarity index 100% rename from puppet/rea/templates/rea.erb rename to puppet/rea/templates/httpd/rea.erb From 3c308ec922731084984b3b2f16937c40369e41f1 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 10:45:52 +1100 Subject: [PATCH 23/38] fix exec name to install_rea from install rea --- puppet/rea/manifests/simple-sinatra-app.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/rea/manifests/simple-sinatra-app.pp b/puppet/rea/manifests/simple-sinatra-app.pp index 1b5c7ec..3626e99 100644 --- a/puppet/rea/manifests/simple-sinatra-app.pp +++ b/puppet/rea/manifests/simple-sinatra-app.pp @@ -13,7 +13,7 @@ refreshonly => true, require => Package['git'], notify => Exec['install_rea']; - 'install rea': + 'install_rea': command => 'bundle install --gemfile /opt/simple-sinatra-app/Gemfile', refreshonly => true, require => [Package['bundle'],Exec['clone_rea']]; From abc803f916afb32b95240ffea91863b433caf40f Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 10:49:44 +1100 Subject: [PATCH 24/38] fix the source from file: to puppet: --- puppet/rea/manifests/firewall.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/puppet/rea/manifests/firewall.pp b/puppet/rea/manifests/firewall.pp index 0a979b3..da7495e 100644 --- a/puppet/rea/manifests/firewall.pp +++ b/puppet/rea/manifests/firewall.pp @@ -12,7 +12,7 @@ '/etc/sysconfig/iptables': ensure => present, mode => '0600', - source => 'file:///modules/rea/firewall/iptables.redhat', + source => 'puppet:///modules/rea/firewall/iptables.redhat', notify => Service['iptables']; } service { @@ -35,16 +35,16 @@ '/etc/iptables': ensure => present, mode => '0600', - source => 'file:///modules/rea/firewall/iptables.ubuntu', + source => 'puppet:///modules/rea/firewall/iptables.ubuntu', notify => Exec['fix_rule']; '/etc/network/if-pre-up.d/iptablesload': ensure => present, mode => '0755', - source => 'file:///modules/rea/firewall/iptablesload.ubuntu'; + source => 'puppet:///modules/rea/firewall/iptablesload.ubuntu'; '/etc/network/if-post-down.d/iptablessave': ensure => present, mode => '0755', - source => 'file:///modules/rea/firewall/iptablessave.ubuntu'; + source => 'puppet:///modules/rea/firewall/iptablessave.ubuntu'; } } default: { fail('Unrecognized operating system') } From bfdef8d177a03ad219f944de4f5150fc5e59cd86 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 10:54:47 +1100 Subject: [PATCH 25/38] add call for F/W and the passanger --- puppet/rea/manifests/init.pp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/puppet/rea/manifests/init.pp b/puppet/rea/manifests/init.pp index 3db5599..1e2fb51 100644 --- a/puppet/rea/manifests/init.pp +++ b/puppet/rea/manifests/init.pp @@ -3,5 +3,7 @@ class rea { #call the parts + include rea::firewall + include rea::passanger include rea::simple-sinatra-app } From 93f84a422479f6e9c3716887e3f21d5f2adcd09d Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 10:58:36 +1100 Subject: [PATCH 26/38] fix package name from curl-devel to libcurl-devel --- puppet/rea/manifests/passanger.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/rea/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp index e2099e9..e84de40 100644 --- a/puppet/rea/manifests/passanger.pp +++ b/puppet/rea/manifests/passanger.pp @@ -25,7 +25,7 @@ require => Package['mod_passenger']; } package { - ['git', 'ruby', 'rubygems', 'ruby-devel', 'gcc-c++', 'curl-devel', 'openssl-devel', 'zlib-devel', 'httpd-devel', 'apr-devel', 'apr-util-devel', 'httpd']: + ['git', 'ruby', 'rubygems', 'ruby-devel', 'gcc-c++', 'libcurl-devel', 'openssl-devel', 'zlib-devel', 'httpd-devel', 'apr-devel', 'apr-util-devel', 'httpd']: ensure => latest; 'mod_passenger': ensure => latest, From 11219427a097dbc95042b7079181487e02f351d0 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 12:28:27 +1100 Subject: [PATCH 27/38] add add httpd to CentOS/RedHat startup --- puppet/rea/manifests/passanger.pp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/puppet/rea/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp index e84de40..60e7b85 100644 --- a/puppet/rea/manifests/passanger.pp +++ b/puppet/rea/manifests/passanger.pp @@ -23,9 +23,15 @@ command => '/usr/bin/passenger-install-apache2-module', refreshonly => true, require => Package['mod_passenger']; + 'add_httpd_to_startup' + command => '/sbin/chkconfig httpd on', + refreshonly => true; } package { - ['git', 'ruby', 'rubygems', 'ruby-devel', 'gcc-c++', 'libcurl-devel', 'openssl-devel', 'zlib-devel', 'httpd-devel', 'apr-devel', 'apr-util-devel', 'httpd']: + 'httpd': + ensure => latest, + notify => Exec['add_httpd_to_startup']; + ['git', 'ruby', 'rubygems', 'ruby-devel', 'gcc-c++', 'libcurl-devel', 'openssl-devel', 'zlib-devel', 'httpd-devel', 'apr-devel', 'apr-util-devel']: ensure => latest; 'mod_passenger': ensure => latest, From 20b575572b4c1916e1e07f9cd70672463cd2fe70 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 12:45:35 +1100 Subject: [PATCH 28/38] add the user and sudo modules --- puppet/rea/files/sudo/admin | 1 + puppet/rea/manifests/init.pp | 2 ++ puppet/rea/manifests/sudo.pp | 15 +++++++++++++++ puppet/rea/manifests/users.pp | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 puppet/rea/files/sudo/admin create mode 100644 puppet/rea/manifests/sudo.pp create mode 100644 puppet/rea/manifests/users.pp diff --git a/puppet/rea/files/sudo/admin b/puppet/rea/files/sudo/admin new file mode 100644 index 0000000..737aa89 --- /dev/null +++ b/puppet/rea/files/sudo/admin @@ -0,0 +1 @@ +%admin ALL=(ALL) NOPASSWD: ALL diff --git a/puppet/rea/manifests/init.pp b/puppet/rea/manifests/init.pp index 1e2fb51..c5c71b3 100644 --- a/puppet/rea/manifests/init.pp +++ b/puppet/rea/manifests/init.pp @@ -3,6 +3,8 @@ class rea { #call the parts + include rea::users + include rea::sudo include rea::firewall include rea::passanger include rea::simple-sinatra-app diff --git a/puppet/rea/manifests/sudo.pp b/puppet/rea/manifests/sudo.pp new file mode 100644 index 0000000..4678edc --- /dev/null +++ b/puppet/rea/manifests/sudo.pp @@ -0,0 +1,15 @@ +#class rea::sudo +#add sudo prmission for rea server + +class rea::sudo { + include rea::users + file { + '/etc/sudoers.d/admin': + ensure => presnet, + owner => 'root', + group => 'root', + mode => '0644', + require => Group['admin'], + source => 'puppet:///modules/rea/sudo/admin'; + } +} diff --git a/puppet/rea/manifests/users.pp b/puppet/rea/manifests/users.pp new file mode 100644 index 0000000..6be424f --- /dev/null +++ b/puppet/rea/manifests/users.pp @@ -0,0 +1,19 @@ +#class rea::users +#create the needed users and groups of managing the server +#default password: 7yhnmju87yhnmju8 + +class rea::users { + group { + 'rea-admin': + ensure => present, + gid => '3000'; + } + user { + 'radmin': + ensure => present, + uid => '4000', + groups => 'rea-admin', + password => '$6$TtvtDcX2$ktTNxIvL7b3Rv7X5JUb5zj9VnOXOUWYZ2fBf3148G.TqsY18GwH7VzIK..cu7FaAv4lK/5Fc9jw.xmYEPU/xF0', + comment => 'REA admin user'; + } +} From 604f112c9d2eb02b3381863a57e36da7e6b8656c Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 13:03:57 +1100 Subject: [PATCH 29/38] fix syntax errors --- puppet/rea/manifests/passanger.pp | 2 +- puppet/rea/manifests/simple-sinatra-app.pp | 6 +++--- puppet/rea/manifests/sudo.pp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/puppet/rea/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp index 60e7b85..ea48bb2 100644 --- a/puppet/rea/manifests/passanger.pp +++ b/puppet/rea/manifests/passanger.pp @@ -23,7 +23,7 @@ command => '/usr/bin/passenger-install-apache2-module', refreshonly => true, require => Package['mod_passenger']; - 'add_httpd_to_startup' + 'add_httpd_to_startup': command => '/sbin/chkconfig httpd on', refreshonly => true; } diff --git a/puppet/rea/manifests/simple-sinatra-app.pp b/puppet/rea/manifests/simple-sinatra-app.pp index 3626e99..283a311 100644 --- a/puppet/rea/manifests/simple-sinatra-app.pp +++ b/puppet/rea/manifests/simple-sinatra-app.pp @@ -9,7 +9,7 @@ include rea::passanger exec { 'clone_rea': - command => '/usr/bin/git clone https://github.com/tnh/simple-sinatra-app.git /opt/simple-sinatra-app' + command => '/usr/bin/git clone https://github.com/tnh/simple-sinatra-app.git /opt/simple-sinatra-app', refreshonly => true, require => Package['git'], notify => Exec['install_rea']; @@ -24,7 +24,7 @@ mode => '0755'; '/var/www/simple-sinatra-app/public': ensure => symlink, - target => '/opt/simple-sinatra-app/' + target => '/opt/simple-sinatra-app/', require => File['/var/www/simple-sinatra-app'], notify => Exec['clone_rea']; } @@ -46,7 +46,7 @@ mode => '0644', require => [Package['apache2.2-bin'],File['/var/www/simple-sinatra-app/public']], content => template('rea/httpd/rea.erb'); - '/etc/apache2/sites-enabled/rea.conf' + '/etc/apache2/sites-enabled/rea.conf': ensure => symlink, target => '/etc/apache2/sites-available/rea.conf', require => File['/etc/apache2/sites-available/rea.conf'], diff --git a/puppet/rea/manifests/sudo.pp b/puppet/rea/manifests/sudo.pp index 4678edc..a4d7c75 100644 --- a/puppet/rea/manifests/sudo.pp +++ b/puppet/rea/manifests/sudo.pp @@ -5,11 +5,11 @@ include rea::users file { '/etc/sudoers.d/admin': - ensure => presnet, + ensure => present, owner => 'root', group => 'root', mode => '0644', - require => Group['admin'], + require => Group['rea-admin'], source => 'puppet:///modules/rea/sudo/admin'; } } From 6e0d4d54c0f744a28447d49b006c05cad46b8412 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 13:04:51 +1100 Subject: [PATCH 30/38] fix group name --- puppet/rea/files/sudo/admin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet/rea/files/sudo/admin b/puppet/rea/files/sudo/admin index 737aa89..893cf4c 100644 --- a/puppet/rea/files/sudo/admin +++ b/puppet/rea/files/sudo/admin @@ -1 +1 @@ -%admin ALL=(ALL) NOPASSWD: ALL +%rea-admin ALL=(ALL) NOPASSWD: ALL From 82eb85fa591abe2d8ca437fcd2d2f7821bf93d5a Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 14:11:26 +1100 Subject: [PATCH 31/38] 1. add sshd config 2. ass selinux settings --- puppet/rea/files/selinux/config | 10 ++ puppet/rea/files/sshd/sshd_config.redhat | 137 +++++++++++++++++++++++ puppet/rea/files/sshd/sshd_config.ubuntu | 87 ++++++++++++++ puppet/rea/manifests/init.pp | 2 + puppet/rea/manifests/selinux.pp | 24 ++++ puppet/rea/manifests/sshd.pp | 30 +++++ 6 files changed, 290 insertions(+) create mode 100644 puppet/rea/files/selinux/config create mode 100644 puppet/rea/files/sshd/sshd_config.redhat create mode 100644 puppet/rea/files/sshd/sshd_config.ubuntu create mode 100644 puppet/rea/manifests/selinux.pp create mode 100644 puppet/rea/manifests/sshd.pp diff --git a/puppet/rea/files/selinux/config b/puppet/rea/files/selinux/config new file mode 100644 index 0000000..a8f59ba --- /dev/null +++ b/puppet/rea/files/selinux/config @@ -0,0 +1,10 @@ +# This file controls the state of SELinux on the system. +# SELINUX= can take one of these three values: +# enforcing - SELinux security policy is enforced. +# permissive - SELinux prints warnings instead of enforcing. +# disabled - No SELinux policy is loaded. +SELINUX=disabled +# SELINUXTYPE= can take one of these two values: +# targeted - Targeted processes are protected, +# mls - Multi Level Security protection. +SELINUXTYPE=targeted diff --git a/puppet/rea/files/sshd/sshd_config.redhat b/puppet/rea/files/sshd/sshd_config.redhat new file mode 100644 index 0000000..52a9186 --- /dev/null +++ b/puppet/rea/files/sshd/sshd_config.redhat @@ -0,0 +1,137 @@ +# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ + +# This is the sshd server system-wide configuration file. See +# sshd_config(5) for more information. + +# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin + +# The strategy used for options in the default sshd_config shipped with +# OpenSSH is to specify options with their default value where +# possible, but leave them commented. Uncommented options change a +# default value. + +Port 22 +#AddressFamily any +#ListenAddress 0.0.0.0 +#ListenAddress :: + +# Disable legacy (protocol version 1) support in the server for new +# installations. In future the default will change to require explicit +# activation of protocol 1 +Protocol 2 + +# HostKey for protocol version 1 +#HostKey /etc/ssh/ssh_host_key +# HostKeys for protocol version 2 +#HostKey /etc/ssh/ssh_host_rsa_key +#HostKey /etc/ssh/ssh_host_dsa_key + +# Lifetime and size of ephemeral version 1 server key +#KeyRegenerationInterval 1h +#ServerKeyBits 1024 + +# Logging +# obsoletes QuietMode and FascistLogging +#SyslogFacility AUTH +SyslogFacility AUTHPRIV +#LogLevel INFO + +# Authentication: + +#LoginGraceTime 2m +PermitRootLogin no +#StrictModes yes +#MaxAuthTries 6 +#MaxSessions 10 + +#RSAAuthentication yes +#PubkeyAuthentication yes +#AuthorizedKeysFile .ssh/authorized_keys +#AuthorizedKeysCommand none +#AuthorizedKeysCommandRunAs nobody + +# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts +#RhostsRSAAuthentication no +# similar for protocol version 2 +#HostbasedAuthentication no +# Change to yes if you don't trust ~/.ssh/known_hosts for +# RhostsRSAAuthentication and HostbasedAuthentication +#IgnoreUserKnownHosts no +# Don't read the user's ~/.rhosts and ~/.shosts files +#IgnoreRhosts yes + +# To disable tunneled clear text passwords, change to no here! +#PasswordAuthentication yes +#PermitEmptyPasswords no + +# Change to no to disable s/key passwords +#ChallengeResponseAuthentication yes +ChallengeResponseAuthentication no + +# Kerberos options +#KerberosAuthentication no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes +#KerberosGetAFSToken no +#KerberosUseKuserok yes + +# GSSAPI options +#GSSAPIAuthentication no +GSSAPIAuthentication yes +#GSSAPICleanupCredentials yes +GSSAPICleanupCredentials yes +#GSSAPIStrictAcceptorCheck yes +#GSSAPIKeyExchange no + +# Set this to 'yes' to enable PAM authentication, account processing, +# and session processing. If this is enabled, PAM authentication will +# be allowed through the ChallengeResponseAuthentication and +# PasswordAuthentication. Depending on your PAM configuration, +# PAM authentication via ChallengeResponseAuthentication may bypass +# the setting of "PermitRootLogin without-password". +# If you just want the PAM account and session checks to run without +# PAM authentication, then enable this but set PasswordAuthentication +# and ChallengeResponseAuthentication to 'no'. +#UsePAM no +UsePAM yes + +# Accept locale-related environment variables +AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES +AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT +AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE +AcceptEnv XMODIFIERS + +#AllowAgentForwarding yes +#AllowTcpForwarding yes +#GatewayPorts no +#X11Forwarding no +X11Forwarding yes +#X11DisplayOffset 10 +#X11UseLocalhost yes +#PrintMotd yes +#PrintLastLog yes +#TCPKeepAlive yes +#UseLogin no +#UsePrivilegeSeparation yes +#PermitUserEnvironment no +#Compression delayed +#ClientAliveInterval 0 +#ClientAliveCountMax 3 +#ShowPatchLevel no +#UseDNS yes +#PidFile /var/run/sshd.pid +#MaxStartups 10 +#PermitTunnel no +#ChrootDirectory none + +# no default banner path +#Banner none + +# override default of no subsystems +Subsystem sftp /usr/libexec/openssh/sftp-server + +# Example of overriding settings on a per-user basis +#Match User anoncvs +# X11Forwarding no +# AllowTcpForwarding no +# ForceCommand cvs server diff --git a/puppet/rea/files/sshd/sshd_config.ubuntu b/puppet/rea/files/sshd/sshd_config.ubuntu new file mode 100644 index 0000000..36689f8 --- /dev/null +++ b/puppet/rea/files/sshd/sshd_config.ubuntu @@ -0,0 +1,87 @@ +# Package generated configuration file +# See the sshd_config(5) manpage for details + +# What ports, IPs and protocols we listen for +Port 22 +# Use these options to restrict which interfaces/protocols sshd will bind to +#ListenAddress :: +#ListenAddress 0.0.0.0 +Protocol 2 +# HostKeys for protocol version 2 +HostKey /etc/ssh/ssh_host_rsa_key +HostKey /etc/ssh/ssh_host_dsa_key +HostKey /etc/ssh/ssh_host_ecdsa_key +#Privilege Separation is turned on for security +UsePrivilegeSeparation yes + +# Lifetime and size of ephemeral version 1 server key +KeyRegenerationInterval 3600 +ServerKeyBits 768 + +# Logging +SyslogFacility AUTH +LogLevel INFO + +# Authentication: +LoginGraceTime 120 +PermitRootLogin no +StrictModes yes + +RSAAuthentication yes +PubkeyAuthentication yes +#AuthorizedKeysFile %h/.ssh/authorized_keys + +# Don't read the user's ~/.rhosts and ~/.shosts files +IgnoreRhosts yes +# For this to work you will also need host keys in /etc/ssh_known_hosts +RhostsRSAAuthentication no +# similar for protocol version 2 +HostbasedAuthentication no +# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication +#IgnoreUserKnownHosts yes + +# To enable empty passwords, change to yes (NOT RECOMMENDED) +PermitEmptyPasswords no + +# Change to yes to enable challenge-response passwords (beware issues with +# some PAM modules and threads) +ChallengeResponseAuthentication no + +# Change to no to disable tunnelled clear text passwords +PasswordAuthentication yes + +# Kerberos options +#KerberosAuthentication no +#KerberosGetAFSToken no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes + +# GSSAPI options +#GSSAPIAuthentication no +#GSSAPICleanupCredentials yes + +X11Forwarding yes +X11DisplayOffset 10 +PrintMotd no +PrintLastLog yes +TCPKeepAlive yes +#UseLogin no + +#MaxStartups 10:30:60 +#Banner /etc/issue.net + +# Allow client to pass locale environment variables +AcceptEnv LANG LC_* + +Subsystem sftp /usr/lib/openssh/sftp-server + +# Set this to 'yes' to enable PAM authentication, account processing, +# and session processing. If this is enabled, PAM authentication will +# be allowed through the ChallengeResponseAuthentication and +# PasswordAuthentication. Depending on your PAM configuration, +# PAM authentication via ChallengeResponseAuthentication may bypass +# the setting of "PermitRootLogin without-password". +# If you just want the PAM account and session checks to run without +# PAM authentication, then enable this but set PasswordAuthentication +# and ChallengeResponseAuthentication to 'no'. +UsePAM yes diff --git a/puppet/rea/manifests/init.pp b/puppet/rea/manifests/init.pp index c5c71b3..81aa150 100644 --- a/puppet/rea/manifests/init.pp +++ b/puppet/rea/manifests/init.pp @@ -5,6 +5,8 @@ #call the parts include rea::users include rea::sudo + include rea::sshd + include rea::selinux include rea::firewall include rea::passanger include rea::simple-sinatra-app diff --git a/puppet/rea/manifests/selinux.pp b/puppet/rea/manifests/selinux.pp new file mode 100644 index 0000000..30b4a54 --- /dev/null +++ b/puppet/rea/manifests/selinux.pp @@ -0,0 +1,24 @@ +#class rea::selinux +#this class is disabling the selinux + +class rea::selinux { + case $::operatingsystem { + 'CentOS', 'RedHat': { + exec { + 'disable_selinux' : + command => '/usr/sbin/setenforce 0', + creates => '/etc/selinux/puppet.disable'; + } + file { + '/etc/selinux/config': + ensure => present, + owner => 'root', + group => 'root', + mode => '0644', + source => 'puppet:///modules/rea/selinux/config'; + } + } + 'Ubuntu': {} + default: { fail('Unrecognized operating system') } + } +} diff --git a/puppet/rea/manifests/sshd.pp b/puppet/rea/manifests/sshd.pp new file mode 100644 index 0000000..541250f --- /dev/null +++ b/puppet/rea/manifests/sshd.pp @@ -0,0 +1,30 @@ +#class rea::sshd +#this will change the default sshd.conf file to one that disable root ssh access + +class rea::sshd { + case $::operatingsystem { + 'CentOS', 'RedHat': { + $service_name = 'sshd' + $source_file = 'sshd_config.redhat' + } + 'Ubuntu': { + $service_name = 'sshd' + $source_file = 'sshd_config.ubuntu' + } + default: { fail('Unrecognized operating system') } + } + file { + '/etc/ssh/sshd_config': + ensure => present, + owner => 'root', + group => 'root', + mode => '0644', + source => "puppet:///modules/rea/sshd/${source_file}", + notify => Service["${service_name}"]; + } + service { + "${service_name}" : + ensure => running, + hasrestart => true; + } +} From e3c1cdff5623ba7b9e2df9da537f08e7b1de75f2 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 15:02:18 +1100 Subject: [PATCH 32/38] add how to use the module --- puppet/README.txt | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 puppet/README.txt diff --git a/puppet/README.txt b/puppet/README.txt new file mode 100644 index 0000000..0e9f3d6 --- /dev/null +++ b/puppet/README.txt @@ -0,0 +1,34 @@ +This file is how to use Oded Simon puppet module for: +REA site performance pre-interview task puppet module + +Assumptions: +1. The new server have on of the followings OSs RedHat, CentOS or Ubuntu +2. The new server get it IP and DNS setting from DHCP. +3. The new server can connect to the puppet master server. +4. The new server have access to the internet for downloading required packages and ruby gems. + +How to use this module +1. Install puppet agent using the script install_puppet_agent.sh from this repo. +2. Add the server to puppet master server. +3. Configure the new server to receive this module by adding the following to the node config: + node 'server name' { + include rea + } +4. run the puppet agent on the new server. + +This module will do the following: +1. Will create the group rea-admin, and will set it to have full sudo permissions. +2. Will create the user radmin, and add it to rea-admin group. +3. Will disable selinux on RedHat/CentOS servers. +4. Will set the iptables firewall to start at boot with the following settings: +4.1. INPUT, FORWARD chain policy is DROP. +4.2. OUTPUT chain policy is ACCEPT. +4.3. Allow tcp connection on port 22 (management via SSH), 80 (HTTP). +4.4. Allow all ICMP connections. +5. Install Apache and mod_passenger via RPM/DEB packages. +6. Pull the simple-sinatra-app from github, install require ruby gems and configure Apache server to server it on port 80. + + +What can be improved: +1. This module can be smarter by allowing the pull of the application to be variable, and as result it will be able to install additional ruby on rails application. +2. The passenger module can be enhance to use NameVirtualHost option for Apache server. From 0885b469c6c54316b704fb422b930a8f06ae052b Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 21:54:56 +1100 Subject: [PATCH 33/38] fix the CentOS/Redhat to work in one run --- puppet/rea/manifests/passanger.pp | 16 +++++++--------- puppet/rea/manifests/simple-sinatra-app.pp | 7 ++++--- puppet/rea/manifests/sshd.pp | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/puppet/rea/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp index ea48bb2..eb6e29f 100644 --- a/puppet/rea/manifests/passanger.pp +++ b/puppet/rea/manifests/passanger.pp @@ -9,6 +9,7 @@ case $::operatingsystem { 'CentOS', 'RedHat': { + $webserver = 'httpd' exec { 'import_stealthy_monkeys_gpg_key': command => '/bin/rpm --import http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc', @@ -19,24 +20,19 @@ refreshonly => true, creates => '/etc/yum.repos.d/passenger.repo', require => Exec['import_stealthy_monkeys_gpg_key']; - 'install_httpd_module': - command => '/usr/bin/passenger-install-apache2-module', - refreshonly => true, - require => Package['mod_passenger']; 'add_httpd_to_startup': command => '/sbin/chkconfig httpd on', refreshonly => true; } package { - 'httpd': + "$webserver": ensure => latest, notify => Exec['add_httpd_to_startup']; ['git', 'ruby', 'rubygems', 'ruby-devel', 'gcc-c++', 'libcurl-devel', 'openssl-devel', 'zlib-devel', 'httpd-devel', 'apr-devel', 'apr-util-devel']: ensure => latest; 'mod_passenger': ensure => latest, - require => Exec['install_stealthymonkeys_repo'], - notify => Exec['install_httpd_module']; + require => Exec['install_stealthymonkeys_repo']; 'bundle': ensure => latest, require => Package['rubygems'], @@ -49,6 +45,7 @@ } } 'Ubuntu': { + $webserver = 'apache2.2-bin' exec { 'import_stealthy_monkeys_gpg_key': command => '/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7', @@ -64,10 +61,11 @@ ensure => present, mode => '0644', content => "deb https://oss-binaries.phusionpassenger.com/apt/passenger ${::lsbdistcodename} main", + require => Exec['import_stealthy_monkeys_gpg_key'], notify => Exec['refresh_package_list']; } package { - ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common', 'git']: + ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common', 'git', 'apt-transport-https', 'ca-certificates']: ensure => latest; 'libapache2-mod-passenger': ensure => latest, @@ -80,7 +78,7 @@ service { 'apache2': ensure => running, - require => Package['apache2.2-bin']; + require => Package['apache2.2-common']; } } default: { fail('Unrecognized operating system') } diff --git a/puppet/rea/manifests/simple-sinatra-app.pp b/puppet/rea/manifests/simple-sinatra-app.pp index 283a311..3e2d7c7 100644 --- a/puppet/rea/manifests/simple-sinatra-app.pp +++ b/puppet/rea/manifests/simple-sinatra-app.pp @@ -21,7 +21,8 @@ file { '/var/www/simple-sinatra-app': ensure => directory, - mode => '0755'; + mode => '0755', + require => Package["$rea::passanger::webserver"]; '/var/www/simple-sinatra-app/public': ensure => symlink, target => '/opt/simple-sinatra-app/', @@ -44,13 +45,13 @@ '/etc/apache2/sites-available/rea.conf': ensure => present, mode => '0644', - require => [Package['apache2.2-bin'],File['/var/www/simple-sinatra-app/public']], + require => [Package['apache2.2-common'],File['/var/www/simple-sinatra-app/public']], content => template('rea/httpd/rea.erb'); '/etc/apache2/sites-enabled/rea.conf': ensure => symlink, target => '/etc/apache2/sites-available/rea.conf', require => File['/etc/apache2/sites-available/rea.conf'], - notify => Service['httpd']; + notify => Service['apache2']; } } default: { fail('Unrecognized operating system') } diff --git a/puppet/rea/manifests/sshd.pp b/puppet/rea/manifests/sshd.pp index 541250f..7f36f39 100644 --- a/puppet/rea/manifests/sshd.pp +++ b/puppet/rea/manifests/sshd.pp @@ -8,7 +8,7 @@ $source_file = 'sshd_config.redhat' } 'Ubuntu': { - $service_name = 'sshd' + $service_name = 'ssh' $source_file = 'sshd_config.ubuntu' } default: { fail('Unrecognized operating system') } From 0663a16b37f14ddb0149f0498c4f40362ec3823c Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 23:45:17 +1100 Subject: [PATCH 34/38] fix ubuntu to run in single run --- puppet/rea/manifests/passanger.pp | 20 ++++++++++++-------- puppet/rea/manifests/simple-sinatra-app.pp | 5 +++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/puppet/rea/manifests/passanger.pp b/puppet/rea/manifests/passanger.pp index eb6e29f..7f73939 100644 --- a/puppet/rea/manifests/passanger.pp +++ b/puppet/rea/manifests/passanger.pp @@ -41,16 +41,17 @@ service { 'httpd': ensure => running, - require => Package['httpd']; + require => Package["$webserver"]; } } 'Ubuntu': { - $webserver = 'apache2.2-bin' + $webserver = 'apache2.2-common' exec { 'import_stealthy_monkeys_gpg_key': command => '/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7', creates => '/etc/apt/sources.list.d/stealthymonkeys.puppet', - refreshonly => true; + refreshonly => true, + notify => Exec['refresh_package_list']; 'refresh_package_list': command => '/usr/bin/apt-get update', refreshonly => true, @@ -61,15 +62,18 @@ ensure => present, mode => '0644', content => "deb https://oss-binaries.phusionpassenger.com/apt/passenger ${::lsbdistcodename} main", - require => Exec['import_stealthy_monkeys_gpg_key'], - notify => Exec['refresh_package_list']; + notify => Exec['import_stealthy_monkeys_gpg_key']; } package { - ['ruby', 'ruby-dev', 'rubygems', 'apache2-utils', 'apache2.2-bin', 'apache2.2-common', 'git', 'apt-transport-https', 'ca-certificates']: + ["$webserver", 'apache2-utils', 'apache2.2-bin']: + ensure => latest, + notify => Service['apache2']; + ['ruby', 'ruby-dev', 'rubygems', 'git', 'apt-transport-https', 'ca-certificates']: ensure => latest; 'libapache2-mod-passenger': ensure => latest, - require => File['/etc/apt/sources.list.d/passenger.list']; + require => File['/etc/apt/sources.list.d/passenger.list'], + notify => Service['apache2']; 'bundle': ensure => latest, require => Package['rubygems'], @@ -78,7 +82,7 @@ service { 'apache2': ensure => running, - require => Package['apache2.2-common']; + require => Package["$webserver"]; } } default: { fail('Unrecognized operating system') } diff --git a/puppet/rea/manifests/simple-sinatra-app.pp b/puppet/rea/manifests/simple-sinatra-app.pp index 3e2d7c7..0a0ec0f 100644 --- a/puppet/rea/manifests/simple-sinatra-app.pp +++ b/puppet/rea/manifests/simple-sinatra-app.pp @@ -42,10 +42,15 @@ } 'Ubuntu':{ file { + '/etc/apache2/sites-enabled/000-default': + #remove the ubuntu default site + ensure => absent, + notify => Service['apache2']; '/etc/apache2/sites-available/rea.conf': ensure => present, mode => '0644', require => [Package['apache2.2-common'],File['/var/www/simple-sinatra-app/public']], + notify => File['/etc/apache2/sites-enabled/000-default'], content => template('rea/httpd/rea.erb'); '/etc/apache2/sites-enabled/rea.conf': ensure => symlink, From 787259ddf288a89c272d79b593bbb996a4c613f9 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 23:46:19 +1100 Subject: [PATCH 35/38] add install puppet script --- puppet/install_puppet_agent.sh | 111 +++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 puppet/install_puppet_agent.sh diff --git a/puppet/install_puppet_agent.sh b/puppet/install_puppet_agent.sh new file mode 100755 index 0000000..7a2f851 --- /dev/null +++ b/puppet/install_puppet_agent.sh @@ -0,0 +1,111 @@ +#/bin/bash + +usage () { + echo "This script install puppet agent and configure the agent" + echo "Usage:" + echo "$0 -s " + exit 3 +} +if [[ $# != 2 ]] +then + usage +fi + +#read the args +while getopts ":s:h" opt; do + case $opt in + s) + MASTER=$OPTARG + ;; + h) + usage + ;; + *) + usage + ;; + esac +done + +#is puppet configured +if [ -f /etc/puppet/puppet.conf ] +then + CHECKMASTER=`grep "server" /etc/puppet/puppet.conf |awk -F'=' '{print $2}'` + echo "puppet agent is already install and configure with" + echo "confiugre master server is $CHECKMASTER" + exit 0 +fi + +#Check the server OS +if [ ! -f /etc/redhat-release ] && [ ! -f /etc/lsb-release ] +then + echo "Error: can not detect the OS" + exit 1 +fi +if [ -f /etc/redhat-release ] +then + VER5=`grep 5\.[0-9] /etc/redhat-release` + VER6=`grep 6\.[0-9] /etc/redhat-release` + PROC=`uname -p` + if [ -z "$VER6" ] && [ -z "$VER5" ] + then + echo "Error: could not detect the RedHat/CentOS version" + exit 1 + fi + #add puppet repo + if [ "$PROC" == "x86_64" ] + then + if [ ! -z "$VER6" ] && [ -z "$VER5" ] + then + sudo rpm -ivh https://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm + fi + if [ -z "$VER6" ] && [ ! -z "$VER5" ] + then + sudo rpm -ivh https://yum.puppetlabs.com/el/5/products/x86_64/puppetlabs-release-5-7.noarch.rpm + fi + else + if [ ! -z "$VER6" ] && [ -z "$VER5" ] + then + sudo rpm -ivh https://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm + fi + if [ -z "$VER6" ] && [ ! -z "$VER5" ] + then + sudo rpm -ivh https://yum.puppetlabs.com/el/5/products/i386/puppetlabs-release-5-7.noarch.rpm + fi + fi + #install the agent + sudo yum -y install puppet + #add the service to startup + /sbin/chkconfig puppet on +fi +if [ -f /etc/lsb-release ] && [ ! -f /etc/redhat-release ] +then + VER=`grep DISTRIB_CODENAME /etc/lsb-release| awk -F'=' '{print $2}'` + wget https://apt.puppetlabs.com/puppetlabs-release-${VER}.deb + sudo dpkg -i puppetlabs-release-${VER}.deb + sudo apt-get update + sudo apt-get -y install puppet +fi +if [ -f /etc/puppet/puppet.conf ] +then + #edit the puppet.conf file + mv /etc/puppet/puppet.conf /etc/puppet/puppet.orig + echo "[main]" >>/etc/puppet/puppet.conf + echo " server=${MASTER}" >>/etc/puppet/puppet.conf + echo " pluginsync=true" >>/etc/puppet/puppet.conf + echo " logdir=/var/log/puppet" >>/etc/puppet/puppet.conf + echo " vardir=/var/lib/puppet" >>/etc/puppet/puppet.conf + echo " ssldir=/var/lib/puppet/ssl" >>/etc/puppet/puppet.conf + echo " rundir=/var/run/puppet" >>/etc/puppet/puppet.conf + echo " factpath=$vardir/lib/facter" >>/etc/puppet/puppet.conf + echo " templatedir=$confdir/templates" >>/etc/puppet/puppet.conf + echo "" >>/etc/puppet/puppet.conf + echo "[agent]" >>/etc/puppet/puppet.conf + echo " report = true" >>/etc/puppet/puppet.conf + echo " show_diff = true" >>/etc/puppet/puppet.conf + echo " runinterval = 3600" >>/etc/puppet/puppet.conf + #run the agent for the first time + sudo puppet agent --noop --test + #echo to add the node to the puppet master + echo "Please add the new server certificat to the puppet master and re run the agent" + exit 0 +fi From abc1ee4c8fe99d32919d403589d402888c951d2b Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 23:48:06 +1100 Subject: [PATCH 36/38] add the testing platform --- puppet/README.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/puppet/README.txt b/puppet/README.txt index 0e9f3d6..a9c4c2a 100644 --- a/puppet/README.txt +++ b/puppet/README.txt @@ -32,3 +32,7 @@ This module will do the following: What can be improved: 1. This module can be smarter by allowing the pull of the application to be variable, and as result it will be able to install additional ruby on rails application. 2. The passenger module can be enhance to use NameVirtualHost option for Apache server. + +Tested on: +CentOS 6.4 x64 +Ubuntu 12.04 LTS x64 From 929fe46eb5cd8efd931983ae6ea09b742580883e Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Thu, 3 Apr 2014 23:52:15 +1100 Subject: [PATCH 37/38] fix spelling --- puppet/README.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/puppet/README.txt b/puppet/README.txt index a9c4c2a..5620431 100644 --- a/puppet/README.txt +++ b/puppet/README.txt @@ -2,7 +2,7 @@ This file is how to use Oded Simon puppet module for: REA site performance pre-interview task puppet module Assumptions: -1. The new server have on of the followings OSs RedHat, CentOS or Ubuntu +1. The new server have one of the followings OSs RedHat, CentOS or Ubuntu 2. The new server get it IP and DNS setting from DHCP. 3. The new server can connect to the puppet master server. 4. The new server have access to the internet for downloading required packages and ruby gems. @@ -34,5 +34,5 @@ What can be improved: 2. The passenger module can be enhance to use NameVirtualHost option for Apache server. Tested on: -CentOS 6.4 x64 +CentOS 6.5 x64 Ubuntu 12.04 LTS x64 From c49432a2583599cab6de21c39247b495b15b80e5 Mon Sep 17 00:00:00 2001 From: "simonoded@gmail.com" Date: Sat, 5 Apr 2014 15:28:20 +1100 Subject: [PATCH 38/38] add check if the master puppet server is provided --- puppet/install_puppet_agent.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/puppet/install_puppet_agent.sh b/puppet/install_puppet_agent.sh index 7a2f851..1892cfc 100755 --- a/puppet/install_puppet_agent.sh +++ b/puppet/install_puppet_agent.sh @@ -34,6 +34,11 @@ then echo "confiugre master server is $CHECKMASTER" exit 0 fi +if [ -z $MASTER ] +then + echo "ERROR: puppet master is not provided." + usage +fi #Check the server OS if [ ! -f /etc/redhat-release ] && [ ! -f /etc/lsb-release ]