diff --git a/lib/puppet-standalone-mashup/capistrano.rb b/lib/puppet-standalone-mashup/capistrano.rb index 76c7407..c19dd6b 100644 --- a/lib/puppet-standalone-mashup/capistrano.rb +++ b/lib/puppet-standalone-mashup/capistrano.rb @@ -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 diff --git a/shared/additional-modules/debian-base/manifests/init.pp b/shared/additional-modules/debian-base/manifests/init.pp index 78528d8..7b7b742 100644 --- a/shared/additional-modules/debian-base/manifests/init.pp +++ b/shared/additional-modules/debian-base/manifests/init.pp @@ -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 { diff --git a/shared/additional-modules/god-debian/manifests/init.pp b/shared/additional-modules/god-debian/manifests/init.pp index 9205ec2..c3a2df6 100644 --- a/shared/additional-modules/god-debian/manifests/init.pp +++ b/shared/additional-modules/god-debian/manifests/init.pp @@ -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 - } } diff --git a/shared/additional-modules/god/manifests/debian.pp b/shared/additional-modules/god/manifests/debian.pp new file mode 100644 index 0000000..9415421 --- /dev/null +++ b/shared/additional-modules/god/manifests/debian.pp @@ -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 + } +} diff --git a/shared/additional-modules/god-debian/templates/init_d_prerun b/shared/additional-modules/god/templates/debian/init_d_prerun similarity index 100% rename from shared/additional-modules/god-debian/templates/init_d_prerun rename to shared/additional-modules/god/templates/debian/init_d_prerun diff --git a/shared/additional-modules/god-debian/templates/init_d_prolog b/shared/additional-modules/god/templates/debian/init_d_prolog similarity index 100% rename from shared/additional-modules/god-debian/templates/init_d_prolog rename to shared/additional-modules/god/templates/debian/init_d_prolog diff --git a/shared/additional-modules/god-debian/templates/resurrect b/shared/additional-modules/god/templates/debian/resurrect similarity index 100% rename from shared/additional-modules/god-debian/templates/resurrect rename to shared/additional-modules/god/templates/debian/resurrect diff --git a/shared/additional-modules/god/templates/god-init.d b/shared/additional-modules/god/templates/god-init.d index 78d9efe..b6cc1cd 100644 --- a/shared/additional-modules/god/templates/god-init.d +++ b/shared/additional-modules/god/templates/god-init.d @@ -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 - echo "$NAME: loading $file ..." - $BIN load $file - done - fi + for file in $(find <%= scope.lookupvar('god::dir') %> -name "*.god"); do + echo "$NAME: loading $file ..." + <%= bin %> load $file + done fi echo "$NAME." - - return $RETVAL } stop() { echo -n "Stopping $DESC: " - if [ -f $PID ]; then - kill `cat $PID` - rm $PID - fi - killall -9 $BIN || true + for pid in <%= scope.lookupvar('god::pid') %>; do + if [ -f pid ]; then + kill `cat $pid` + rm $PID + fi + done + + 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') %> diff --git a/shared/additional-modules/ruby-debian/manifests/init.pp b/shared/additional-modules/ruby-debian/manifests/init.pp index c2b1b6a..8b13789 100644 --- a/shared/additional-modules/ruby-debian/manifests/init.pp +++ b/shared/additional-modules/ruby-debian/manifests/init.pp @@ -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 - } -} diff --git a/shared/additional-modules/ruby/manifests/debian.pp b/shared/additional-modules/ruby/manifests/debian.pp new file mode 100644 index 0000000..c6e522b --- /dev/null +++ b/shared/additional-modules/ruby/manifests/debian.pp @@ -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 + } +} + diff --git a/shared/additional-modules/varnish/manifests/debian.pp b/shared/additional-modules/varnish/manifests/debian.pp new file mode 100644 index 0000000..51d7312 --- /dev/null +++ b/shared/additional-modules/varnish/manifests/debian.pp @@ -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'] + } +} + diff --git a/shared/additional-modules/varnish/manifests/init.pp b/shared/additional-modules/varnish/manifests/init.pp index 69e062c..7ca1870 100644 --- a/shared/additional-modules/varnish/manifests/init.pp +++ b/shared/additional-modules/varnish/manifests/init.pp @@ -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 } } diff --git a/shared/additional-modules/varnish/templates/debian/init-d-prerun b/shared/additional-modules/varnish/templates/debian/init-d-prerun new file mode 100644 index 0000000..8d9cb86 --- /dev/null +++ b/shared/additional-modules/varnish/templates/debian/init-d-prerun @@ -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 %> diff --git a/shared/additional-modules/varnish/templates/debian/init-d-prolog b/shared/additional-modules/varnish/templates/debian/init-d-prolog new file mode 100644 index 0000000..2308f2a --- /dev/null +++ b/shared/additional-modules/varnish/templates/debian/init-d-prolog @@ -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 diff --git a/shared/additional-modules/varnish/templates/defaults b/shared/additional-modules/varnish/templates/defaults index 02afcd0..bbdc96a 100644 --- a/shared/additional-modules/varnish/templates/defaults +++ b/shared/additional-modules/varnish/templates/defaults @@ -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} \ " diff --git a/shared/additional-modules/varnish/templates/varnish-init.d b/shared/additional-modules/varnish/templates/varnish-init.d new file mode 100644 index 0000000..217847b --- /dev/null +++ b/shared/additional-modules/varnish/templates/varnish-init.d @@ -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') %> + diff --git a/shared/modules/ssh/manifests/init.pp b/shared/modules/ssh/manifests/init.pp new file mode 100644 index 0000000..6a61cac --- /dev/null +++ b/shared/modules/ssh/manifests/init.pp @@ -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' + } +} + diff --git a/shared/templates/base/init-d-actions b/shared/templates/base/init-d-actions new file mode 100644 index 0000000..10f687e --- /dev/null +++ b/shared/templates/base/init-d-actions @@ -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 diff --git a/shared/templates/base/init-d-header b/shared/templates/base/init-d-header new file mode 100644 index 0000000..bdc3f32 --- /dev/null +++ b/shared/templates/base/init-d-header @@ -0,0 +1,7 @@ +#!/bin/sh +PATH=<%= scope.lookupvar('base::path') %> + +NAME=<%= name %> +DESC=<%= name %> + +RETVAL=0 diff --git a/skel/apply.erb b/skel/apply.erb index d018aa8..598ae23 100644 --- a/skel/apply.erb +++ b/skel/apply.erb @@ -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