rearrange all the things

This commit is contained in:
John Bintz 2012-05-14 09:15:05 -04:00
parent cf9406f84c
commit 3d37477eb5
20 changed files with 212 additions and 115 deletions

View File

@ -104,7 +104,7 @@ Capistrano::Configuration.instance.load do
run "mkdir -p #{puppet_dir}/shared/additional-modules"
(%w{lib modules} + additional_modules.collect { |dir| "additional-modules/#{dir}" }).each do |dir|
(%w{lib modules templates} + additional_modules.collect { |dir| "additional-modules/#{dir}" }).each do |dir|
top.upload PuppetStandaloneMashup::BASE.join('shared', dir).to_s, File.join(puppet_dir, 'shared', dir)
end
end

View File

@ -15,7 +15,25 @@ class base {
$log_path = "/var/log"
$local_path = $install_path
$share_path = "/usr/local/share"
$data_path = "/var/data"
}
define init_d($init_d_prolog = '', $init_d_prerun = '') {
file { "/etc/init.d/${name}":
content => template("${name}/${name}-init.d"),
mode => 755
}
$update_rc_d = "update-rc.d ${name}"
exec { $update_rc_d:
command => "update-rc.d ${name} defaults",
require => File["/etc/init.d/${name}"],
path => $base::path
}
service { $name:
require => Exec[$update_rc_d],
ensure => running
}
}
node default {

View File

@ -1,15 +1,3 @@
class god-debian {
class { god: }
init_d_bundle { '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

@ -0,0 +1,14 @@
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

@ -1,80 +1,40 @@
#!/bin/bash
<%= scope.function_template('base/init-d-header') %>
<% bin = scope.lookupvar('god::bin') %>
<%= 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
<%= bin %> -P <%= scope.lookupvar('god::pid') %> -l <%= scope.lookupvar('god::log') %>
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
sleep 2
if [ -d $DIR ]; then
for file in $(find $DIR -name "*.god"); do
for file in $(find <%= scope.lookupvar('god::dir') %> -name "*.god"); do
echo "$NAME: loading $file ..."
$BIN load $file
<%= bin %> load $file
done
fi
fi
echo "$NAME."
return $RETVAL
}
stop() {
echo -n "Stopping $DESC: "
if [ -f $PID ]; then
kill `cat $PID`
for pid in <%= scope.lookupvar('god::pid') %>; do
if [ -f pid ]; then
kill `cat $pid`
rm $PID
fi
done
killall -9 $BIN || true
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
<%= scope.function_template('base/init-d-actions') %>

View File

@ -1,17 +1 @@
class ruby-debian($version) {
$packages = [
'libyaml-dev', 'libreadline-dev', 'libssl-dev', 'libffi-dev',
'libncurses5-dev', 'libcurl4-openssl-dev', 'zlib1g-dev',
'libxml2', 'libxml2-dev', 'libxslt1.1', 'libxslt1-dev'
]
package { $packages: ensure => installed }
class { ruby: version => $version, require => Package[$packages] }
bash_rc_d { 'ruby':
ensure => present,
path => $base::local_path
}
}

View File

@ -0,0 +1,17 @@
class ruby::debian($version) {
$packages = [
'libyaml-dev', 'libreadline-dev', 'libssl-dev', 'libffi-dev',
'libncurses5-dev', 'libcurl4-openssl-dev', 'zlib1g-dev',
'libxml2', 'libxml2-dev', 'libxslt1.1', 'libxslt1-dev'
]
package { $packages: ensure => installed }
class { ruby: version => $version, require => Package[$packages] }
bash_rc_d { 'ruby':
ensure => present,
path => $base::local_path
}
}

View File

@ -0,0 +1,21 @@
class varnish::debian($version, $vcl_template) {
$user = 'varnish'
$group = 'varnish'
user { $user: uid => 27835 }
package { 'libpcre3-dev': ensure => installed }
class { 'varnish':
version => $version,
require => Package['libpcre3-dev'],
vcl_template => $vcl_template
}
init_d { 'varnish':
init_d_prerun => template('varnish/debian/init-d-prerun'),
init_d_prolog => template('varnish/debian/init-d-prolog'),
require => Class['varnish']
}
}

View File

@ -1,4 +1,4 @@
class varnish($version, $store_file_mb = 1024) {
class varnish($version, $vcl_template, $store_file_mb = 1024) {
$install_path = install_path($name, $version)
$config = config_path($name)
$share = share_path($name)
@ -12,41 +12,23 @@ class varnish($version, $store_file_mb = 1024) {
$ncsa_bin = "${bin_path}/varnishncsa"
$ncsa_pid = pid_path('varnishncsa')
$ncsa_log = $log
$ncsa_log = "${log}/access.log"
$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, $log, $share, $sysconfig_dir, $data ]:
mkdir_p { [ $config, $log, $share, $data ]:
path => $base::path,
require => Build_and_install[$name]
}
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,
@ -59,12 +41,18 @@ class varnish($version, $store_file_mb = 1024) {
$varnish_start = "service varnish start"
$varnish_stop = "service varnish stop"
file { $vcl_path:
content => template($vcl_template),
require => Build_and_install[$name]
}
god_init { $name:
start => $varnish_start,
stop => $varnish_stop,
restart => "${varnish_stop} && ${varnish_start}",
pid_file => $pid,
ensure => present,
require => Build_and_install[$name]
require => File[$vcl_path],
interval => 10
}
}

View File

@ -0,0 +1,8 @@
# Open files (usually 1024, which is way too small for varnish)
ulimit -n ${NFILES:-131072}
# Maxiumum locked memory size for shared memory log
ulimit -l ${MEMLOCK:-82000}
USER=<%= user %>
GROUP=<%= group %>

View File

@ -0,0 +1,12 @@
### BEGIN INIT INFO
# Provides: varnish
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start HTTP accelerator
# Description: This script provides a server-side cache
# to be run in front of a httpd and should
# listen on port 80 on a properly configured
# system
### END INIT INFO

View File

@ -1,9 +1,3 @@
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
DAEMON_OPTS="\
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:6082 \
-u ${VARNISH_USERNAME} -g ${VARNISH_GROUP} \
-w 1,1,3600 \
-f ${VARNISH_VCL_CONF} \
-s ${VARNISH_BACKEND_STORE} \
"

View File

@ -0,0 +1,41 @@
<%= scope.function_template('base/init-d-header') %>
<%= init_d_prolog %>
<%= init_d_prerun %>
start() {
echo -n "Starting $NAME: "
<%= scope.lookupvar('varnish::bin') %> \
-P <%= scope.lookupvar('varnish::pid') %> \
-T 127.0.0.1:6082 \
-u $USER -g $GROUP \
-w 1,1,3600 \
-f <%= scope.lookupvar('varnish::vcl_path') %> \
-s file,<%= scope.lookupvar('varnish::store_file_path') %>
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
<%= scope.lookupvar('varnish::ncsa_bin') %> \
-P <%= scope.lookupvar('varnish::ncsa_pid') %> \
-a -w <%= scope.lookupvar('varnish::ncsa_log') %> -D
RETVAL=$?
fi
echo "done"
}
stop() {
echo -n "Stopping $NAME: "
for pid in <%= scope.lookupvar('varnish::pid') %> <%= scope.lookupvar('varnish::ncsa_pid') %>; do
if [ -f $pid ]; then
kill `cat $pid`
rm $pid
fi
done
echo "done"
}
<%= scope.function_template('base/init-d-actions') %>

View File

@ -0,0 +1,27 @@
define ssh {
$ssh_dir = "/home/${name}/.ssh"
file { $ssh_dir:
ensure => directory,
mode => '2700'
}
file { "${ssh_dir}/authorized_keys":
content => template("ssh/${name}/authorized_keys"),
require => File[$ssh_dir],
mode => '0644'
}
file { "${ssh_dir}/id_dsa":
content => template("ssh/${name}/id_dsa"),
require => File[$ssh_dir],
mode => '0600'
}
file { "${ssh_dir}/id_dsa.pub":
content => template("ssh/${name}/id_dsa.pub"),
require => File[$ssh_dir],
mode => '0644'
}
}

View File

@ -0,0 +1,18 @@
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
$RETVAL=1
;;
esac
exit $RETVAL

View File

@ -0,0 +1,7 @@
#!/bin/sh
PATH=<%= scope.lookupvar('base::path') %>
NAME=<%= name %>
DESC=<%= name %>
RETVAL=0

View File

@ -1,5 +1,5 @@
#!/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/templates -v $@ manifests/site.pp
<%= 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