Skip to content

Commit

Permalink
Add support for CentOS
Browse files Browse the repository at this point in the history
  • Loading branch information
omarqureshi committed Jun 19, 2011
1 parent 3f6d59a commit e10e6f3
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 149 deletions.
18 changes: 5 additions & 13 deletions lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@
desc "Ruby RVM support."

commands :rvmcmd => "/usr/local/rvm/bin/rvm"

def create
command = [command(:rvmcmd), "install", resource[:name]]
output = execute(command)
rvmcmd "install", resource[:name]
end

def destroy
rvmcmd "uninstall", resource[:name]
end

def exists?
command = [command(:rvmcmd), "list", "strings"]

begin
execute(command).any? do |line|
rvmcmd("list", "strings").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
Expand All @@ -26,9 +23,8 @@ def exists?
end

def default_use
command = [command(:rvmcmd), "list", "default", "string"]
begin
execute(command).any? do |line|
rvmcmd("list", "default", "string").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
Expand All @@ -37,10 +33,6 @@ def default_use
end

def default_use=(value)
if value
rvmcmd "--default", "use", resource[:name]
else
rvmcmd "--default", "use", "system"
end
rvmcmd "--default", "use", value || resource[:name]
end
end
2 changes: 0 additions & 2 deletions lib/puppet/type/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

newparam(:name) do
desc "The name of the Ruby to be managed."

isnamevar
end

newproperty(:default_use) do
desc "Should this Ruby be the system default for new terminals?"

