Merge branch 'master' of github.com:johnbintz/puppet-standalone-mashup

This commit is contained in:
John Bintz 2012-05-07 21:28:04 -04:00
commit 3ee80e88a4
31 changed files with 455 additions and 133 deletions

View File

@ -37,24 +37,24 @@ Capistrano::Configuration.instance.load do
run "cd #{base_dir} && #{sudo} rm -Rf #{apps}"
end
desc "Apply the configuration"
task :apply do
desc "Copy files to the remote server"
task :copy_files do
top.copy
top.copy_shared
top.copy_skel
end
desc "Apply the configuration"
task :apply do
top.copy_files
run "cd #{puppet_dir} && #{sudo} ./apply"
end
desc "Bootstrap the server"
task :bootstrap do
top.copy
top.copy_shared
top.copy_skel
if rename_server
top.rename
end
top.copy_files
top.rename if rename_server
run "cd #{puppet_dir} && #{sudo} ./bootstrap"
end

View File

@ -0,0 +1,25 @@
Capistrano::Configuration.instance.load do
server '127.0.0.1:2222', :vagrant
ssh_options[:port] = 2222
set(:user) { 'vagrant' }
set(:password) { 'vagrant' }
task :ensure_puppet do
require 'socket'
begin
p = TCPSocket.new('localhost', 2222)
p.close
rescue Errno::ECONNREFUSED
system %{vagrant up}
p = TCPSocket.new('localhost', 2222)
p.close
end
end
before 'apply', 'ensure_puppet'
before 'bootstrap', 'ensure_puppet'
end

View File

@ -11,7 +11,9 @@ class base {
$install_path = "/usr/local"
$config_path = "/etc"
$pid_path = "/var/run"
$log_path = "/var/log"
$local_path = $install_path
$share_path = "/usr/local/share"
}
node default {

View File

@ -0,0 +1,32 @@
class god-debian {
class { god: }
$init_d_prolog = template('god-debian/init_d_prolog')
$init_d_prerun = template('god-debian/init_d_prerun')
$god_init_d = "${base::share_path}/god/god-init.d"
file { $god_init_d:
content => template('god/god-init.d'),
require => File[$god::share],
mode => 755
}
file { 'etc/init.d/god':
ensure => $god_init_d,
require => Class['god']
}
update_rc_d_defaults { 'god':
require => File['/etc/init.d/god']
}
running_service { 'god':
require => Update_rc_d_defaults['god']
}
file { '/usr/local/sbin/resurrect':
content => template('god-debian/resurrect'),
mode => 755
}
}

View File

@ -0,0 +1,6 @@
set -e
# Make sure the binary and the config file are present before proceeding
test -x <%= god_bin %> || exit 0
. /lib/lsb/init-functions

View File

@ -0,0 +1,9 @@
### BEGIN INIT INFO
# Provides: god
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God
### END INIT INFO

View File

@ -5,30 +5,14 @@ class god {
require => Make_and_install['ruby']
}
$god_bin = "${base::install_path}/ruby/bin/god"
$god_dir = "${base::config_path}/god.d"
$pid_path = pid_path($name)
$bin = "${base::install_path}/ruby/bin/god"
$dir = config_path("god.d")
$pid = pid_path($name)
$log = log_path($name)
$share = share_path($name)
file { '/etc/init.d/god':
content => template('god/god-init.d'),
mode => 755
}
file { $god_dir:
file { [ $dir, $share ]:
ensure => directory
}
update_rc_d_defaults { $name:
require => File['/etc/init.d/god']
}
running_service { $name:
require => Update_rc_d_defaults[$name]
}
file { '/usr/local/sbin/resurrect':
content => template('god/resurrect'),
mode => 755
}
}

View File

@ -1,82 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: god
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God
### END INIT INFO
PATH=/usr/local/ruby/bin:<%= scope.lookupvar('base::path') %>
NAME=god
DESC=god
set -e
# Make sure the binary and the config file are present before proceeding
test -x <%= god_bin %> || exit 0
. /lib/lsb/init-functions
RETVAL=0
PID_PATH=<%= pid_path %>
start() {
echo -n "Starting $DESC: "
rm -f $PID_PATH
<%= god_bin %> -P $PID_PATH -l /var/log/god.log
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
sleep 2
if [ -d <%= god_dir %> ]; then
for file in $(find <%= god_dir %> -name "*.god"); do
echo "god: loading $file ..."
<%= god_bin %> load $file
done
fi
fi
echo "$NAME."
return $RETVAL
}
stop() {
echo -n "Stopping $DESC: "
if [ -f $PID_PATH ]; then
kill `cat $PID_PATH`
rm $PID_PATH
fi
killall -9 <%= god_bin %> || true
echo "$NAME."
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
<%= god_bin %> status
RETVAL=$?
;;
*)
echo "Usage: god {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL

View File

@ -0,0 +1,80 @@
#!/bin/bash
<%= init_d_prolog %>
PATH=/usr/local/ruby/bin:<%= scope.lookupvar('base::path') %>
NAME=god
DESC=god
BIN=<%= scope.lookupvar('god::bin') %>
PID=<%= scope.lookupvar('god::pid') %>
DIR=<%= scope.lookupvar('god::dir') %>
LOG=<%= scope.lookupvar('god::log') %>
<%= init_d_prerun %>
RETVAL=0
start() {
echo -n "Starting $DESC: "
rm -f $PID
$BIN -P $PID -l $LOG
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
sleep 2
if [ -d $DIR ]; then
for file in $(find $DIR -name "*.god"); do
echo "$NAME: loading $file ..."
$BIN load $file
done
fi
fi
echo "$NAME."
return $RETVAL
}
stop() {
echo -n "Stopping $DESC: "
if [ -f $PID ]; then
kill `cat $PID`
rm $PID
fi
killall -9 $BIN || true
echo "$NAME."
return 0
}
status_q() {
test -f $PID
}
case "$1" in
start)
status_q && exit 0
start
;;
stop)
status_q || exit 0
stop
;;
restart)
status_q
if [ $? -eq 0 ]; then stop; fi
start
;;
status)
$BIN status
RETVAL=$?
;;
*)
echo "Usage: $NAME {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL

