Skip to content

Commit

Permalink
modules handling installation of yoxos & dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mruzicka committed Apr 18, 2012
0 parents commit 0e256c9
Show file tree
Hide file tree
Showing 24 changed files with 616 additions and 0 deletions.
Empty file added README
Empty file.
9 changes: 9 additions & 0 deletions modules/apache2/Modulefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name 'cloudsmith-apache2'
version '0.1.0'

author 'mruzicka'
license ''
project_page ''
source ''
summary 'Minimalistic Apache httpd'
description ''
24 changes: 24 additions & 0 deletions modules/apache2/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class apache2 {
$package = $::operatingsystem ? {
'Ubuntu' => 'apache2',
'CentOS' => 'httpd',
'Debian' => 'apache2',
default => 'httpd',
}

$service = $package

package { 'apache2':
name => "${package}",
ensure => latest,
}

service { 'apache2':
name => "${service}",
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
require => Package['apache2'],
}
}
9 changes: 9 additions & 0 deletions modules/apache2/manifests/variables.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class apache2::variables {
# TODO verify the locataion of config includes accross distros
$config_include_dir = $::operatingsystem ? {
'Ubuntu' => '/etc/httpd/conf.d',
'CentOS' => '/etc/httpd/conf.d',
'Debian' => '/etc/httpd/conf.d',
default => '/etc/httpd/conf.d',
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'digest/sha1'

SMALLINT_RANGE = 2 ** 16

# create a password hash of the suplied password in the same way couchdb does that
Puppet::Parser::Functions::newfunction(:couchdb_hash_password, :type => :rvalue) do |args|
password = args.shift()
raise ArgumentError, "password must be specified" if password.nil?

salt = args.shift()
if salt.nil? || salt.empty?
# compose a random salt string if not specified
salt = 8.times.map { "%04x" % rand(SMALLINT_RANGE) }.join()
else
# validate (and downcase) the specified salt string
raise ArgumentError, "salt must be a 32 characters long hexadecimal string" unless salt =~ /^[0-9A-Fa-f]{32}$/
salt = salt.downcase()
end

digester = Digest::SHA1.new()

digester.update(password)
digester.update(salt)

'-hashed-' << digester.hexdigest() << ',' << salt
end
32 changes: 32 additions & 0 deletions modules/couchdb/lib/puppet/parser/functions/format_as_ini_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'puppet/external/pson/common'
require 'puppet/external/pson/version'
require 'puppet/external/pson/pure'

# turn the suplied JSON data into a string having the ini file format
Puppet::Parser::Functions::newfunction(:format_as_ini_file, :type => :rvalue) do |args|
settings = {}
# treat all input arguments as JSON data
args.each() do |json|
begin
# parse the json data and merge the result to the hash holding the configuration settings
PSON.parse(json).each_pair() do |key, value|
values = settings[key] || {}
settings[key] = values.merge(value)
end
rescue => e
raise ArgumentError, "specified parameter is not a valid JSON configuration data: #{json}#{$/}"
end
end

# convert the configuration settings collected in the hash to the ini file format string
result = ''
settings.keys().sort().each() do |section|
result << "[#{section}]#{$/}"
values = settings[section]
values.keys().sort().each() do |key|
result << "#{key} = #{values[key]}#{$/}"
end
end

result
end
101 changes: 101 additions & 0 deletions modules/couchdb/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
class couchdb(
$install_dir = '/usr/local',
$ini_file_settings = '{}'
) {
include rubygems
include rubygems::common_dependencies

$couchdb_repository = 'git://git.apache.org/couchdb.git'
$couchdb_verion = 'tags/1.2.0'

$build_repository = 'git://github.com/iriscouch/build-couchdb.git'
$build_dir = '/var/cache/build-couchdb'

$build_dependencies = [
'automake', 'libtool', 'perl', 'help2man', 'libcurl-devel', 'openssl-devel', 'zlib-devel'
]

package { 'git':
ensure => latest,
}

package { [$build_dependencies]:
ensure => latest,
}

package { 'rake':
ensure => latest,
provider => gem,
}

exec { 'git-clone-build-repository':
command => "git clone \"${build_repository}\" \"${build_dir}\"",
path => ['/usr/local/bin', '/bin', '/usr/bin'],
creates => "${build_dir}",
require => Package['git'],
}

exec { 'git-update-build-submodules':
onlyif => 'git submodule status | grep -q ^[-+]',
command => 'git submodule update --init',
cwd => "${build_dir}",
path => ['/usr/local/bin', '/bin', '/usr/bin'],
require => Exec['git-clone-build-repository'],
}

exec { 'build-couchdb':
command => "rake git='${couchdb_repository} ${couchdb_verion}' install='${install_dir}'",
cwd => "${build_dir}",
path => ['/usr/local/bin', '/bin', '/usr/bin'],
creates => "${install_dir}/bin/couchdb",
timeout => 0,
require => Package['rake'],
subscribe => [Exec['git-clone-build-repository', 'git-update-build-submodules'], Class['rubygems::common_dependencies'], Package[$build_dependencies]],
}

group { 'couchdb':
ensure => present,
system => true,
}

user { 'couchdb':
ensure => present,
gid => 'couchdb',
system => true,
home => "${install_dir}/var/lib/couchdb",
managehome => false,
}

file { "${install_dir}/etc/couchdb/local.ini":
content => format_as_ini_file(template('couchdb/local.json.erb'), $ini_file_settings),
owner => root,
group => root,
mode => 0644,
require => Exec['build-couchdb'],
}

file { '/etc/init.d/couchdb':
ensure => link,
target => "${install_dir}/etc/rc.d/couchdb",
}

file { '/etc/logrotate.d/couchdb':
ensure => link,
target => "${install_dir}/etc/logrotate.d/couchdb",
}

file { ["${install_dir}/var/lib/couchdb", "${install_dir}/var/log/couchdb", "${install_dir}/var/run/couchdb"]:
owner => couchdb,
group => couchdb,
mode => 0755,
require => Exec['build-couchdb'],
}

service { 'couchdb':
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
subscribe => [Exec['build-couchdb'], File["${install_dir}/etc/couchdb/local.ini", '/etc/init.d/couchdb']],
}
}
9 changes: 9 additions & 0 deletions modules/couchdb/templates/local.json.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"couchdb": {
"delayed_commits": false
},

"httpd": {
"socket_options": "[{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]"
}
}
5 changes: 5 additions & 0 deletions modules/patch/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class patch {
package { 'patch':
ensure => latest,
}
}
9 changes: 9 additions & 0 deletions modules/rubygems/Modulefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name 'cloudsmith-rubygems'
version '0.1.0'

author 'mruzicka'
license ''
project_page ''
source ''
summary 'Module handling installation and updating of the ruby gem system'
description ''
38 changes: 38 additions & 0 deletions modules/rubygems/lib/facter/gems_system_latest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if Object.const_defined?(:Facter)
# this is a hack to install rubygems during collecting of facts
lambda do # we wrap the code to a lambda so that we can use "return" to exit early
begin
# install the rubygems package
catalog = Puppet::Resource::Catalog.new()
catalog.add_resource(Puppet::Resource.new('Package', 'rubygems'))
return if catalog.to_ral.apply().any_failed?()
rescue SystemExit, NoMemoryError
raise
rescue Exception => e
Facter.debug("could not install rubygems: #{e}\n#{e.backtrace}")
return
end

thisfile = File.expand_path(__FILE__)

Facter.add('gems_system_latest') do
setcode do
# run this file in a separate ruby interpreter
system('ruby', thisfile)
end
end
end.call
else
# this is executed if not run from facter
require 'rubygems'

name = 'rubygems-update'
dependency = Gem::Dependency.new(name, "> #{Gem::VERSION}")
candidates = Gem::SpecFetcher.fetcher.find_matching(dependency)

latest = candidates.find() { |(candidate_name, _, candidate_platform),|
candidate_name == name && Gem::Platform.match(candidate_platform)
}.nil?

exit latest ? 0 : 1
end
5 changes: 5 additions & 0 deletions modules/rubygems/manifests/common_dependencies.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class rubygems::common_dependencies {
package { ['gcc', 'gcc-c++', 'make', 'ruby-devel']:
ensure => installed,
}
}
8 changes: 8 additions & 0 deletions modules/rubygems/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class rubygems {
if($::gems_system_latest != 'true') {
exec { 'update-gems-system':
command => 'gem update --system',
path => ['/usr/local/bin', '/bin', '/usr/bin'],
} -> Package<| provider == gem |>
}
}
55 changes: 55 additions & 0 deletions modules/tomcat6/files/tomcat_script.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--- tomcat6 2012-03-20 00:22:33.000000000 +0000
+++ tomcat6 2012-04-18 14:33:02.757517809 +0000
@@ -27,7 +27,9 @@
CLASSPATH="${CLASSPATH}:$(build-classpath commons-daemon 2>/dev/null)"

if [ "$1" = "start" ]; then
- ${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
+ LOG="$2"
+ eval "set -- $JAVA_OPTS $CATALINA_OPTS"
+ ${JAVACMD} "$@" \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
@@ -36,12 +38,14 @@
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start \
- >> ${2} 2>&1 &
+ >> "$LOG" 2>&1 &
if [ ! -z "$CATALINA_PID" ]; then
echo $! > $CATALINA_PID
fi
elif [ "$1" = "start-security" ]; then
- ${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
+ LOG="$2"
+ eval "set -- $JAVA_OPTS $CATALINA_OPTS"
+ ${JAVACMD} "$@" \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
@@ -52,19 +56,21 @@
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start \
- >> ${2} 2>&1 &
+ >> "$LOG" 2>&1 &
if [ ! -z "$CATALINA_PID" ]; then
echo $! > $CATALINA_PID
fi
elif [ "$1" = "stop" ]; then
- ${JAVACMD} $JAVA_OPTS \
+ LOG="$2"
+ eval "set -- $JAVA_OPTS"
+ ${JAVACMD} "$@" \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap stop \
- >> ${2} 2>&1
+ >> "$LOG" 2>&1
elif [ "$1" = "version" ]; then
${JAVACMD} -classpath ${CATALINA_HOME}/lib/catalina.jar \
org.apache.catalina.util.ServerInfo
43 changes: 43 additions & 0 deletions modules/tomcat6/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class tomcat6 {
include patch

$package = $::operatingsystem ? {
'Ubuntu' => 'tomcat6',
'CentOS' => 'tomcat6',
'Debian' => 'tomcat6',
default => 'tomcat6',
}

$service = $package

$script_patch = '/usr/local/lib/tomcat_script.patch'

file { $script_patch:
source => 'puppet:///modules/tomcat6/tomcat_script.patch',
owner => root,
group => root,
mode => 0644,
}

package { 'tomcat6':
name => $package,
ensure => latest,
}

exec { 'patch-script':
unless => "patch --dry-run --reverse --force --quiet --input=\"${script_patch}\"",
command => "patch --force --quiet --input=\"${script_patch}\"",
cwd => '/usr/sbin',
path => ['/usr/local/bin', '/bin', '/usr/bin'],
require => [Package['tomcat6'], Class['patch'], File[$script_patch]],
}

service { 'tomcat6':
name => $service,
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
subscribe => [Package['tomcat6'], Exec['patch-script']],
}
}
Loading

0 comments on commit 0e256c9

Please sign in to comment.