defaultto false
end
end
27 changes: 27 additions & 0 deletions manifests/classes/dependencies-centos.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class rvm::dependencies::centos {

if ! defined(Package['which']) { package { 'which': ensure => installed } }
if ! defined(Package['gcc']) { package { 'gcc': ensure => installed } }
if ! defined(Package['gcc-c++']) { package { 'gcc-c++': ensure => installed } }
if ! defined(Package['make']) { package { 'make': ensure => installed } }
if ! defined(Package['gettext-devel']) { package { 'gettext-devel': ensure => installed } }
if ! defined(Package['expat-devel']) { package { 'expat-devel': ensure => installed } }
if ! defined(Package['curl-devel']) { package { 'curl-devel': ensure => installed } }
if ! defined(Package['zlib-devel']) { package { 'zlib-devel': ensure => installed } }
if ! defined(Package['openssl-devel']) { package { 'openssl-devel': ensure => installed } }
if ! defined(Package['perl']) { package { 'perl': ensure => installed } }
if ! defined(Package['cpio']) { package { 'cpio': ensure => installed } }
if ! defined(Package['expat-devel']) { package { 'expat-devel': ensure => installed } }
if ! defined(Package['gettext-devel']) { package { 'gettext-devel': ensure => installed } }
if ! defined(Package['wget']) { package { 'wget': ensure => installed } }
if ! defined(Package['bzip2']) { package { 'bzip2': ensure => installed } }
if ! defined(Package['sendmail']) { package { 'sendmail': ensure => installed } }
if ! defined(Package['mailx']) { package { 'mailx': ensure => installed } }
if ! defined(Package['libxml2']) { package { 'libxml2': ensure => installed } }
if ! defined(Package['libxml2-devel']) { package { 'libxml2-devel': ensure => installed } }
if ! defined(Package['libxslt']) { package { 'libxslt': ensure => installed } }
if ! defined(Package['libxslt-devel']) { package { 'libxslt-devel': ensure => installed } }
if ! defined(Package['readline-devel']) { package { 'readline-devel': ensure => installed } }
if ! defined(Package['patch']) { package { 'patch': ensure => installed } }
if ! defined(Package['git']) { package { 'git': ensure => installed } }
}
22 changes: 22 additions & 0 deletions manifests/classes/dependencies-ubuntu.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class rvm::dependencies::ubuntu {

if ! defined(Package['build-essential']) { package { 'build-essential': ensure => installed } }
if ! defined(Package['bison']) { package { 'bison': ensure => installed } }
if ! defined(Package['openssl']) { package { 'openssl': ensure => installed } }
if ! defined(Package['libreadline6']) { package { 'libreadline6': ensure => installed } }
if ! defined(Package['libreadline6-dev']) { package { 'libreadline6-dev': ensure => installed } }
if ! defined(Package['curl']) { package { 'curl': ensure => installed } }
if ! defined(Package['git-core']) { package { 'git-core': ensure => installed } }
if ! defined(Package['zlib1g']) { package { 'zlib1g': ensure => installed } }
if ! defined(Package['zlib1g-dev']) { package { 'zlib1g-dev': ensure => installed } }
if ! defined(Package['libssl-dev']) { package { 'libssl-dev': ensure => installed } }
if ! defined(Package['libyaml-dev']) { package { 'libyaml-dev': ensure => installed } }
if ! defined(Package['libsqlite3-0']) { package { 'libsqlite3-0': ensure => installed } }
if ! defined(Package['libsqlite3-dev']) { package { 'libsqlite3-dev': ensure => installed } }
if ! defined(Package['sqlite3']) { package { 'sqlite3': ensure => installed } }
if ! defined(Package['libxml2-dev']) { package { 'libxml2-dev': ensure => installed } }
if ! defined(Package['libxslt1-dev']) { package { 'libxslt1-dev': ensure => installed, alias => 'libxslt-dev' } }
if ! defined(Package['autoconf']) { package { 'autoconf': ensure => installed } }
if ! defined(Package['libc6-dev']) { package { 'libc6-dev': ensure => installed } }

}
24 changes: 4 additions & 20 deletions manifests/classes/dependencies.pp
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
class rvm::dependencies {

if ! defined(Package['build-essential']) { package { 'build-essential': ensure => installed } }
if ! defined(Package['bison']) { package { 'bison': ensure => installed } }
if ! defined(Package['openssl']) { package { 'openssl': ensure => installed } }
if ! defined(Package['libreadline6']) { package { 'libreadline6': ensure => installed } }
if ! defined(Package['libreadline6-dev']) { package { 'libreadline6-dev': ensure => installed } }
if ! defined(Package['curl']) { package { 'curl': ensure => installed } }
if ! defined(Package['git-core']) { package { 'git-core': ensure => installed } }
if ! defined(Package['zlib1g']) { package { 'zlib1g': ensure => installed } }
if ! defined(Package['zlib1g-dev']) { package { 'zlib1g-dev': ensure => installed } }
if ! defined(Package['libssl-dev']) { package { 'libssl-dev': ensure => installed } }
if ! defined(Package['libyaml-dev']) { package { 'libyaml-dev': ensure => installed } }
if ! defined(Package['libsqlite3-0']) { package { 'libsqlite3-0': ensure => installed } }
if ! defined(Package['libsqlite3-dev']) { package { 'libsqlite3-dev': ensure => installed } }
if ! defined(Package['sqlite3']) { package { 'sqlite3': ensure => installed } }
if ! defined(Package['libxml2-dev']) { package { 'libxml2-dev': ensure => installed } }
if ! defined(Package['libxslt1-dev']) { package { 'libxslt1-dev': ensure => installed, alias => 'libxslt-dev' } }
if ! defined(Package['autoconf']) { package { 'autoconf': ensure => installed } }
if ! defined(Package['libc6-dev']) { package { 'libc6-dev': ensure => installed } }

case $operatingsystem {
Ubuntu: { include rvm::dependencies::ubuntu }
CentOS: { include rvm::dependencies::centos }
}
}
18 changes: 18 additions & 0 deletions manifests/classes/passenger-centos-post.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class rvm::passenger::apache::centos::post {

exec {
'passenger-install-apache2-module':
command => "${binpath}rvm ${ruby_version} exec passenger-install-apache2-module -a",
creates => "${gempath}/passenger-${version}/ext/apache2/mod_passenger.so",
logoutput => 'on_failure',
require => [Rvm_gem['passenger'], Package['httpd','httpd-devel','mod_ssl']];
}

file {
'/etc/httpd/conf.d/passenger.conf':
content => template('rvm/passenger-apache-centos.conf.erb'),
ensure => file,
require => Exec['passenger-install-apache2-module'];
}

}
7 changes: 7 additions & 0 deletions manifests/classes/passenger-centos-pre.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class rvm::passenger::apache::centos::pre {

# Dependencies
if ! defined(Package["httpd"]) { package { "httpd": ensure => installed } }
if ! defined(Package["httpd-devel"]) { package { "httpd-devel": ensure => installed } }

}
8 changes: 8 additions & 0 deletions manifests/classes/passenger-gem.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class rvm::passenger::gem($ruby_version, $version, $rvm_prefix) {
rvm_gem {
"passenger":
ruby_version => $ruby_version,
ensure => $version,
rvm_prefix => $rvm_prefix,
}
}
53 changes: 53 additions & 0 deletions manifests/classes/passenger-ubuntu-post.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class rvm::passenger::apache::ubuntu::post {

exec {
'passenger-install-apache2-module':
command => "${binpath}rvm ${ruby_version} exec passenger-install-apache2-module -a",
creates => "${gempath}/passenger-${version}/ext/apache2/mod_passenger.so",
logoutput => 'on_failure',
require => [Rvm_gem['passenger'], Package['apache2', 'build-essential', 'apache2-prefork-dev',
'libapr-dev', 'libaprutil-dev', 'libcurl4-openssl-dev']],
}

file {
'/etc/apache2/mods-available/passenger.load':
content => "LoadModule passenger_module ${gempath}/passenger-${version}/ext/apache2/mod_passenger.so",
ensure => file,
require => Exec['passenger-install-apache2-module'];

'/etc/apache2/mods-available/passenger.conf':
content => template('rvm/passenger-apache.conf.erb'),
ensure => file,
require => Exec['passenger-install-apache2-module'];

'/etc/apache2/mods-enabled/passenger.load':
ensure => 'link',
target => '../mods-available/passenger.load',
require => File['/etc/apache2/mods-available/passenger.load'];

'/etc/apache2/mods-enabled/passenger.conf':
ensure => 'link',
target => '../mods-available/passenger.conf',
require => File['/etc/apache2/mods-available/passenger.conf'];
}

# Add Apache restart hooks
if defined(Service['apache']) {
File['/etc/apache2/mods-available/passenger.load'] ~> Service['apache']
File['/etc/apache2/mods-available/passenger.conf'] ~> Service['apache']
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['apache']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['apache']
}
if defined(Service['apache2']) {
File['/etc/apache2/mods-available/passenger.load'] ~> Service['apache2']
File['/etc/apache2/mods-available/passenger.conf'] ~> Service['apache2']
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['apache2']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['apache2']
}
if defined(Service['httpd']) {
File['/etc/apache2/mods-available/passenger.load'] ~> Service['httpd']
File['/etc/apache2/mods-available/passenger.conf'] ~> Service['httpd']
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['httpd']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['httpd']
}
}
12 changes: 12 additions & 0 deletions manifests/classes/passenger-ubuntu-pre.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class rvm::passenger::apache::ubuntu::pre {

include apache
# Dependencies
if ! defined(Package['build-essential']) { package { build-essential: ensure => installed } }
if ! defined(Package['apache2-prefork-dev']) { package { apache2-prefork-dev: ensure => installed } }
if ! defined(Package['libapr1-dev']) { package { libapr1-dev: ensure => installed, alias => 'libapr-dev' } }
if ! defined(Package['libaprutil1-dev']) { package { libaprutil1-dev: ensure => installed, alias => 'libaprutil-dev' } }
if ! defined(Package['libcurl4-openssl-dev']) { package { libcurl4-openssl-dev: ensure => installed } }


}
139 changes: 26 additions & 113 deletions manifests/classes/passenger.pp
Original file line number Diff line number Diff line change
@@ -1,122 +1,35 @@

