diff --git a/shared/additional-modules/debian-base/manifests/init.pp b/shared/additional-modules/debian-base/manifests/init.pp index 46810c5..6fe2e9a 100644 --- a/shared/additional-modules/debian-base/manifests/init.pp +++ b/shared/additional-modules/debian-base/manifests/init.pp @@ -11,6 +11,7 @@ class base { $install_path = "/usr/local" $config_path = "/etc" $pid_path = "/var/run" + $log_path = "/var/log" $local_path = $install_path } diff --git a/shared/additional-modules/god-debian/manifests/init.pp b/shared/additional-modules/god-debian/manifests/init.pp index c819e54..e07471e 100644 --- a/shared/additional-modules/god-debian/manifests/init.pp +++ b/shared/additional-modules/god-debian/manifests/init.pp @@ -1,6 +1,9 @@ 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'), diff --git a/shared/additional-modules/god-debian/templates/god-init.d b/shared/additional-modules/god-debian/templates/god-init.d deleted file mode 100644 index 501b8ca..0000000 --- a/shared/additional-modules/god-debian/templates/god-init.d +++ /dev/null @@ -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 - diff --git a/shared/additional-modules/god-debian/templates/init_d_prerun b/shared/additional-modules/god-debian/templates/init_d_prerun new file mode 100644 index 0000000..657df07 --- /dev/null +++ b/shared/additional-modules/god-debian/templates/init_d_prerun @@ -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 diff --git a/shared/additional-modules/god-debian/templates/init_d_prolog b/shared/additional-modules/god-debian/templates/init_d_prolog new file mode 100644 index 0000000..844e51a --- /dev/null +++ b/shared/additional-modules/god-debian/templates/init_d_prolog @@ -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 + diff --git a/shared/additional-modules/god/manifests/init.pp b/shared/additional-modules/god/manifests/init.pp index b13a8d2..340d723 100644 --- a/shared/additional-modules/god/manifests/init.pp +++ b/shared/additional-modules/god/manifests/init.pp @@ -5,15 +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 { $god_dir: + file { [ $dir, $share ]: ensure => directory } - - $share = "${base::share_path}/god" - file { $share: ensure => directory } } diff --git a/shared/additional-modules/god/templates/god-init.d-base b/shared/additional-modules/god/templates/god-init.d-base new file mode 100644 index 0000000..78d9efe --- /dev/null +++ b/shared/additional-modules/god/templates/god-init.d-base @@ -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 + diff --git a/shared/additional-modules/varnish-vcl/manifests/init.pp b/shared/additional-modules/varnish-vcl/manifests/init.pp new file mode 100644 index 0000000..125e026 --- /dev/null +++ b/shared/additional-modules/varnish-vcl/manifests/init.pp @@ -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] ], + } +} + diff --git a/shared/additional-modules/varnish/manifests/init.pp b/shared/additional-modules/varnish/manifests/init.pp new file mode 100644 index 0000000..541764c --- /dev/null +++ b/shared/additional-modules/varnish/manifests/init.pp @@ -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 + } +} diff --git a/shared/additional-modules/varnish/templates/defaults b/shared/additional-modules/varnish/templates/defaults new file mode 100644 index 0000000..6c94c1f --- /dev/null +++ b/shared/additional-modules/varnish/templates/defaults @@ -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} \ + " + diff --git a/shared/additional-modules/varnish/templates/varnish-init.d-base b/shared/additional-modules/varnish/templates/varnish-init.d-base new file mode 100644 index 0000000..baeb1fe --- /dev/null +++ b/shared/additional-modules/varnish/templates/varnish-init.d-base @@ -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 $? + diff --git a/shared/lib/puppet/parser/functions/config_path.rb b/shared/lib/puppet/parser/functions/config_path.rb new file mode 100644 index 0000000..ed3d9c6 --- /dev/null +++ b/shared/lib/puppet/parser/functions/config_path.rb @@ -0,0 +1,5 @@ +module Puppet::Parser::Functions + newfunction(:config_path, :type => :rvalue) do |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 new file mode 100644 index 0000000..c831936 --- /dev/null +++ b/shared/lib/puppet/parser/functions/data_path.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:data_path, :type => :rvalue) do |args| + File.join(lookupvar('base::data_path'), *args) + end +end + diff --git a/shared/lib/puppet/parser/functions/log_path.rb b/shared/lib/puppet/parser/functions/log_path.rb new file mode 100644 index 0000000..dc5b28a --- /dev/null +++ b/shared/lib/puppet/parser/functions/log_path.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:log_path, :type => :rvalue) do |args| + File.join(lookupvar('base::log_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 53e5013..448ff3e 100644 --- a/shared/lib/puppet/parser/functions/sbin_path.rb +++ b/shared/lib/puppet/parser/functions/sbin_path.rb @@ -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 - diff --git a/shared/lib/puppet/parser/functions/share_path.rb b/shared/lib/puppet/parser/functions/share_path.rb new file mode 100644 index 0000000..4dd45a4 --- /dev/null +++ b/shared/lib/puppet/parser/functions/share_path.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:share_path, :type => :rvalue) do |args| + File.join(lookupvar('base::share_path'), *args) + end +end + diff --git a/shared/lib/puppet/provider/download_and_unpack/action.rb b/shared/lib/puppet/provider/download_and_unpack/action.rb index 9e60fdc..62bdccc 100644 --- a/shared/lib/puppet/provider/download_and_unpack/action.rb +++ b/shared/lib/puppet/provider/download_and_unpack/action.rb @@ -3,6 +3,7 @@ Puppet::Type.type(:download_and_unpack).provide(:action) do def create system %{bash -c 'cd #{@resource[:src_path]} ; (curl #{@resource[:url]} | tar #{tar_command} -)'} + raise StandardError.new("Could not download") if $?.exitstatus != 0 end def destroy diff --git a/shared/modules/init_d/manifests/init.pp b/shared/modules/init_d/manifests/init.pp deleted file mode 100644 index 492937d..0000000 --- a/shared/modules/init_d/manifests/init.pp +++ /dev/null @@ -1,3 +0,0 @@ -define init_d($template) { - -}