From 4a19b54683583900cb2456590bc764d25329b6fc Mon Sep 17 00:00:00 2001
From: Jeremy Stanley <fungi@yuggoth.org>
Date: Mon, 28 Jan 2013 19:44:38 +0000
Subject: [PATCH] Restore cgroup-bin Upstart jobs on Ubuntu Quantal.

* modules/jenkins/files/cgroups/upstart_cgconfig: Very trivial
Upstart job to load /etc/cgconfig.conf once cgroup-lite has started.

* modules/jenkins/files/cgroups/upstart_cgred: Very trivial Upstart
job to start cgred once cgconfig has been loaded.

* modules/jenkins/manifests/cgroups.pp: Conditionally add Upstart
jobs cgconfig and cgred if Ubuntu >= 12.10. They used to exist, but
were dropped in the process of refactoring cgroup support after
Precise.

* modules/jenkins/manifests/params.pp: Add parameter lists for the
cgconfig and cgred dependencies since they differ between RHEL and
Ubuntu.

* modules/jenkins/templates/cgconfig.erb: Conditionally omit the
default cgroup mounts section on Ubuntu Quantal or later.

Change-Id: I16e2996387d534928a3cfa90de9159fbe02bbdd2
Reviewed-on: https://review.openstack.org/20638
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Reviewed-by: James E. Blair <corvus@inaugust.com>
Approved: Jeremy Stanley <fungi@yuggoth.org>
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Tested-by: Jenkins
---
 .../jenkins/files/cgroups/upstart_cgconfig    |  6 +++
 modules/jenkins/files/cgroups/upstart_cgred   |  6 +++
 modules/jenkins/manifests/cgroups.pp          | 51 ++++++++++++++++++-
 modules/jenkins/manifests/params.pp           | 10 ++++
 modules/jenkins/templates/cgconfig.erb        |  2 +-
 5 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 modules/jenkins/files/cgroups/upstart_cgconfig
 create mode 100644 modules/jenkins/files/cgroups/upstart_cgred

diff --git a/modules/jenkins/files/cgroups/upstart_cgconfig b/modules/jenkins/files/cgroups/upstart_cgconfig
new file mode 100644
index 0000000000..80a12e01f9
--- /dev/null
+++ b/modules/jenkins/files/cgroups/upstart_cgconfig
@@ -0,0 +1,6 @@
+description "load legacy cgconfig files"
+author "Jeremy Stanley <fungi@yuggoth.org>"
+start on started cgroup-lite
+pre-start script
+	/usr/sbin/cgconfigparser -l /etc/cgconfig.conf
+end script
diff --git a/modules/jenkins/files/cgroups/upstart_cgred b/modules/jenkins/files/cgroups/upstart_cgred
new file mode 100644
index 0000000000..b6802f24c9
--- /dev/null
+++ b/modules/jenkins/files/cgroups/upstart_cgred
@@ -0,0 +1,6 @@
+description "launch cgrulesengd"
+author "Jeremy Stanley <fungi@yuggoth.org>"
+start on started cgconfig
+pre-start script
+	/usr/sbin/cgrulesengd
+end script
diff --git a/modules/jenkins/manifests/cgroups.pp b/modules/jenkins/manifests/cgroups.pp
index 91b936d0cb..e8573d33b7 100644
--- a/modules/jenkins/manifests/cgroups.pp
+++ b/modules/jenkins/manifests/cgroups.pp
@@ -27,17 +27,64 @@ class jenkins::cgroups {
     source  => 'puppet:///modules/jenkins/cgroups/cgrules.conf',
   }
 
+  # Starting with Ubuntu Quantal (12.10) cgroup-bin dropped its upstart jobs.
+  if $::operatingsystem == 'Ubuntu' {
+
+    if $::operatingsystemrelease >= '12.10' {
+
+      file { '/etc/init/cgconfig.conf':
+        ensure  => present,
+        replace => true,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0644',
+        source  => 'puppet:///modules/jenkins/cgroups/upstart_cgconfig',
+      }
+
+      file { '/etc/init.d/cgconfig':
+        ensure => link,
+        target => '/lib/init/upstart-job',
+      }
+
+      file { '/etc/init/cgred.conf':
+        ensure  => present,
+        replace => true,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0644',
+        source  => 'puppet:///modules/jenkins/cgroups/upstart_cgred',
+      }
+
+      file { '/etc/init.d/cgred':
+        ensure => link,
+        target => '/lib/init/upstart-job',
+      }
+
+    } else {
+
+      file { '/etc/init/cgconfig.conf':
+        ensure  => present,
+      }
+
+      file { '/etc/init/cgred.conf':
+        ensure  => present,
+      }
+
+    }
+
+  }
+
   service { 'cgconfig':
     ensure    => running,
     enable    => true,
-    require   => Package['cgroups'],
+    require   => $::jenkins::params::cgconfig_require,
     subscribe => File['/etc/cgconfig.conf'],
   }
 
   service { 'cgred':
     ensure    => running,
     enable    => true,
-    require   => Package['cgroups'],
+    require   => $::jenkins::params::cgred_require,
     subscribe => File['/etc/cgrules.conf'],
   }
 }
diff --git a/modules/jenkins/manifests/params.pp b/modules/jenkins/manifests/params.pp
index a4f7ba8240..3260f867e0 100644
--- a/modules/jenkins/manifests/params.pp
+++ b/modules/jenkins/manifests/params.pp
@@ -44,6 +44,8 @@ class jenkins::params {
       $xslt_package = 'libxslt'
       $xvfb_package = 'xorg-x11-server-Xvfb'
       $cgroups_package = 'libcgroup'
+      $cgconfig_require = Package['cgroups']
+      $cgred_require = Package['cgroups']
     }
     'Debian', 'Ubuntu': {
       # common packages
@@ -82,6 +84,14 @@ class jenkins::params {
       $xslt_package = 'xsltproc'
       $xvfb_package = 'xvfb'
       $cgroups_package = 'cgroup-bin'
+      $cgconfig_require = [
+        Package['cgroups'],
+        File['/etc/init/cgconfig.conf'],
+      ]
+      $cgred_require = [
+        Package['cgroups'],
+        File['/etc/init/cgred.conf'],
+      ]
     }
     default: {
       fail("Unsupported osfamily: ${::osfamily} The 'jenkins' module only supports osfamily Ubuntu or Redhat(slaves only).")
diff --git a/modules/jenkins/templates/cgconfig.erb b/modules/jenkins/templates/cgconfig.erb
index 6236ca8fb5..c2639be6e5 100644
--- a/modules/jenkins/templates/cgconfig.erb
+++ b/modules/jenkins/templates/cgconfig.erb
@@ -11,7 +11,7 @@ mount {
         blkio   = /cgroup/blkio;
 }
 
-<% else %>
+<% elsif ( operatingsystemrelease < '12.10' ) or ( operatingsystem != 'Ubuntu' ) then %>
 mount {
         cpu = /sys/fs/cgroup/cpu;
         cpuacct = /sys/fs/cgroup/cpuacct;