Compare commits

..

No commits in common. "master" and "pre-new-stuff" have entirely different histories.

69 changed files with 306 additions and 690 deletions

View File

@ -1,10 +0,0 @@
class debian {
$varnish_apt_source = "deb http://repo.varnish-cache.org/debian/ squeeze varnish-3.0"
$varnish_keyfile = "http://repo.varnish-cache.org/debian/GPG-key.txt"
$varnish_hash = "C4DEFFEB"
$mongo_apt_source = "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen"
$mongo_host = "keyserver.ubuntu.com"
$mongo_hash = "7F0CEB10"
}

View File

@ -1,23 +0,0 @@
class ruby::falcon($version, $configure, $build_path) {
class { ruby:
version => $version,
configure => $configure,
build_path => $build_path
}
file { '/tmp/ruby-falcon-patch.sh':
content => template('ruby/falcon-patch.sh'),
before => Configure['ruby'],
mode => 755
}
exec { 'patch-ruby':
command => "ruby-falcon-patch.sh",
before => Configure['ruby'],
cwd => build_path('ruby', $version),
unless => 'test -f patched',
logoutput => true,
path => "/tmp:$base::path"
}
}

View File

@ -1,49 +0,0 @@
class ruby($version = '', $deb_url = '', $configure = "--disable-install-doc", $build_path = '') {
gem { [ 'bundler', 'penchant' ]:
path => "${path}:${base::path}",
ensure => present
}
if ($::osfamily == 'debian') {
$path = '/usr/bin'
remotedeb { ruby:
url => $deb_url,
version => $version
}
Remotedeb[ruby] -> Gem['bundler', 'penchant']
} else {
$path = bin_path($name)
build_and_install { $name:
version => $version,
source => "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-<%= version %>.tar.gz",
configure => $configure,
preconfigure => "LDFLAGS='-rdynamic -Wl,-export-dynamic'",
path => $build_path
}
if ($osfamily == 'debian') {
$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,
before => Build_and_install[$name]
}
bash_rc_d { 'ruby':
ensure => present,
path => $base::local_path,
require => Build_and_install[$name]
}
}
Build_and_install[ruby] -> Gem['bundler', 'penchant']
}
}

View File

@ -1,10 +0,0 @@
#!/bin/bash
curl https://raw.github.com/gist/2593385/perf_and_gc.diff | patch -p1
if [ $? -ne 0 ]; then exit 1; fi
curl https://raw.github.com/gist/2502451/46c9fbc07abf7ea5670ba0e23a11ff93d6e3c9db/yaml.rb.diff | patch -p1
if [ $? -ne 0 ]; then exit 1; fi
touch patched

View File

@ -1,98 +0,0 @@
class squid($version = '', $user = 'proxy', $group = 'proxy', $config_template, $error_template) {
if ($::osfamily == 'debian') {
$cache_dir = '/var/spool/squid3'
$config_dir = "/etc/squid3"
$config = "${config_dir}/squid.conf"
$log_dir = "/var/log/squid3"
$sbin = '/usr/sbin'
package { 'squid3': ensure => latest }
package { 'squidclient': ensure => latest }
service { squid3:
ensure => stopped,
require => Package[squid3]
}
Package['squid3'] -> File[$config]
Package['squid3'] -> Exec['stop-squid-for-good'] -> Exec['squid-cache']
exec { 'stop-squid-for-good':
command => 'service squid3 stop ; update-rc.d -f squid3 remove',
path => $::base::path
}
logrotate_d { 'squid3':
postrotate => 'god signal squid HUP',
pattern => "${log_dir}/access.log"
}
} else {
$bin = bin_path($name)
$sbin = sbin_path($name)
$build_dir = build_path($name, $version)
$log_dir = log_path($name)
$pid = pid_path($name)
$cache_dir = data_path($name)
$config_dir = config_path($name)
$config = "${config_dir}/squid.conf"
build_and_install { $name:
version => $version,
source => "http://www.squid-cache.org/Versions/v3/3.1/squid-${version}.tar.bz2",
configure => template('squid/configure'),
preconfigure => template('squid/preconfigure')
}
Build_and_install[$name] -> File[$config]
Build_and_install[$name] -> Exec[cache_dir_perms]
}
mkdir_p { [ $log_dir, $cache_dir, $config_dir ]:
path => $base::path
}
exec { log_dir_params:
command => "chown -R ${user}:${group} ${log_dir}",
path => $::base::path,
require => Mkdir_p[$log_dir]
}
exec { 'cache_dir_perms':
command => "chown -R ${user}:${group} ${cache_dir}",
path => $::base::path,
require => Mkdir_p[$cache_dir]
}
exec { 'squid-cache':
command => "${sbin}/squid3 -z",
logoutput => true,
require => Exec[cache_dir_perms, log_dir_params],
unless => "test -d ${cache_dir}/00",
path => $::base::path
}
file { "${sbin}/clear-squid-cache":
content => template('squid/clear-squid-cache'),
mode => 0755
}
exec { 'cache_dir_perms_again':
command => "chown -R ${user}:${group} ${cache_dir}",
path => $::base::path,
require => Exec['squid-cache']
}
file { $config:
content => template($config_template)
}
god_init { $name:
start => "${sbin}/squid3 -YC -f ${config} -N -a 80",
dir => config_path('god.d'),
ensure => present,
require => File[$config],
interval => 10
}
}

