even cleaner

This commit is contained in:
John Bintz 2012-06-04 15:05:38 -04:00
parent 5f5731868f
commit dc5e8549b5
29 changed files with 92 additions and 97 deletions

2
.ackrc Normal file
View File

@ -0,0 +1,2 @@
--type-add puppet=pp

View File

@ -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

View File

@ -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

View File

@ -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
}
}

View File

@ -14,5 +14,9 @@ class god {
file { [ $dir, $share ]:
ensure => directory
}
init_d { 'god':
require => Gem['god']
}
}

View File

@ -1,8 +0,0 @@
#!/bin/sh
sudo killall god
sudo killall nginx
sudo killall thin
sudo killall php5-fpm
sudo service god start

View File

@ -0,0 +1,6 @@
#
# God
#
# chkconfig: - 85 15
# description: start, stop, restart God (bet you feel powerful)
#

View File

@ -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"
}
}

View File

@ -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]
}
}

View File

@ -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
}
}

View File

@ -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: "

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 %>") }

View File

@ -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