This commit is contained in:
John Bintz 2012-05-03 09:31:41 -04:00
commit ba55ab4338
20 changed files with 331 additions and 118 deletions

View File

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

View File

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

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'] require => Make_and_install['ruby']
} }
$god_bin = "${base::install_path}/ruby/bin/god" $bin = "${base::install_path}/ruby/bin/god"
$god_dir = "${base::config_path}/god.d" $dir = config_path("god.d")
$pid_path = pid_path($name) $pid = pid_path($name)
$log = log_path($name)
$share = share_path($name)
file { '/etc/init.d/god': file { [ $dir, $share ]:
content => template('god/god-init.d'),
mode => 755
}
file { $god_dir:
ensure => directory 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

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

@ -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' require 'puppet/modules/common_directories'
module Puppet::Parser::Functions module Puppet::Parser::Functions
newfunction(:sbin_path, :type => :rvalue) do |args| newfunction(:sbin_path, :type => :rvalue) do |args|
sbin_path(lookupvar('base::install_path'), *args) sbin_path(lookupvar('base::install_path'), *args)
end end
end end

View File

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

View File

@ -3,6 +3,7 @@ Puppet::Type.type(:download_and_unpack).provide(:action) do
def create def create
system %{bash -c 'cd #{@resource[:src_path]} ; (curl #{@resource[:url]} | tar #{tar_command} -)'} system %{bash -c 'cd #{@resource[:src_path]} ; (curl #{@resource[:url]} | tar #{tar_command} -)'}
raise StandardError.new("Could not download") if $?.exitstatus != 0
end end
def destroy def destroy

View File

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