View File

@ -32,7 +32,6 @@ class nginx($version, $max_pool_size = 20) {
restart => "${nginx_stop} ; ${nginx_start}",
pid_file => $pid_file,
ensure => present,
notify => Service['god'],
require => Exec['install-passenger']
}

View File

@ -1,11 +1,12 @@
class ruby($version) {
class ruby($version, $configure = "--disable-install-doc", $build_path = '') {
$path = bin_path($name)
$with_ruby_path = "${path}:${base::path}"
build_and_install { $name:
version => $version,
source => "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-<%= version %>.tar.gz",
configure => "--disable-install-doc"
configure => $configure,
path => "${base::path}:${path}:${build_path}"
}
gem { [ 'bundler', 'penchant' ]:

View File

@ -0,0 +1,15 @@
class varnish-default-vcl {
$backend_port = '8080'
$assets_age = 86400
$no_ttl_time = "10m"
$healthy_grace_time = "1m"
$sick_grace_time = "24h"
$probe_interval = "3s"
file { $varnish::vcl_path:
content => template('varnish-default-vcl/default.vcl'),
require => [ Build_and_install[$name], Mkdir_p[$config_path] ],
}
}

View File

@ -0,0 +1,56 @@
class varnish($version, $store_file_mb = 1024) {
$install_path = install_path($name, $version)
$pid = pid_path($name)
$log = log_path($name)
$config = config_path($name)
$share = share_path($name)
$data = data_path($name)
$bin = "${name}d"
$sysconfig_dir = "${config}/sysconfig"
$vcl_path = "${config}/default.vcl"
$override_config = "${sysconfig_dir}/${name}"
$store_file_path = "${data}/store"
$store_file_size = $store_file_mb * 1024 * 1024
$backend_port = '8080'
$assets_age = 86400
$no_ttl_time = "10m"
$healthy_grace_time = "1m"
$sick_grace_time = "24h"
$probe_interval = "3s"
build_and_install { $name:
version => $version,
source => "http://repo.varnish-cache.org/source/varnish-<%= scope.lookupvar('version') %>.tar.gz"
}
mkdir_p { [ $config, $share, $sysconfig_dir, $data ]:
path => $base::path,
require => Build_and_install[$name]
}
file { $varnish::vcl_path:
content => template('varnish-redhat/default.vcl'),
require => [ Mkdir_p[$config] ]
}
file { $override_config:
ensure => present,
mode => 644,
content => template('varnish/defaults'),
require => Mkdir_p[$sysconfig_dir],
}
exec { '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}",
path => $base::path,
require => Mkdir_p[$data],
logoutput => true
}
}

View File

@ -0,0 +1,11 @@
VARNISH_LISTEN_ADDRESS=0.0.0.0
VARNISH_LISTEN_PORT=80
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
DAEMON_OPTS="\
-T 127.0.0.1:6082 \
-u ${VARNISH_USERNAME} -g ${VARNISH_PASSWORD} \
-w 1,1,3600 \
-f ${VARNISH_VCL_CONF} \
-s ${VARNISH_BACKEND_STORE} \
"

View File

@ -0,0 +1,82 @@
#!/bin/sh
<%= init_d_prolog %>
NAME=varnish
DESC=varnish
BIN=<%= scope.lookupvar('varnish::bin') %>
PID=<%= scope.lookupvar('varnish::pid') %>
LOG=<%= scope.lookupvar('varnish::log') %>
OVERRIDE_CONFIG=<%= scope.lookupvar('varnish::override_config') %>
<%= init_d_prerun %>
RETVAL=0
VARNISH_VCL_CONF=<%= scope.lookupvar('varnish::vcl_path') %>
VARNISH_BACKEND_STORE="file,<%= scope.lookupvar('varnish::store_file_path') %>,<%= scope.lookupvar('varnish::store_file_size') %>"
VARNISH_USERNAME=<%= username %>
VARNISH_PASSWORD=<%= password %>
# Include varnish defaults
[ -e $OVERRIDE_CONFIG ] && . $OVERRIDE_CONFIG
start() {
echo -n "Starting $DESC: "
rm -Rf $PID
ulimit -n ${NFILES:-131072}
ulimit -l ${MEMLOCK:-82000}
# Varnish always gives output on STDOUT
$BIN -P $pidfile "$DAEMON_OPTS" > /dev/null 2>&1
echo "$NAME."
RETVAL=$?
return $RETVAL
}
stop() {
echo -n "Stopping $DESC: "
if [ -f $PID ]; then
kill `cat $PID`
rm $PID
fi
killall -9 $VARNISH || true
echo "$NAME."
return 0
}
status_q() {
test -f $PID
}
configtest() {
$BIN -f "$VARNISH_VCL_CONF" -C -n /tmp > /dev/null && echo "Syntax ok"
}
# See how we were called.
case "$1" in
start)
status_q && exit 0
$1
;;
stop)
status_q || exit 0
$1
;;
restart)
status_q
if [ $? -eq 0 ]; then stop; fi
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 2
esac
exit $?