View File

@ -1,20 +0,0 @@
#!/bin/bash
target="<%= @cache_dir %>$(date +%Y%m%d%H%M%S)"
if [ $UID -ne 0 ]; then
sudo $0
exit
fi
god stop squid
while [ "$(pgrep squid3 | wc -l)" -ne 0 ]; do
sleep 1
done
mv <%= @cache_dir %> "$target"
mkdir <%= @cache_dir %>
chown -R <%= @user %>:<%= @group %> <%= @cache_dir %>
squid3 -z
god start squid
rm -Rf "$target"

View File

@ -1,110 +0,0 @@
class varnish($version = '', $vcl, $user = 'varnish', $group = 'varnish') {
if ($::osfamily == 'debian') {
$config = '/etc/varnish'
$default_varnish = '/etc/default/varnish'
$bin = "/usr/sbin/varnishd"
} else {
$install_path = install_path($name, $version)
$config = config_path($name)
$share = share_path($name)
$data = data_path($name)
$sbin = sbin_path($name)
$bin_path = bin_path($name)
$bin = "${sbin}/${name}d"
$pid = pid_path($name)
$log = log_path($name)
$default_varnish = "${config}/defaults"
}
$vcl_path = "${config}/default.vcl"
if ($::osfamily == 'debian') {
debsource { varnish:
apt_source => $debian::varnish_apt_source,
keyfile => $debian::varnish_keyfile,
hash => $debian::varnish_hash
}
$cache_root = "/var/lib"
$cache_dir = "${cache_root}/varnish"
package { varnish:
ensure => latest,
require => [
Debsource['varnish'], Mkdir_p[$cache_dir]
]
}
service { varnish:
ensure => stopped,
require => Package[varnish]
}
exec { 'update-rc.d -f varnish remove':
path => $::base::path,
require => Package[varnish]
}
$store_file_size = dir_size($cache_root)
Package['varnish'] -> File[$default_varnish, $vcl_path]
} else {
$source = "http://repo.varnish-cache.org/source/varnish-${version}.tar.gz"
$dirs = [ $config, $log, $share, $data ]
$cache_dir = "${data}/store"
build_and_install { $name:
version => $version,
source => $source
}
mkdir_p { $dirs:
path => $base::path,
require => Build_and_install[$name]
}
init_d { $name:
require => Mkdir_p[$dirs]
}
Build_and_install['varnish'] -> File[$default_varnish, $vcl_path]
/*
$ncsa_bin = "${bin_path}/varnishncsa"
$ncsa_pid = pid_path('varnishncsa')
$ncsa_log = "${log}/access.log"
logrotate_d { 'varnishncsa':
postrotate => 'service varnish rotate',
pattern => "${log}/access.log"
}
*/
}
file { $default_varnish:
content => template("varnish/default"),
notify => Service['god']
}
file { $vcl_path:
content => $vcl,
notify => Service['god']
}
mkdir_p { $cache_dir:
path => $base::path
}
god_init { $name:
start => "${bin} -T 127.0.0.1:6082 -F -u ${user} -g ${group} -w 1,1,3600 -f ${vcl_path} -s file,${cache_dir}/varnish",
dir => config_path('god.d'),
ensure => present,
require => File[$vcl_path],
interval => 10
}
}