class rvm::passenger($ruby_version, $version, $rvm_prefix) {
rvm_gem {
'passenger':
ruby_version => $ruby_version,
ensure => $version,
rvm_prefix => $rvm_prefix,
require => Rvm_system_ruby[$ruby_version];
}
}


class rvm::passenger::apache(
$ruby_version,
$version,
$rvm_prefix = '/usr/local/',
$mininstances = '1',
$maxpoolsize = '6',
$poolidletime = '300',
$maxinstancesperapp = '0',
$spawnmethod = 'smart-lv2'
$ruby_version,
$version,
$rvm_prefix = '/usr/local/',
$mininstances = '1',
$maxpoolsize = '6',
$poolidletime = '300',
$maxinstancesperapp = '0',
$spawnmethod = 'smart-lv2'
) {

# TODO: How to inherit this from above?
class { 'rvm::passenger': ruby_version => $ruby_version, version => $version, rvm_prefix => $rvm_prefix }
include apache

include rvm::passenger::gem

case $operatingsystem {
Ubuntu: { include rvm::passenger::apache::ubuntu::pre }
CentOS: { include rvm::passenger::apache::centos::pre }
}

class {
'rvm::passenger::gem':
ruby_version => $ruby_version,
version => $version,
rvm_prefix => $rvm_prefix
}

# TODO: How can we get the gempath automatically using the ruby version
# Can we read the output of a command into a variable?
# e.g. $gempath = `usr/local/bin/rvm ${ruby_version} exec rvm gemdir`
$gempath = "${rvm_prefix}rvm/gems/${ruby_version}/gems"
$binpath = "${rvm_prefix}rvm/bin/"


# Dependencies
if ! defined(Package['build-essential']) { package { build-essential: ensure => installed } }
if ! defined(Package['apache2-prefork-dev']) { package { apache2-prefork-dev: ensure => installed } }
if ! defined(Package['libapr1-dev']) { package { libapr1-dev: ensure => installed, alias => 'libapr-dev' } }
if ! defined(Package['libaprutil1-dev']) { package { libaprutil1-dev: ensure => installed, alias => 'libaprutil-dev' } }
if ! defined(Package['libcurl4-openssl-dev']) { package { libcurl4-openssl-dev: ensure => installed } }

exec {
'passenger-install-apache2-module':
command => "${binpath}rvm ${ruby_version} exec passenger-install-apache2-module -a",
creates => "${gempath}/passenger-${version}/ext/apache2/mod_passenger.so",
logoutput => 'on_failure',
require => [Rvm_gem['passenger'], Package[
'apache2',
'build-essential',
'apache2-prefork-dev',
'libapr-dev',
'libaprutil-dev',
'libcurl4-openssl-dev'
]];
}

file {
'/etc/apache2/mods-available/passenger.load':
content => "LoadModule passenger_module ${gempath}/passenger-${version}/ext/apache2/mod_passenger.so",
ensure => file,
require => Exec['passenger-install-apache2-module'];

'/etc/apache2/mods-available/passenger.conf':
content => template('rvm/passenger-apache.conf.erb'),
ensure => file,
require => Exec['passenger-install-apache2-module'];

'/etc/apache2/mods-enabled/passenger.load':
ensure => 'link',
target => '../mods-available/passenger.load',
require => File['/etc/apache2/mods-available/passenger.load'];

'/etc/apache2/mods-enabled/passenger.conf':
ensure => 'link',
target => '../mods-available/passenger.conf',
require => File['/etc/apache2/mods-available/passenger.conf'];
}

# Add Apache restart hooks
if defined(Service['apache']) {
File['/etc/apache2/mods-available/passenger.load'] ~> Service['apache']
File['/etc/apache2/mods-available/passenger.conf'] ~> Service['apache']
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['apache']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['apache']
}
if defined(Service['apache2']) {
File['/etc/apache2/mods-available/passenger.load'] ~> Service['apache2']
File['/etc/apache2/mods-available/passenger.conf'] ~> Service['apache2']
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['apache2']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['apache2']
}
if defined(Service['httpd']) {
File['/etc/apache2/mods-available/passenger.load'] ~> Service['httpd']
File['/etc/apache2/mods-available/passenger.conf'] ~> Service['httpd']
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['httpd']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['httpd']
}
}

class rvm::passenger::apache::disable {

file {
'/etc/apache2/mods-enabled/passenger.load':
ensure => 'absent';
'/etc/apache2/mods-enabled/passenger.conf':
ensure => 'absent';
}

# Add Apache restart hooks
if defined(Service['apache']) {
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['apache']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['apache']
}
if defined(Service['apache2']) {
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['apache2']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['apache2']
}
if defined(Service['httpd']) {
File['/etc/apache2/mods-enabled/passenger.load'] ~> Service['httpd']
File['/etc/apache2/mods-enabled/passenger.conf'] ~> Service['httpd']
case $operatingsystem {
Ubuntu: { include rvm::passenger::apache::ubuntu::post }
CentOS: { include rvm::passenger::apache::centos::post }
}
}
}
Loading

0 comments on commit e10e6f3

Please sign in to comment.