View File

@ -24,6 +24,10 @@ module Puppet
def pid_path(pid_path, name)
File.join(pid_path, "#{name}.pid")
end
def share_path(share_path, name)
File.join(share_path, name)
end
end
end
end

View File

@ -0,0 +1,5 @@
module Puppet::Parser::Functions
newfunction(:config_path, :type => :rvalue) do |args|
File.join(lookupvar('base::config_path'), *args)
end
end

View File

@ -0,0 +1,6 @@
module Puppet::Parser::Functions
newfunction(:data_path, :type => :rvalue) do |args|
File.join(lookupvar('base::data_path'), *args)
end
end

View File

@ -0,0 +1,6 @@
module Puppet::Parser::Functions
newfunction(:log_path, :type => :rvalue) do |args|
File.join(lookupvar('base::log_path'), *args)
end
end

View File

@ -1,9 +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)
end
end

View File

@ -0,0 +1,6 @@
module Puppet::Parser::Functions
newfunction(:share_path, :type => :rvalue) do |args|
share_path(lookupvar('base::share_path'), *args)
end
end

View File

@ -2,7 +2,7 @@ Puppet::Type.type(:configure).provide(:action) do
desc "Configure a program to install"
def create
system %{bash -c '#{path} cd #{@resource[:build_path]} ; ./configure --prefix=#{@resource[:install_path]} #{@resource[:options]}'}.tap { |o| p o }
system %{bash -c '#{path} cd #{@resource[:build_path]} ; #{@resource[:preconfigure]} ./configure --prefix=#{@resource[:install_path]} #{@resource[:options]}'}.tap { |o| p o }
end
def destroy
@ -10,7 +10,9 @@ Puppet::Type.type(:configure).provide(:action) do
end
def exists?
File.file? config_status
return true if unless?
File.file?(config_status)
end
private
@ -18,6 +20,13 @@ Puppet::Type.type(:configure).provide(:action) do
File.join(@resource[:build_path], @resource[:config_status])
end
def unless?
return nil if @resource[:unless].empty?
system %{bash -c '#{@resource[:unless]}'}
$?.exitstatus == 0
end
def path
@resource[:path].empty? ? '' : "export PATH=#{@resource[:path]}:$PATH ; "
end

View File

@ -2,26 +2,49 @@ Puppet::Type.type(:download_and_unpack).provide(:action) do
desc "Download an unpack a remote repository"
def create
system %{bash -c 'cd #{@resource[:src_path]} ; (curl #{@resource[:url]} | tar #{tar_command} -)'}
system %{bash -c 'mkdir -p #{@resource[:src_path]} ; cd #{@resource[:src_path]} ; (curl -L #{@resource[:url]} | tar #{tar_command} -)'}
raise StandardError.new("Could not download") if $?.exitstatus != 0
if original_name
system %{bash -c 'cd #{@resource[:src_path]} && mv #{original_name} #{target_dir}'}
end
end
def destroy
FileUtils.rm_rf dir
FileUtils.rm_rf target_dir
end
def exists?
File.directory?(dir)
return true if unless?
File.directory?(File.join(@resource[:src_path], target_dir))
end
private
def unless?
return nil if @resource[:unless].empty?
system %{bash -c '#{@resource[:unless]}'}
$?.exitstatus == 0
end
def file
File.join(@resource[:src_path], File.basename(@resource[:url]))
end
def target_dir
"#{@resource[:name]}-#{@resource[:version]}"
end
def dir
file.gsub(%r{\.tar\.(gz|bz2)$}, '')
end
def original_name
(@resource[:original_name] || '').empty? ? nil : @resource[:original_name]
end
def tar_command
case @resource[:url]
when /\.gz/