View File

@ -1,12 +0,0 @@
START=1
DAEMON_OPTS=" \
-a :80 \
-T 127.0.0.1:6082 \
-f <%= vcl_path %> \
-s file,<%= cache_dir %>/cache,<%= store_file_size %>M \
-u nobody \
-g nogroup \
-w <%= scope.lookupvar('::processorcount') %>,<%= scope.lookupvar('::processorcount').to_i * 2 %>,600 \
"

View File

@ -1,20 +1,9 @@
require "puppet-standalone-mashup/version"
module PuppetStandaloneMashup
autoload :Provider, 'puppet-standalone-mashup/provider'
autoload :Configuration, 'puppet-standalone-mashup/configuration'
class ProvideMyself < Provider ; end
def self.configure
yield configuration
end
def self.configuration
@configuration ||= Configuration.new
end
def self.paths_for(*args)
Provider.paths_for(*args)
module Puppet
module Standalone
module Mashup
# Your code goes here...
end
end
end

View File

@ -1,5 +1,4 @@
require 'erb'
require 'puppet-standalone-mashup'
def _cset(name, *args, &block)
unless exists?(name)
@ -7,6 +6,10 @@ def _cset(name, *args, &block)
end
end
module PuppetStandaloneMashup
BASE = Pathname(File.expand_path('../../..', __FILE__))
end
require 'capistrano/command'
module Capistrano
@ -30,7 +33,6 @@ Capistrano::Configuration.instance.load do
_cset(:rename_server) { true }
_cset(:use_sudo) { true }
_cset(:run_as_user) { false }
_cset(:additional_modules) { [] }
_cset(:additional_puppet_options) { '' }
@ -57,24 +59,12 @@ Capistrano::Configuration.instance.load do
top.copy_skel
end
def as_user(cmd)
if use_sudo
if run_as_user
%{#{sudo} su -c "#{cmd}" #{user}}
else
%{#{sudo} #{cmd}}
end
else
cmd
end
end
desc "Apply the configuration"
task :apply do
top.copy_files
top.rename if rename_server && wrong_server_name?
run "cd #{puppet_dir} && #{as_user("./apply")}"
run "cd #{puppet_dir} && #{sudo} ./apply"
end
def wrong_server_name?
@ -86,13 +76,7 @@ Capistrano::Configuration.instance.load do
top.copy_files
top.rename if rename_server
run "cd #{puppet_dir} && #{as_user("./bootstrap")}"
top.bootstrap_reboot
end
desc "Reboot the server after bootstrapping"
task :bootstrap_reboot do
run "#{sudo} shutdown -r now"
run "cd #{puppet_dir} && #{sudo} ./bootstrap"
end
desc "Rename the server"
@ -108,39 +92,25 @@ Capistrano::Configuration.instance.load do
top.ensure_puppet_dir
Dir["*"].each do |file|
if !%w{vbox deb}.include?(file)
if !%w{vbox}.include?(file)
top.upload file, File.join(puppet_dir, file)
end
end
end
def upload_directory_safely(source, target, options = {})
run "mkdir -p #{target}"
Dir["#{source}/*"].each do |child|
top.upload child, File.join(target, File.basename(child)), options
end
end
desc "Copy skel files to remote server"
task :copy_skel do
top.ensure_puppet_dir
targets = []
[ '*.erb', "#{distribution}/*.erb" ].each do |dir|
Dir[PuppetStandaloneMashup::BASE.join('skel').join(dir).to_s].each do |file|
data = StringIO.new(ERB.new(File.read(file)).result(binding))
PuppetStandaloneMashup.paths_for('skel').each do |path|
[ '*.erb', "#{distribution}/*.erb" ].each do |dir|
Dir[path.join(dir).to_s].each do |file|
data = StringIO.new(ERB.new(File.read(file)).result(binding))
top.upload data, target = File.join(puppet_dir, File.basename(file, '.erb'))
top.upload data, target = File.join(puppet_dir, File.basename(file, '.erb'))
targets << target
end
run "chmod a+x #{target}"
end
end
run "chmod a+x #{targets.join(' ')}"
end
desc "Copy shared"
@ -149,8 +119,8 @@ Capistrano::Configuration.instance.load do
run "mkdir -p #{puppet_dir}/shared/additional-modules"
PuppetStandaloneMashup.configuration.shared_paths.each do |path|
upload_directory_safely path.to_s, File.join(puppet_dir, 'shared', path.target)
(%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
@ -175,22 +145,7 @@ Capistrano::Configuration.instance.load do
end
def with_additional_puppet_bin_path
"PATH=" + (PuppetStandaloneMashup.configuration.bin_path + [ "$PATH" ]).join(':')
end
desc "Get managing user's public key"
task :public_key do
as_user = ->(command) { %{sudo -u #{user} -- #{command}} }
key = capture(as_user.("cat ~/.ssh/id_dsa.pub 2>/dev/null ; true"))
if key.empty?
if Capistrano::CLI.ui.ask("No key found. Generate a key?")
run as_user.("ssh-keygen -f ~/.ssh/id_dsa -t dsa -N ''")
key = capture(as_user("cat ~/.ssh/id_dsa.pub"))
end
end
$stdout.puts "\n#{key}\n"
additional_puppet_bin_path ? %{PATH="#{additional_puppet_bin_path}:$PATH"} : ''
end
end

View File

@ -5,8 +5,6 @@ Capistrano::Configuration.instance.load do
set(:user) { 'vagrant' }
set(:password) { 'vagrant' }
set(:use_sudo) { true }
set(:run_as_user) { false }
task :ensure_puppet do
require 'socket'

View File

@ -1,60 +0,0 @@
require 'delegate'
class Pathname
def only_valid_paths_for_directories(*dirs)
valid_paths = []
dirs.flatten.each do |dir|
target = self.join(dir)
if target.directory?
valid_paths << target
end
end
valid_paths
end
end
module PuppetStandaloneMashup
class TargetedPath < SimpleDelegator
attr_reader :path, :target
def initialize(path, target = path.basename)
@path, @target = path, target
end
def __getobj__
@path
end
end
class Configuration
SHARED_DIRS = %w{lib modules templates}
def additional_modules
@additional_modules ||= []
end
def bin_path
@bin_path ||= []
end
def shared_paths
return @shared_paths if @shared_paths
@shared_paths = []
Provider.paths_for('shared').each do |path|
@shared_paths += path.only_valid_paths_for_directories(SHARED_DIRS).collect { |dirpath| TargetedPath.new(dirpath) }
end
Provider.paths_for('additional-modules').each do |path|
@shared_paths += path.only_valid_paths_for_directories(additional_modules).collect { |dirpath| TargetedPath.new(dirpath, "modules/#{dirpath.basename}") }
end
@shared_paths
end
end
end

View File

@ -1,15 +0,0 @@
class PuppetStandaloneMashup::Provider
def self.shared_sources
@shared_sources ||= []
end
def self.inherited(klass)
shared_sources << Pathname(caller.first.gsub(%r{lib/.*}, ''))
end
def self.paths_for(*paths)
shared_sources.collect do |source|
paths.collect { |path| source.join(path) }
end.flatten
end
end

View File

@ -2,7 +2,7 @@ class basics {
$packages = [
"ntp", "ntpdate", "gcc", "curl",
"build-essential", "patch", 'sysstat',
'git-core', 'vim', 'libffi5'
'git-core', 'vim'
]
package { $packages: ensure => installed }

View File

@ -0,0 +1,6 @@
class debian {
group { web:
gid => 30010
}
}

View File

@ -2,10 +2,10 @@ class god {
gem { 'god':
path => "${ruby::path}:${base::path}",
ensure => present,
require => Class['ruby']
require => Make_and_install['ruby']
}
$bin = "${ruby::path}/god"
$bin = "${base::install_path}/ruby/bin/god"
$dir = config_path("god.d")
$pid = pid_path($name)
$log = log_path($name)

View File

@ -0,0 +1,38 @@
class ruby($version, $configure = "--disable-install-doc", $build_path = '') {
$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",
configure => $configure,
preconfigure => "LDFLAGS='-rdynamic -Wl,-export-dynamic'",
path => "${build_path}:${with_ruby_path}"
}
if ($osfamily == 'debian') {
$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,
before => Build_and_install[$name]
}
bash_rc_d { 'ruby':
ensure => present,
path => $base::local_path,
require => Build_and_install[$name]
}
}
gem { [ 'bundler', 'penchant' ]:
require => Build_and_install[$name],
path => $with_ruby_path,
ensure => present
}
}

View File

@ -23,5 +23,10 @@ class squid::debian($version, $config_template, $error_template) {
path => $base::path,
require => Class['squid']
}
logrotate_d { 'squid':
postrotate => 'service squid rotate',
pattern => "${squid::log_dir}/access.log"
}
}

View File

@ -0,0 +1,49 @@
class squid($version, $user, $config_template, $error_template) {
$bin = bin_path($name)
$sbin = sbin_path($name)
$build_dir = build_path($name, $version)
$log_dir = log_path($name)
$pid = pid_path($name)
$data_dir = data_path($name)
$config_dir = config_path($name)
$config = "${config_dir}/squid.conf"
mkdir_p { [ $log_dir, $data_dir, $config_dir ]:
path => $base::path
}
build_and_install { $name:
version => $version,
source => "http://www.squid-cache.org/Versions/v3/3.1/squid-${version}.tar.bz2",
configure => template('squid/configure'),
preconfigure => template('squid/preconfigure')
}
file { $config:
content => template($config_template),
require => Build_and_install[$name]
}
$squid_start = 'service squid start'
$squid_stop = 'service squid stop'
god_init { $name:
start => $squid_start,
stop => $squid_stop,
restart => "${squid_stop} && ${squid_start}",
pid_file => $pid,
ensure => present,
require => File[$config],
interval => 10
}
file { [
"${data_dir}/errors/en/ERR_CANNOT_FORWARD",
"${data_dir}/errors/templates/ERR_CANNOT_FORWARD"
]:
content => template($error_template),
require => Build_and_install['squid']
}
}

View File

@ -1,4 +1,4 @@
<%= scope.function_template([ 'base/init-d-header' ]) %>
<%= scope.function_template('base/init-d-header') %>
<%= init_d_prolog %>
<%= init_d_prerun %>
@ -19,5 +19,5 @@ stop() {
echo "done"
}
<%= scope.function_template([ 'base/init-d-actions' ]) %>
<%= scope.function_template('base/init-d-actions') %>

View File

@ -0,0 +1,91 @@
class varnish($version, $vcl, $user = 'varnish', $group = 'varnish', $store_file_mb = 1024) {
$install_path = install_path($name, $version)
$config = config_path($name)
$share = share_path($name)
$data = data_path($name)
$sbin = sbin_path($name)
$bin_path = bin_path($name)
$bin = "${sbin}/${name}d"
$pid = pid_path($name)
$log = log_path($name)
$ncsa_bin = "${bin_path}/varnishncsa"
$ncsa_pid = pid_path('varnishncsa')
$ncsa_log = "${log}/access.log"
$vcl_path = "${config}/default.vcl"
$store_file_path = "${data}/store"
$store_file_size = $store_file_mb * 1024 * 1024
$varnish_start = "service varnish start"
$varnish_stop = "service varnish stop"
$varnish_rotate = "service varnish rotate"
$source = "http://repo.varnish-cache.org/source/varnish-${version}.tar.gz"
$dirs = [ $config, $log, $share, $data ]
build_and_install { $name:
version => $version,
source => $source
}
mkdir_p { $dirs:
path => $base::path,
require => Build_and_install[$name]
}
exec { "${name} 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
}
file { $vcl_path:
content => $vcl,
require => Build_and_install[$name]
}
god_init { $name:
start => $varnish_start,
stop => $varnish_stop,
dir => config_path('god.d'),
restart => "${varnish_stop} && ${varnish_start}",
pid_file => $pid,
ensure => present,
require => File[$vcl_path],
interval => 10
}
/* debian stuff */
if ($::osfamily == 'debian') {
user { $user: uid => 27835 }
$packages = [ 'libpcre3', 'libpcre3-dev', 'pkg-config' ]
package { $packages:
ensure => installed,
before => Build_and_install[$name]
}
exec { 'ensure-data-store-ownership':
command => "chown -R ${user}:${group} ${data}",
path => $base::path,
require => Exec["${name} create-store-file"]
}
logrotate_d { 'varnishncsa':
postrotate => 'service varnish rotate',
pattern => "${log}/access.log"
}
}
init_d { $name:
require => Mkdir_p[$dirs]
}
}

View File

@ -1,8 +0,0 @@
Facter.add('all_ip_addresses') do
setcode do
Facter.collection.list.find_all { |fact| fact[%r{^ipaddress_}] }.collect do |fact|
Facter[fact].value
end.compact.join(',')
end
end

View File

@ -1,6 +0,0 @@
Facter.add("varnish_cache_size") do
setcode do
%x{df -m /var}.lines.to_a.last.strip.split(/ +/)[1].to_i / 4
end
end

View File

@ -6,3 +6,4 @@ module Puppet::Parser::Functions
end
end

View File

@ -1,6 +0,0 @@
module Puppet::Parser::Functions
newfunction(:dir_size, :type => :rvalue) do |path|
%x{df -m #{path}}.lines.to_a.last.strip.split(/ +/)[1].to_i / 4
end
end

View File

@ -1,10 +0,0 @@
module Puppet::Parser::Functions
newfunction(:find_path, :type => :rvalue) do |name, root|
Pathname(root).find do |file|
return file.to_s if file.basename == name
end
raise StandardError.new("File not found in #{root}: #{name}")
end
end

View File

@ -2,8 +2,8 @@ Puppet::Type.type(:configure).provide(:action) do
desc "Configure a program to install"
def create
command = %{bash -c "cd #{@resource[:build_path]} && #{@resource[:preconfigure].gsub('"', '\\"')} #{path} ./configure --prefix=#{@resource[:install_path]} #{@resource[:options]}"}.tap { |o| p o }
system command
system %{bash -c "cd #{@resource[:build_path]} && #{@resource[:preconfigure].gsub('"', '\\"')} #{path} ./configure --prefix=#{@resource[:install_path]} #{@resource[:options]}"}.tap { |o| p o }
p $?
raise StandardError.new("Could not configure") if $?.exitstatus != 0
end
@ -12,7 +12,7 @@ Puppet::Type.type(:configure).provide(:action) do
end
def exists?
return unless? if unless? != nil
return true if unless?
File.file?(config_status)
end
@ -31,7 +31,7 @@ Puppet::Type.type(:configure).provide(:action) do
end
def path
@resource[:path].empty? ? '' : "PATH=#{@resource[:path]} "
@resource[:path].empty? ? '' : "PATH=#{@resource[:path]}:$PATH "
end
end

View File

@ -15,7 +15,7 @@ Puppet::Type.type(:download_and_unpack).provide(:action) do
end
def exists?
return unless? if unless? != nil
return true if unless?
File.directory?(File.join(@resource[:src_path], target_dir))
end

View File

@ -2,12 +2,6 @@ Puppet::Type.type(:git).provide(:clone) do
desc "Clone/pull a git repo"
def create
system key_check_command
if $?.exitstatus != 0
system keyscan_command
end
if File.directory?(path)
Dir.chdir(path) { system git_command("pull origin master") }
else
@ -25,27 +19,9 @@ Puppet::Type.type(:git).provide(:clone) do
private
def git_command(what)
path_wrap("git #{what}")
end
user_switch = @resource[:user] ? "sudo -u #{@resource[:user]} -- " : ""
def keyscan_command
path_wrap("ssh-keyscan -t dsa,rsa #{@resource[:host]} >> ~/.ssh/known_hosts")
end
def key_check_command
path_wrap("ssh-keygen -F #{@resource[:host]}")
end
def path_wrap(command)
command = %{PATH=#{@resource[:path]} #{command}}
if @resource[:user]
command = %{su -c "#{command}" #{@resource[:user]}}
else
command = %{sh -c "#{command}"}
end
command
%{bash -c 'PATH=#{@resource[:path]} #{user_switch} git #{what}'}
end
def path

View File

@ -1,17 +1,7 @@
require 'erb'
Puppet::Type.type(:god_init).provide(:install) do
desc "Install a God script for a non-daemonized process"
def self.def_resources(*args)
args.each do |arg|
class_eval <<-RB
def #{arg}
@resource[:#{arg}] || ''
end
RB
end
end
desc "Install a God script"
def create
FileUtils.mkdir_p File.dirname(file)
@ -31,28 +21,64 @@ Puppet::Type.type(:god_init).provide(:install) do
ERB.new(config).result(binding)
end
def_resources :start, :group, :name, :dir
def interval
@resource[:interval] || 30
end
private
def file
File.join(dir, "#{name}.god")
File.join(@resource[:dir], "#{@resource[:name]}.god")
end
def start
@resource[:start] || ''
end
def stop
@resource[:stop] || ''
end
def restart
@resource[:restart] || ''
end
def name
@resource[:name] || ''
end
def pid_file
@resource[:pid_file] || ''
end
def interval
@resource[:interval] || 5
end
def config
<<-GOD
God.watch do |w|
w.name = "<%= name %>"
<% if !group.empty? %>
w.group = "<%= group %>"
w.interval = <%= interval %>.seconds
w.start = lambda { system("<%= start %>") }
w.start_grace = <%= interval %>.seconds
<% if !stop.empty? %>
w.stop = lambda { system("<%= stop %>") ; system("killall -9 <%= name %>") }
<% end %>
w.interval = <%= interval %>.seconds
w.start = %{<%= start %>}
w.keepalive
<% if !restart.empty? %>
w.restart = lambda { system("<%= restart %>") }
<% end %>
<% if pid_file %>
w.pid_file = "<%= pid_file %>";
<% else %>
w.behavior(:clean_pid_file)
<% end %>
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = <%= interval %>.seconds
c.running = false
end
end
end
GOD
end

View File

@ -17,7 +17,7 @@ Puppet::Type.type(:make_and_install).provide(:action) do
end
def exists?
return unless? if unless? != nil
return true if unless?
File.directory?(@resource[:install_path]) && File.symlink?(symlink_path)
end

View File

@ -1,33 +0,0 @@
require 'pathname'
Puppet::Type.type(:sudoers_d).provide(:install) do
desc "Install a sudoers.d file"
def create
temp_target.open('w') { |fh| fh.puts content }
temp_target.chmod 0440
temp_target.rename(target)
end
def destroy
target.unlink
end
def exists?
target.file? and target.read == content
end
private
def target
@target ||= Pathname("/etc/sudoers.d/#{@resource[:name]}")
end
def temp_target
@temp_target ||= Pathname("/tmp/sudoers.d-#{@resource[:name]}-#{Time.now.to_f}")
end
def content
@resource[:content]
end
end

View File

@ -22,9 +22,5 @@ Puppet::Type.newtype(:git) do
newparam(:user) do
desc "The user to perform the command as"
end
newparam(:host) do
desc "The host to connect to"
end
end

View File

@ -11,14 +11,22 @@ Puppet::Type.newtype(:god_init) do
desc "The command to start the process"
end
newparam(:group) do
desc "The group this process belongs to"
newparam(:stop) do
desc "The command to stop the process"
end
newparam(:restart) do
desc "The command to restart/reload the process"
end
newparam(:dir) do
desc "The directory where god configs are held"
end
newparam(:pid_file) do
desc "A pid file"
end
newparam(:interval) do
desc "The check interval"
end

View File

@ -1,14 +0,0 @@
Puppet::Type.newtype(:sudoers_d) do
@doc = "Add a file to /etc/sudoers.d"
ensurable
newparam(:name) do
desc "The file to create"
end
newparam(:content) do
desc "The content of the file"
end
end

View File

@ -1,23 +0,0 @@
define debsource($apt_source, $keyfile = '', $host = '', $hash = '') {
$file = "/etc/apt/sources.list.d/${name}.list"
file { $file: content => $apt_source }
if ($host != '') {
exec { "debsource-${name}":
command => "apt-key adv --keyserver ${host} --recv ${hash} && apt-get update",
unless => "test $(apt-key list | grep ${hash} | wc -l) -ne 0",
path => $base::path,
require => File[$file]
}
}
if ($keyfile != '') {
exec { "debsource-${name}":
command => "curl $keyfile | apt-key add - && apt-get update",
path => $base::path,
require => File[$file],
unless => "test $(apt-key list | grep ${hash} | wc -l) -ne 0"
}
}
}

View File

@ -3,6 +3,7 @@
rotate 10000
missingok
compress
delaycompress
missingok
dateext
postrotate

View File

@ -1,14 +1,7 @@
define mkdir_p($path, $owner = '') {
define mkdir_p($path) {
exec { "mkdir -p ${name}":
path => $path,
unless => "test -d ${name}"
}
if ($owner != '') {
exec { "chown ${owner} ${name}":
path => $path,
require => Exec["mkdir -p ${name}"]
}
}
}

View File

@ -1,10 +0,0 @@
define remotedeb($url, $version) {
$deb = "/tmp/${name}.deb"
exec { "remotedeb-${name}":
command => "curl -o ${deb} ${url} && dpkg -i ${deb}",
unless => "test $(dpkg -l ${name} | grep ${version} | wc -l) -ne 0",
path => $base::path
}
}

View File

@ -5,8 +5,7 @@ define ssh {
ensure => directory,
mode => '0700',
owner => $name,
group => $name,
require => User[$name]
group => $name
}
file { "${ssh_dir}/authorized_keys":

View File

@ -1,12 +1,12 @@
#!/bin/bash
mkdir -p ~/.puppet
RUBYLIB="${PWD}/lib:${PWD}/shared/lib" \
<%= use_sudo ? "sudo env" : "" %> RUBYLIB="${PWD}/shared/lib" \
<%= with_additional_puppet_bin_path %> \
puppet apply <%= additional_puppet_options %> \
--confdir=$PWD \
--modulepath=$PWD/modules:$PWD/shared/modules \
--templatedir=$PWD/templates:$PWD/shared/templates \
-v --no-report $@ \
--modulepath=$PWD/modules:$PWD/shared/modules:$PWD/shared/additional-modules \
--templatedir=$PWD/shared/templates:$PWD/templates \
-v $@ \
manifests/site.pp

View File

@ -23,3 +23,5 @@ gem install puppet --no-ri --no-rdoc
./apply
shutdown -r now

View File

@ -1,8 +1,5 @@
#!/bin/bash
YAML_VERSION=0.1.4
RUBY_VERSION=1.9.3-p194
pwd=$PWD
base_dir=<%= base_dir %>
@ -13,23 +10,26 @@ if [ ! -f ${base_dir}/ruby-base/bin/ruby ]; then
opt_dir=${base_dir}/tmp/ruby-opt
rm -Rf yaml-$YAML_VERSION*
curl http://pyyaml.org/download/libyaml/yaml-$YAML_VERSION.tar.gz > yaml.tar.gz
tar zxvf yaml.tar.gz
mv yaml-$YAML_VERSION yaml-$YAML_VERSION-base
cd yaml-$YAML_VERSION-base
rm -Rf yaml-0.1.4*
curl -O http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar zxvf yaml-0.1.4.tar.gz
mv yaml-0.1.4 yaml-0.1.4-base
cd yaml-0.1.4-base
./configure --prefix=${opt_dir}
make
make install
cd ..
rm -Rf ruby-$RUBY_VERSION
curl ftp://ftp.ruby-lang.org/pub/ruby/ruby-$RUBY_VERSION.tar.bz2 > ruby.tar.bz2
tar jxvf ruby.tar.bz2
mv ruby-$RUBY_VERSION ruby-base
RUBY=ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.3-p194.tar.bz2
RUBY_FILENAME=${RUBY##*/}
RUBY_VERSION=${RUBY_FILENAME%%.tar.bz2}
curl $RUBY > $RUBY_FILENAME
rm -Rf $RUBY_VERSION
tar jxvf $RUBY_FILENAME
mv $RUBY_VERSION "$RUBY_VERSION-base"
cd ruby-base
cd "$RUBY_VERSION-base"
./configure --prefix=${base_dir}/ruby-base --with-opt-dir=${opt_dir} --disable-pthread --disable-install-doc
make
@ -49,4 +49,5 @@ if [ ! -f ${base_dir}/ruby-base/bin/puppet ]; then
fi
mkdir -p ~/.puppet
cd /tmp/puppet
./apply