From dc5e8549b58f900572e98270981bc192eb449356 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 4 Jun 2012 15:05:38 -0400 Subject: [PATCH] even cleaner --- .ackrc | 2 + lib/puppet-standalone-mashup/capistrano.rb | 1 + .../debian-base/manifests/init.pp | 5 +- .../god/manifests/debian.pp | 14 ------ .../additional-modules/god/manifests/init.pp | 4 ++ .../god/templates/debian/resurrect | 8 ---- .../templates/redhat/init_d_prerun} | 0 .../god/templates/redhat/init_d_prolog | 6 +++ .../varnish/manifests/debian.pp | 34 ------------- .../varnish/manifests/init.pp | 48 +++++++++++++++---- .../varnish/manifests/redhat.pp | 17 ------- .../debian/{init-d-prerun => init_d_prerun} | 0 .../debian/{init-d-prolog => init_d_prolog} | 0 .../varnish/templates/redhat/init_d_prerun | 0 .../redhat/{init-d-prolog => init_d_prolog} | 0 .../varnish/templates/varnish-init.d | 4 +- shared/lib/facter/osfamily.rb | 14 ++++++ .../lib/puppet/parser/functions/bin_path.rb | 4 +- .../lib/puppet/parser/functions/build_path.rb | 2 +- .../puppet/parser/functions/config_path.rb | 2 +- .../lib/puppet/parser/functions/data_path.rb | 2 +- .../puppet/parser/functions/install_path.rb | 2 +- .../lib/puppet/parser/functions/log_path.rb | 2 +- .../lib/puppet/parser/functions/pid_path.rb | 2 +- .../lib/puppet/parser/functions/sbin_path.rb | 2 +- .../lib/puppet/parser/functions/share_path.rb | 2 +- .../puppet/parser/functions/symlink_path.rb | 2 +- .../lib/puppet/provider/god_init/install.rb | 1 + skel/apply.erb | 9 +++- 29 files changed, 92 insertions(+), 97 deletions(-) create mode 100644 .ackrc delete mode 100644 shared/additional-modules/god/manifests/debian.pp delete mode 100644 shared/additional-modules/god/templates/debian/resurrect rename shared/additional-modules/{varnish/templates/redhat/init-d-prerun => god/templates/redhat/init_d_prerun} (100%) create mode 100644 shared/additional-modules/god/templates/redhat/init_d_prolog delete mode 100644 shared/additional-modules/varnish/manifests/debian.pp delete mode 100644 shared/additional-modules/varnish/manifests/redhat.pp rename shared/additional-modules/varnish/templates/debian/{init-d-prerun => init_d_prerun} (100%) rename shared/additional-modules/varnish/templates/debian/{init-d-prolog => init_d_prolog} (100%) create mode 100644 shared/additional-modules/varnish/templates/redhat/init_d_prerun rename shared/additional-modules/varnish/templates/redhat/{init-d-prolog => init_d_prolog} (100%) create mode 100644 shared/lib/facter/osfamily.rb diff --git a/.ackrc b/.ackrc new file mode 100644 index 0000000..1f8d275 --- /dev/null +++ b/.ackrc @@ -0,0 +1,2 @@ +--type-add puppet=pp + diff --git a/lib/puppet-standalone-mashup/capistrano.rb b/lib/puppet-standalone-mashup/capistrano.rb index d0248cb..6f29551 100644 --- a/lib/puppet-standalone-mashup/capistrano.rb +++ b/lib/puppet-standalone-mashup/capistrano.rb @@ -34,6 +34,7 @@ Capistrano::Configuration.instance.load do _cset(:rename_server) { true } _cset(:use_sudo) { true } _cset(:additional_modules) { [] } + _cset(:additional_puppet_options) { '' } @dir_made = false diff --git a/shared/additional-modules/debian-base/manifests/init.pp b/shared/additional-modules/debian-base/manifests/init.pp index 8bf68a4..1dcfb92 100644 --- a/shared/additional-modules/debian-base/manifests/init.pp +++ b/shared/additional-modules/debian-base/manifests/init.pp @@ -22,7 +22,10 @@ class base { $share_path = "/usr/local/share" } -define init_d($init_d_prolog = '', $init_d_prerun = '') { +define init_d { + $init_d_prerun = template("${name}/${osfamily}/init_d_prerun") + $init_d_prolog = template("${name}/${osfamily}/init_d_prolog") + file { "/etc/init.d/${name}": content => template("${name}/${name}-init.d"), mode => 755 diff --git a/shared/additional-modules/god/manifests/debian.pp b/shared/additional-modules/god/manifests/debian.pp deleted file mode 100644 index 9415421..0000000 --- a/shared/additional-modules/god/manifests/debian.pp +++ /dev/null @@ -1,14 +0,0 @@ -class god::debian { - class { god: } - - init_d { 'god': - init_d_prolog => template('god/debian/init_d_prolog'), - init_d_prerun => template('god/debian/init_d_prerun'), - require => Class['god'] - } - - file { '/usr/local/sbin/resurrect': - content => template('god/debian/resurrect'), - mode => 755 - } -} diff --git a/shared/additional-modules/god/manifests/init.pp b/shared/additional-modules/god/manifests/init.pp index 340d723..c83a663 100644 --- a/shared/additional-modules/god/manifests/init.pp +++ b/shared/additional-modules/god/manifests/init.pp @@ -14,5 +14,9 @@ class god { file { [ $dir, $share ]: ensure => directory } + + init_d { 'god': + require => Gem['god'] + } } diff --git a/shared/additional-modules/god/templates/debian/resurrect b/shared/additional-modules/god/templates/debian/resurrect deleted file mode 100644 index ac63598..0000000 --- a/shared/additional-modules/god/templates/debian/resurrect +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -sudo killall god -sudo killall nginx -sudo killall thin -sudo killall php5-fpm -sudo service god start - diff --git a/shared/additional-modules/varnish/templates/redhat/init-d-prerun b/shared/additional-modules/god/templates/redhat/init_d_prerun similarity index 100% rename from shared/additional-modules/varnish/templates/redhat/init-d-prerun rename to shared/additional-modules/god/templates/redhat/init_d_prerun diff --git a/shared/additional-modules/god/templates/redhat/init_d_prolog b/shared/additional-modules/god/templates/redhat/init_d_prolog new file mode 100644 index 0000000..257993f --- /dev/null +++ b/shared/additional-modules/god/templates/redhat/init_d_prolog @@ -0,0 +1,6 @@ +# +# God +# +# chkconfig: - 85 15 +# description: start, stop, restart God (bet you feel powerful) +# diff --git a/shared/additional-modules/varnish/manifests/debian.pp b/shared/additional-modules/varnish/manifests/debian.pp deleted file mode 100644 index c1f1633..0000000 --- a/shared/additional-modules/varnish/manifests/debian.pp +++ /dev/null @@ -1,34 +0,0 @@ -class varnish::debian($version, $vcl, $store_file_mb = 1024) { - $user = 'varnish' - $group = 'varnish' - - user { $varnish_user: uid => 27835 } - - $packages = [ 'libpcre3', 'libpcre3-dev', 'pkg-config' ] - - package { $packages: ensure => installed } - - class { 'varnish': - version => $version, - require => Package[$packages], - vcl_template => $vcl - } - - init_d { 'varnish': - init_d_prolog => template('varnish/debian/init-d-prolog'), - init_d_prerun => template('varnish/debian/init-d-prerun'), - require => Class['varnish'] - } - - exec { 'ensure-data-store-ownership': - command => "chown -R ${user}:${group} ${varnish::data}", - path => $base::path, - require => Class['varnish'] - } - - logrotate_d { 'varnishncsa': - postrotate => 'service varnish rotate', - pattern => "${varnish::log}/access.log" - } -} - diff --git a/shared/additional-modules/varnish/manifests/init.pp b/shared/additional-modules/varnish/manifests/init.pp index 95d9c70..b01e562 100644 --- a/shared/additional-modules/varnish/manifests/init.pp +++ b/shared/additional-modules/varnish/manifests/init.pp @@ -1,4 +1,4 @@ -class varnish($version, $vcl_template, $store_file_mb = 1024) { +class varnish($version, $vcl, $user = 'varnish', $group = 'varnish', $store_file_mb = 1024) { $install_path = install_path($name, $version) $config = config_path($name) $share = share_path($name) @@ -19,17 +19,24 @@ class varnish($version, $vcl_template, $store_file_mb = 1024) { $store_file_path = "${data}/store" $store_file_size = $store_file_mb * 1024 * 1024 + $varnish_start = "service varnish start" + $varnish_stop = "service varnish stop" + $varnish_rotate = "service varnish rotate" + + $source = "http://repo.varnish-cache.org/source/varnish-${version}.tar.gz" + $dirs = [ $config, $log, $share, $data ] + build_and_install { $name: version => $version, - source => "http://repo.varnish-cache.org/source/varnish-<%= scope.lookupvar('version') %>.tar.gz" + source => $source } - mkdir_p { [ $config, $log, $share, $data ]: + mkdir_p { $dirs: path => $base::path, require => Build_and_install[$name] } - exec { 'create-store-file': + exec { "${name} create-store-file": command => "dd if=/dev/zero of=${store_file_path} bs=${store_file_size} count=1", timeout => 0, unless => "test -f ${store_file_path}", @@ -38,11 +45,8 @@ class varnish($version, $vcl_template, $store_file_mb = 1024) { logoutput => true } - $varnish_start = "service varnish start" - $varnish_stop = "service varnish stop" - file { $vcl_path: - content => $vcl_template, + content => $vcl, require => Build_and_install[$name] } @@ -56,4 +60,32 @@ class varnish($version, $vcl_template, $store_file_mb = 1024) { require => File[$vcl_path], interval => 10 } + + /* debian stuff */ + if ($osfamily == 'debian') { + user { $user: uid => 27835 } + + $packages = [ 'libpcre3', 'libpcre3-dev', 'pkg-config' ] + + package { $packages: + ensure => installed, + before => Build_and_install[$name] + } + + exec { 'ensure-data-store-ownership': + command => "chown -R ${user}:${group} ${data}", + path => $base::path, + require => Exec["${name} create-store-file"] + } + + logrotate_d { 'varnishncsa': + postrotate => 'service varnish rotate', + pattern => "${log}/access.log" + } + } + + init_d { $name: + require => Build_and_install[$name] + } } + diff --git a/shared/additional-modules/varnish/manifests/redhat.pp b/shared/additional-modules/varnish/manifests/redhat.pp deleted file mode 100644 index be9f023..0000000 --- a/shared/additional-modules/varnish/manifests/redhat.pp +++ /dev/null @@ -1,17 +0,0 @@ -class varnish::redhat($version, $user, $group, $vcl) { - $init_d_prolog = template('varnish/redhat/init-d-prolog') - $init_d_prerun = template('varnish/redhat/init-d-prerun') - - class { varnish: - vcl_template => $vcl, - version => $version - } - - $varnish_init_d = "${varnish::share}/varnish-init.d" - file { $varnish_init_d: - content => template('varnish/varnish-init.d'), - require => Mkdir_p[$varnish::share], - mode => 755 - } -} - diff --git a/shared/additional-modules/varnish/templates/debian/init-d-prerun b/shared/additional-modules/varnish/templates/debian/init_d_prerun similarity index 100% rename from shared/additional-modules/varnish/templates/debian/init-d-prerun rename to shared/additional-modules/varnish/templates/debian/init_d_prerun diff --git a/shared/additional-modules/varnish/templates/debian/init-d-prolog b/shared/additional-modules/varnish/templates/debian/init_d_prolog similarity index 100% rename from shared/additional-modules/varnish/templates/debian/init-d-prolog rename to shared/additional-modules/varnish/templates/debian/init_d_prolog diff --git a/shared/additional-modules/varnish/templates/redhat/init_d_prerun b/shared/additional-modules/varnish/templates/redhat/init_d_prerun new file mode 100644 index 0000000..e69de29 diff --git a/shared/additional-modules/varnish/templates/redhat/init-d-prolog b/shared/additional-modules/varnish/templates/redhat/init_d_prolog similarity index 100% rename from shared/additional-modules/varnish/templates/redhat/init-d-prolog rename to shared/additional-modules/varnish/templates/redhat/init_d_prolog diff --git a/shared/additional-modules/varnish/templates/varnish-init.d b/shared/additional-modules/varnish/templates/varnish-init.d index 6a7e864..09c54b3 100644 --- a/shared/additional-modules/varnish/templates/varnish-init.d +++ b/shared/additional-modules/varnish/templates/varnish-init.d @@ -3,8 +3,8 @@ <%= init_d_prolog %> <%= init_d_prerun %> -USER=<%= user %> -GROUP=<%= group %> +USER=<%= scope.lookupvar('varnish::user') %> +GROUP=<%= scope.lookupvar('varnish::group') %> start() { echo -n "Starting $NAME: " diff --git a/shared/lib/facter/osfamily.rb b/shared/lib/facter/osfamily.rb new file mode 100644 index 0000000..09ae279 --- /dev/null +++ b/shared/lib/facter/osfamily.rb @@ -0,0 +1,14 @@ +Facter.add("osfamily") do + setcode do + distid = Facter.value('lsbdistid') || Facter.value('operatingsystem') + case distid + when /RedHat|CentOS|Fedora/ + "redhat" + when "ubuntu" + "debian" + else + distid.downcase + end + end +end + diff --git a/shared/lib/puppet/parser/functions/bin_path.rb b/shared/lib/puppet/parser/functions/bin_path.rb index 26474f0..ba5ce29 100644 --- a/shared/lib/puppet/parser/functions/bin_path.rb +++ b/shared/lib/puppet/parser/functions/bin_path.rb @@ -2,9 +2,7 @@ require 'puppet/modules/common_directories' module Puppet::Parser::Functions newfunction(:bin_path, :type => :rvalue) do |args| - $stdout.puts args.inspect - - bin_path(lookupvar('base::install_path'), *args) + bin_path(lookupvar('::base::install_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/build_path.rb b/shared/lib/puppet/parser/functions/build_path.rb index d1cc0aa..f6ea080 100644 --- a/shared/lib/puppet/parser/functions/build_path.rb +++ b/shared/lib/puppet/parser/functions/build_path.rb @@ -2,7 +2,7 @@ require 'puppet/modules/common_directories' module Puppet::Parser::Functions newfunction(:build_path, :type => :rvalue) do |args| - build_path(lookupvar('base::src_path'), *args) + build_path(lookupvar('::base::src_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/config_path.rb b/shared/lib/puppet/parser/functions/config_path.rb index ed3d9c6..d86326c 100644 --- a/shared/lib/puppet/parser/functions/config_path.rb +++ b/shared/lib/puppet/parser/functions/config_path.rb @@ -1,5 +1,5 @@ module Puppet::Parser::Functions newfunction(:config_path, :type => :rvalue) do |args| - File.join(lookupvar('base::config_path'), *args) + File.join(lookupvar('::base::config_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/data_path.rb b/shared/lib/puppet/parser/functions/data_path.rb index c831936..99946df 100644 --- a/shared/lib/puppet/parser/functions/data_path.rb +++ b/shared/lib/puppet/parser/functions/data_path.rb @@ -1,6 +1,6 @@ module Puppet::Parser::Functions newfunction(:data_path, :type => :rvalue) do |args| - File.join(lookupvar('base::data_path'), *args) + File.join(lookupvar('::base::data_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/install_path.rb b/shared/lib/puppet/parser/functions/install_path.rb index bb7e0fa..f287ac5 100644 --- a/shared/lib/puppet/parser/functions/install_path.rb +++ b/shared/lib/puppet/parser/functions/install_path.rb @@ -2,7 +2,7 @@ require 'puppet/modules/common_directories' module Puppet::Parser::Functions newfunction(:install_path, :type => :rvalue) do |args| - install_path(lookupvar('base::install_path'), *args) + install_path(lookupvar('::base::install_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/log_path.rb b/shared/lib/puppet/parser/functions/log_path.rb index dc5b28a..d9e7227 100644 --- a/shared/lib/puppet/parser/functions/log_path.rb +++ b/shared/lib/puppet/parser/functions/log_path.rb @@ -1,6 +1,6 @@ module Puppet::Parser::Functions newfunction(:log_path, :type => :rvalue) do |args| - File.join(lookupvar('base::log_path'), *args) + File.join(lookupvar('::base::log_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/pid_path.rb b/shared/lib/puppet/parser/functions/pid_path.rb index 4684cb8..642e891 100644 --- a/shared/lib/puppet/parser/functions/pid_path.rb +++ b/shared/lib/puppet/parser/functions/pid_path.rb @@ -2,7 +2,7 @@ require 'puppet/modules/common_directories' module Puppet::Parser::Functions newfunction(:pid_path, :type => :rvalue) do |args| - pid_path(lookupvar('base::pid_path'), *args) + pid_path(lookupvar('::base::pid_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/sbin_path.rb b/shared/lib/puppet/parser/functions/sbin_path.rb index 448ff3e..e2f7735 100644 --- a/shared/lib/puppet/parser/functions/sbin_path.rb +++ b/shared/lib/puppet/parser/functions/sbin_path.rb @@ -1,7 +1,7 @@ require 'puppet/modules/common_directories' module Puppet::Parser::Functions newfunction(:sbin_path, :type => :rvalue) do |args| - sbin_path(lookupvar('base::install_path'), *args) + sbin_path(lookupvar('::base::install_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/share_path.rb b/shared/lib/puppet/parser/functions/share_path.rb index c4459e1..00a1691 100644 --- a/shared/lib/puppet/parser/functions/share_path.rb +++ b/shared/lib/puppet/parser/functions/share_path.rb @@ -1,6 +1,6 @@ module Puppet::Parser::Functions newfunction(:share_path, :type => :rvalue) do |args| - share_path(lookupvar('base::share_path'), *args) + share_path(lookupvar('::base::share_path'), *args) end end diff --git a/shared/lib/puppet/parser/functions/symlink_path.rb b/shared/lib/puppet/parser/functions/symlink_path.rb index d40daa8..4f2e2ea 100644 --- a/shared/lib/puppet/parser/functions/symlink_path.rb +++ b/shared/lib/puppet/parser/functions/symlink_path.rb @@ -2,7 +2,7 @@ require 'puppet/modules/common_directories' module Puppet::Parser::Functions newfunction(:symlink_path, :type => :rvalue) do |args| - symlink_path(lookupvar('base::install_path'), *args) + symlink_path(lookupvar('::base::install_path'), *args) end end diff --git a/shared/lib/puppet/provider/god_init/install.rb b/shared/lib/puppet/provider/god_init/install.rb index bb1b55b..43d59e5 100644 --- a/shared/lib/puppet/provider/god_init/install.rb +++ b/shared/lib/puppet/provider/god_init/install.rb @@ -57,6 +57,7 @@ God.watch do |w| w.interval = <%= interval %>.seconds w.start = lambda { system("<%= start %>") } + w.start_grace = <% interval %>.seconds <% if !stop.empty? %> w.stop = lambda { system("<%= stop %>") ; system("killall -9 <%= name %>") } diff --git a/skel/apply.erb b/skel/apply.erb index 598ae23..9e88d4d 100644 --- a/skel/apply.erb +++ b/skel/apply.erb @@ -1,5 +1,12 @@ #!/bin/bash mkdir -p ~/.puppet -<%= use_sudo ? "sudo env" : "" %> RUBYLIB="${PWD}/shared/lib" <%= with_additional_puppet_bin_path %> puppet apply --confdir=$PWD --modulepath=$PWD/modules:$PWD/shared/modules:$PWD/shared/additional-modules --templatedir=$PWD/shared/templates:$PWD/templates -v $@ manifests/site.pp +<%= use_sudo ? "sudo env" : "" %> RUBYLIB="${PWD}/shared/lib" \ + <%= with_additional_puppet_bin_path %> \ + puppet apply <%= additional_puppet_options %> \ + --confdir=$PWD \ + --modulepath=$PWD/modules:$PWD/shared/modules:$PWD/shared/additional-modules \ + --templatedir=$PWD/shared/templates:$PWD/templates \ + -v $@ \ + manifests/site.pp