View File

@ -16,10 +16,19 @@ Puppet::Type.type(:make_and_install).provide(:action) do
end
def exists?
return true if unless?
File.directory?(@resource[:install_path]) && File.symlink?(symlink_path)
end
private
def unless?
return nil if @resource[:unless].empty?
system %{bash -c '#{@resource[:unless]}'}
$?.exitstatus == 0
end
def symlink_path
File.join(File.dirname(@resource[:install_path]), @resource[:name])
end

View File

@ -19,6 +19,10 @@ Puppet::Type.newtype(:configure) do
desc "Options to build the software"
end
newparam(:preconfigure) do
desc "Options to go before the configure command, like environment variables"
end
newparam(:config_status) do
desc "Relative location of config.status"
end
@ -26,5 +30,9 @@ Puppet::Type.newtype(:configure) do
newparam(:path) do
desc "Path for executables"
end
newparam(:unless) do
desc "If provided, don't run the configure unless this condition is true"
end
end

View File

@ -18,5 +18,13 @@ Puppet::Type.newtype(:download_and_unpack) do
newparam(:version) do
desc "The version to install"
end
newparam(:original_name) do
desc "The directory name that the software unpacks as"
end
newparam(:unless) do
desc "If provided, don't run the download unless this condition is true"
end
end

View File

@ -22,5 +22,9 @@ Puppet::Type.newtype(:make_and_install) do
newparam(:path) do
desc "Binary path to add"
end
newparam(:unless) do
desc "If provided, don't run the make and install unless this condition is true"
end
end

View File

@ -1,4 +1,4 @@
define build_and_install($version, $source, $path = '', $configure = '', $config_status = 'config.status') {
define build_and_install($version, $preconfigure = '', $original_name = '', $source, $path = '', $configure = '', $config_status = 'config.status', $unless = '') {
$full_source = inline_template($source)
$build_path = build_path($name, $version)
@ -8,17 +8,22 @@ define build_and_install($version, $source, $path = '', $configure = '', $config
download_and_unpack { $name:
url => $full_source,
src_path => $base::src_path,
ensure => present
original_name => $original_name,
version => $version,
ensure => present,
unless => $unless
}
configure { $name:
build_path => $build_path,
install_path => $install_path,
options => $configure,
preconfigure => $preconfigure,
path => $path,
require => Download_and_unpack[$name],
config_status => $config_status,
ensure => present
ensure => present,
unless => $unless
}
make_and_install { $name:
@ -26,7 +31,8 @@ define build_and_install($version, $source, $path = '', $configure = '', $config
install_path => $install_path,
path => $path,
require => Configure[$name],
ensure => present
ensure => present,
unless => $unless
}
}

View File

@ -1,3 +0,0 @@
define init_d($template) {
}

View File

@ -8,7 +8,20 @@ if [ ! -f ${base_dir}/ruby-base/bin/ruby ]; then
mkdir -p ${base_dir}/tmp
cd ${base_dir}/tmp
RUBY=ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.2-p290.tar.bz2
opt_dir=${base_dir}/tmp/ruby-opt
rm -Rf yaml-0.1.4*
curl -O http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar zxvf yaml-0.1.4.tar.gz
mv yaml-0.1.4 yaml-0.1.4-base
cd yaml-0.1.4-base
./configure --prefix=${opt_dir}
make
make install
cd ..
RUBY=ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.3-p194.tar.bz2
RUBY_FILENAME=${RUBY##*/}
RUBY_VERSION=${RUBY_FILENAME%%.tar.bz2}
curl $RUBY > $RUBY_FILENAME
@ -18,7 +31,7 @@ if [ ! -f ${base_dir}/ruby-base/bin/ruby ]; then
cd "$RUBY_VERSION-base"
./configure --prefix=${base_dir}/ruby-base --disable-pthread
./configure --prefix=${base_dir}/ruby-base --with-opt-dir=${opt_dir} --disable-pthread --disable-install-doc
make
make install
@ -32,7 +45,7 @@ PATH=${base_dir}/ruby-base/bin:$PATH
if [ ! -f ${base_dir}/ruby-base/bin/puppet ]; then
echo "Installing Puppet..."
gem install puppet
gem install puppet --no-ri --no-rdoc
fi
mkdir -p ~/.puppet