summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-07-12 16:46:06 -0400
committerMicah <micah@leap.se>2016-07-12 16:46:06 -0400
commit4a11e48e397f1a7eb4c68a1dd1f9e3c5a11352f8 (patch)
tree66379b593391e99bb5dc66cf7e9ef48947d80a21
parent95d95925e53ec98f3f5868479328a69449de3ca7 (diff)
git subrepo clone https://leap.se/git/puppet_passenger puppet/modules/passenger
subrepo: subdir: "puppet/modules/passenger" merged: "47fca11" upstream: origin: "https://leap.se/git/puppet_passenger" branch: "master" commit: "47fca11" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "1e79595" Change-Id: Idba1129126ca0f13a4441e00d7b53e8b4f856825
-rw-r--r--puppet/modules/passenger/.gitrepo11
-rw-r--r--puppet/modules/passenger/README42
-rw-r--r--puppet/modules/passenger/files/mod_passenger.conf0
-rwxr-xr-xpuppet/modules/passenger/files/munin/passenger_memory_stats123
-rwxr-xr-xpuppet/modules/passenger/files/munin/passenger_stats47
-rw-r--r--puppet/modules/passenger/manifests/apache.pp7
-rw-r--r--puppet/modules/passenger/manifests/apache/base.pp4
-rw-r--r--puppet/modules/passenger/manifests/apache/centos.pp24
-rw-r--r--puppet/modules/passenger/manifests/apache/debian.pp24
-rw-r--r--puppet/modules/passenger/manifests/init.pp75
-rw-r--r--puppet/modules/passenger/manifests/munin.pp20
11 files changed, 377 insertions, 0 deletions
diff --git a/puppet/modules/passenger/.gitrepo b/puppet/modules/passenger/.gitrepo
new file mode 100644
index 00000000..7a402ad5
--- /dev/null
+++ b/puppet/modules/passenger/.gitrepo
@@ -0,0 +1,11 @@
+; DO NOT EDIT (unless you know what you are doing)
+;
+; This subdirectory is a git "subrepo", and this file is maintained by the
+; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
+;
+[subrepo]
+ remote = https://leap.se/git/puppet_passenger
+ branch = master
+ commit = 47fca117b594d30aa29d33f8d8846eeec0a88d5f
+ parent = 95d95925e53ec98f3f5868479328a69449de3ca7
+ cmdver = 0.3.0
diff --git a/puppet/modules/passenger/README b/puppet/modules/passenger/README
new file mode 100644
index 00000000..549432e2
--- /dev/null
+++ b/puppet/modules/passenger/README
@@ -0,0 +1,42 @@
+Passenger (mod_rails) puppet module
+-----------------------------------
+
+This puppet module handles a passenger setup, it installs the
+packages, and configures some munin graphs.
+
+Dependencies
+------------
+
+This module expects you to have:
+ . apache module
+
+Optional:
+ . munin module
+
+Getting started
+---------------
+
+Simply do 'include passenger' and it will be installed.
+
+Configuration
+-------------
+
+If you need to install a specific version of passenger or
+librack-ruby, you can specify the version to be installed by providing
+a variable, for example:
+
+class { 'passenger':
+ passenger_ensure_version => '2.2.23-2~bpo50+1',
+ librack-ruby_ensure_version = "1.0.0-2~bpo50+1"
+}
+
+If you wish to use gems, pass 'use_gems => true'.
+
+By default munin will be used, but you can disable that by passing
+'use_munin => false'.
+
+If you need to set different munin plugin configuration values, you
+can also do so as follows:
+
+$passenger_memory_munin_config = "user root\nenv.passenger_memory_stats /opt/bin/passenger-memory-stats"
+$passenger_stats_munin_config = "user root\nenv.PASSENGER_TMPDIR /var/tmp\n"
diff --git a/puppet/modules/passenger/files/mod_passenger.conf b/puppet/modules/passenger/files/mod_passenger.conf
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/puppet/modules/passenger/files/mod_passenger.conf
diff --git a/puppet/modules/passenger/files/munin/passenger_memory_stats b/puppet/modules/passenger/files/munin/passenger_memory_stats
new file mode 100755
index 00000000..eb9b2843
--- /dev/null
+++ b/puppet/modules/passenger/files/munin/passenger_memory_stats
@@ -0,0 +1,123 @@
+#!/usr/bin/env ruby
+pod=<<-POD
+
+=head1 NAME
+passenger_memory_stats - Munin plugin to monitor the memory usage of passenger application servers.
+Monitors the memory consumed by passenger instances.
+
+=head1 APPLICABLE SYSTEMS
+All systems that have passenger installed.
+
+=head1 CONFIGURATION
+The plugin needs to execute passenger-memory-stats.
+This configuration section shows the defaults of the plugin:
+
+ [passenger_*]
+ user root
+ command /usr/local/bin/ruby %c
+
+Options
+ env.passenger_memory_stats '/path/to/passenger-memory-stats' # Path to passenger memory status.
+ env.graph_category 'App' # Graph Category. Defaults to Passenger.
+
+ln -s /usr/share/munin/plugins/passenger_memory_stats /etc/munin/plugins/passenger_memory_stats
+
+=head1 INTERPRETATION
+The plugin shows the memory consumed by passenger instances.
+
+=head1 MAGIC MARKERS
+ #%# family=auto
+ #%# capabilities=autoconf
+
+=head1 VERSION
+1.5
+
+=head1 BUGS
+None known
+
+=head1 AUTHOR
+Ilya Lityuga
+Bart ten Brinke - railsdoctors.com
+
+=head1 LICENSE
+MIT
+
+POD
+
+# Globals
+GRAPH_CATEGORY = ENV['graph_category'] || 'Passenger'
+PASSENGER_MEMORY_STATS = ENV['passenger_memory_stats'] || '/usr/local/bin/passenger-memory-stats'
+
+# Check if this plugin can run
+def autoconf
+ begin
+ require 'rubygems'
+ gem "passenger", ">=2.0"
+ rescue Exception => e
+ puts "no (Gem not found: #{e})"
+ exit 1
+ end
+
+ status = `#{PASSENGER_MEMORY_STATS}`
+ unless $?.success?
+ puts "no (error when executing #{PASSENGER_MEMORY_STATS})"
+ exit 1
+ end
+
+ puts "yes"
+ exit 0
+end
+
+# Describe the graph config
+def config
+ status = `#{PASSENGER_MEMORY_STATS}`
+ memory_info = open('/proc/meminfo', 'r') do |lines|
+ lines.inject({}) do |h, line|
+ matched = line.match(/^([\w_\(\)]+):\s+(\d+)/)
+ h[matched[1].to_sym] = matched[2].to_i * 1024
+ h
+ end
+ end
+ upper_limit = memory_info[:MemTotal]
+ puts <<-CONFIG
+graph_category #{GRAPH_CATEGORY}
+graph_title Passenger memory stats
+graph_vlabel Bytes
+graph_args --base 1000 -l 0 --upper-limit #{upper_limit}
+graph_info The memory used by passenger instances on this application server
+
+memory.label memory
+CONFIG
+ exit 0
+end
+
+
+# Collect the data
+# <tt>debug</tt> Show debug information
+def run(debug = false)
+ stats = `#{PASSENGER_MEMORY_STATS}`
+
+ unless $?.success?
+ $stderr.puts "failed executing passenger-memory-stats"
+ exit 1
+ end
+
+ puts stats if debug
+
+ #### Total private dirty RSS: 81.81 MB
+ stats =~ /RSS:\s*([\d\.]+)\s*MB\Z/m
+ memory = ($1.to_f * 1024 * 1024).to_i
+ puts "memory.value #{memory}"
+end
+
+
+# Main
+if ARGV[0] == "config"
+ config
+elsif ARGV[0] == "autoconf"
+ autoconf
+elsif ARGV[0] == "debug"
+ run(true)
+else
+ run
+end
diff --git a/puppet/modules/passenger/files/munin/passenger_stats b/puppet/modules/passenger/files/munin/passenger_stats
new file mode 100755
index 00000000..f06e88a0
--- /dev/null
+++ b/puppet/modules/passenger/files/munin/passenger_stats
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+PASSENGER_STATUS = ENV['passenger_status'] || '/usr/local/bin/passenger-status'
+
+def output_config
+ puts <<-END
+graph_category Passenger
+graph_title passenger status
+graph_vlabel count
+
+sessions.label sessions
+max.label max processes
+running.label running processes
+active.label active processes
+inactive.label inactive processes
+END
+ exit 0
+end
+
+def output_values
+ status = `#{PASSENGER_STATUS}`
+ unless $?.success?
+ $stderr.puts "failed executing passenger-status"
+ exit 1
+ end
+ status =~ /max\s+=\s+(\d+)/
+ puts "max.value #{$1}"
+
+ status =~ /count\s+=\s+(\d+)/
+ puts "running.value #{$1}"
+
+ status =~ /active\s+=\s+(\d+)/
+ puts "active.value #{$1}"
+
+ status =~ /inactive\s+=\s+(\d+)/
+ puts "inactive.value #{$1}"
+
+ total_sessions = 0
+ status.scan(/Sessions: (\d+)/).flatten.each { |count| total_sessions += count.to_i }
+ puts "sessions.value #{total_sessions}"
+end
+
+if ARGV[0] == "config"
+ output_config
+else
+ output_values
+end
diff --git a/puppet/modules/passenger/manifests/apache.pp b/puppet/modules/passenger/manifests/apache.pp
new file mode 100644
index 00000000..d4181ffe
--- /dev/null
+++ b/puppet/modules/passenger/manifests/apache.pp
@@ -0,0 +1,7 @@
+class passenger::apache{
+ case $operatingsystem {
+ centos: { include passenger::apache::centos }
+ debian: { include passenger::apache::debian }
+ defaults: { include passenger::apache::base }
+ }
+}
diff --git a/puppet/modules/passenger/manifests/apache/base.pp b/puppet/modules/passenger/manifests/apache/base.pp
new file mode 100644
index 00000000..441c9bd5
--- /dev/null
+++ b/puppet/modules/passenger/manifests/apache/base.pp
@@ -0,0 +1,4 @@
+class passenger::apache::base {
+ # Todo !
+ include apache
+}
diff --git a/puppet/modules/passenger/manifests/apache/centos.pp b/puppet/modules/passenger/manifests/apache/centos.pp
new file mode 100644
index 00000000..b7b80e3b
--- /dev/null
+++ b/puppet/modules/passenger/manifests/apache/centos.pp
@@ -0,0 +1,24 @@
+class passenger::apache::centos inherits passenger::apache::base {
+
+ package { 'mod_passenger':
+ ensure => installed,
+ require => Package['apache'],
+ }
+
+ file { '/var/www/passenger_buffer':
+ ensure => directory,
+ require => [ Package['apache'], Package['mod_passenger'] ],
+ owner => apache,
+ group => 0,
+ mode => '0600';
+ }
+
+ file{ '/etc/httpd/conf.d/mod_passenger_custom.conf':
+ content => "PassengerUploadBufferDir /var/www/passenger_buffer\n",
+ require => File['/var/www/passenger_buffer'],
+ notify => Service['apache'],
+ owner => root,
+ group => 0,
+ mode => '0644';
+ }
+}
diff --git a/puppet/modules/passenger/manifests/apache/debian.pp b/puppet/modules/passenger/manifests/apache/debian.pp
new file mode 100644
index 00000000..38eb3fa4
--- /dev/null
+++ b/puppet/modules/passenger/manifests/apache/debian.pp
@@ -0,0 +1,24 @@
+class passenger::apache::debian inherits passenger::apache::base {
+
+ package { 'libapache2-mod-passenger':
+ ensure => installed,
+ require => Package['apache2'],
+ }
+
+ file { '/var/www/passenger_buffer':
+ ensure => directory,
+ require => [ Package['apache2'], Package['libapache2-mod-passenger'] ],
+ owner => www-data,
+ group => 0,
+ mode => '0600';
+ }
+
+ file { '/etc/apache2/conf.d/mod_passenger_custom.conf':
+ content => "PassengerUploadBufferDir /var/www/passenger_buffer\n",
+ require => File['/var/www/passenger_buffer'],
+ notify => Service['apache2'],
+ owner => root,
+ group => 0,
+ mode => '0644';
+ }
+}
diff --git a/puppet/modules/passenger/manifests/init.pp b/puppet/modules/passenger/manifests/init.pp
new file mode 100644
index 00000000..ed9b8c31
--- /dev/null
+++ b/puppet/modules/passenger/manifests/init.pp
@@ -0,0 +1,75 @@
+# passenger module
+#
+# Copyright 2010, Riseup Networks
+# Micah Anderson micah(at)riseup.net
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+
+class passenger (
+ $use_gems = false, $manage_munin = false,
+ $passenger_ensure_version = 'installed',
+ $librack_ensure_version = 'installed',
+ $passenger_bin_path = '/usr/sbin' )
+{
+ Class['::apache'] -> Class['passenger']
+
+ if ! $use_gems {
+
+ apache::module { 'passenger':
+ ensure => $passenger_ensure_version,
+ package_name => 'libapache2-mod-passenger';
+ }
+
+ if !defined(Package['librack-ruby']) {
+ if $::lsbdistcodename == 'squeeze' {
+ package { 'librack-ruby1.8': ensure => $librack_ensure_version }
+ }
+ else {
+ package { 'ruby-rack':
+ ensure => $librack_ensure_version;
+ }
+ }
+ }
+ }
+ else {
+ package {
+ 'passenger':
+ ensure => $passenger_ensure_version,
+ provider => gem;
+ 'rack':
+ ensure => $librack_ensure_version,
+ provider => gem;
+ }
+ }
+
+ apache::config::file { 'mod_passenger':
+ ensure => present,
+ source => [ "puppet:///modules/site_passenger/${::fqdn}/mod_passenger.conf",
+ 'puppet:///modules/site_passenger/mod_passenger.conf',
+ 'puppet:///modules/passenger/mod_passenger.conf',
+ ],
+ }
+
+ if $manage_munin {
+ if $passenger_memory_munin_config == '' {
+ $passenger_memory_munin_config = "user root\nenv.passenger_memory_stats ${passenger_bin_path}/passenger-memory-stats"
+ }
+
+ if $passenger_stats_munin_config == '' {
+ $passenger_stats_munin_config = "user root\nenv.passenger_status ${passenger_bin_path}/passenger-status"
+ }
+
+ munin::plugin::deploy {
+ 'passenger_memory_stats':
+ source => 'passenger/munin/passenger_memory_stats',
+ config => $passenger_memory_munin_config;
+ 'passenger_stats':
+ source => 'passenger/munin/passenger_stats',
+ config => $passenger_stats_munin_config;
+ }
+ }
+
+}
+
diff --git a/puppet/modules/passenger/manifests/munin.pp b/puppet/modules/passenger/manifests/munin.pp
new file mode 100644
index 00000000..36bc53f2
--- /dev/null
+++ b/puppet/modules/passenger/manifests/munin.pp
@@ -0,0 +1,20 @@
+class passenger::munin {
+
+ case $passenger_memory_munin_config { '':
+ { $passenger_memory_munin_config = "user root\nenv.passenger_memory_stats /usr/sbin/passenger-memory-stats" }
+ }
+
+ case $passenger_stats_munin_config { '':
+ { $passenger_stats_munin_config = "user root\n" }
+ }
+
+ munin::plugin::deploy {
+ 'passenger_memory_stats':
+ source => 'passenger/munin/passenger_memory_stats',
+ config => $passenger_memory_munin_config;
+ 'passenger_stats':
+ source => 'passenger/munin/passenger_stats',
+ config => $passenger_stats_munin_config;
+ }
+
+}