diff --git a/.gitignore b/.gitignore index 4040c6c..2f0a9ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .bundle Gemfile.lock pkg/* +.DS_Store diff --git a/lib/puppet-standalone-mashup/capistrano.rb b/lib/puppet-standalone-mashup/capistrano.rb index e1ddafb..bf44470 100644 --- a/lib/puppet-standalone-mashup/capistrano.rb +++ b/lib/puppet-standalone-mashup/capistrano.rb @@ -16,6 +16,7 @@ Capistrano::Configuration.instance.load do _cset(:base_dir) { '/usr/local' } _cset(:rename_server) { true } _cset(:use_sudo) { true } + _cset(:additional_modules) { [] } @dir_made = false @@ -83,7 +84,11 @@ Capistrano::Configuration.instance.load do task :copy_shared do top.ensure_puppet_dir - top.upload PuppetStandaloneMashup::BASE.join('shared').to_s, File.join(puppet_dir, 'shared') + run "mkdir -p #{puppet_dir}/shared/additional-modules" + + (%w{lib modules} + 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 desc "Ensure Puppet target dir exists" diff --git a/shared/additional-modules/god/manifests/init.pp b/shared/additional-modules/god/manifests/init.pp new file mode 100644 index 0000000..f1b1fa2 --- /dev/null +++ b/shared/additional-modules/god/manifests/init.pp @@ -0,0 +1,34 @@ +class god { + gem { 'god': + path => "${ruby::path}:${base::path}", + ensure => present, + 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) + + file { '/etc/init.d/god': + content => template('god/god-init.d'), + mode => 755 + } + + file { $god_dir: + 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 + } +} + diff --git a/shared/additional-modules/god/templates/god-init.d b/shared/additional-modules/god/templates/god-init.d new file mode 100644 index 0000000..1be6219 --- /dev/null +++ b/shared/additional-modules/god/templates/god-init.d @@ -0,0 +1,76 @@ +#!/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: " + kill `cat $PID_PATH` + RETVAL=$? + echo "$NAME." +} + +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/templates/resurrect b/shared/additional-modules/god/templates/resurrect new file mode 100644 index 0000000..ac63598 --- /dev/null +++ b/shared/additional-modules/god/templates/resurrect @@ -0,0 +1,8 @@ +#!/bin/sh + +sudo killall god +sudo killall nginx +sudo killall thin +sudo killall php5-fpm +sudo service god start + diff --git a/shared/additional-modules/ruby/manifests/init.pp b/shared/additional-modules/ruby/manifests/init.pp new file mode 100644 index 0000000..9c1ebd5 --- /dev/null +++ b/shared/additional-modules/ruby/manifests/init.pp @@ -0,0 +1,23 @@ +class ruby($version) { + $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", + require => Class['base'] + } + + gem { 'bundler': + require => Build_and_install[$name], + path => $with_ruby_path, + ensure => present + } + + bash_rc_d { $name: + ensure => present, + path => $base::local_path, + require => Build_and_install[$name] + } +} + diff --git a/skel/apply.erb b/skel/apply.erb index 50e8a29..d018aa8 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 --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/templates -v $@ manifests/site.pp