diff --git a/deployment/puppet/cgroups/files/cgconfig.init b/deployment/puppet/cgroups/files/cgconfig.init new file mode 100644 index 0000000000..cc84fdd207 --- /dev/null +++ b/deployment/puppet/cgroups/files/cgconfig.init @@ -0,0 +1,66 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: cgconfig +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Configures CGroups +### END INIT INFO + +start_service() { + if is_running; then + echo "cgrulesengd is running already!" + return 1 + else + echo "Processing /etc/cgconfig.conf ..." + cgconfigparser -l /etc/cgconfig.conf + echo "Processing /etc/cgrules.conf ..." + cgrulesengd -vvv --logfile=/var/log/cgrulesengd.log + return 0 + fi +} + +stop_service() { + if is_running; then + echo "Stopping cgrulesengd ..." + pkill cgrulesengd + else + echo "cgrulesengd is not running!" + return 1 + fi +} + +status() { + if pgrep cgrulesengd > /dev/null; then + echo "cgrulesengd is running" + return 0 + else + echo "cgrulesengd is not running!" + return 3 + fi +} + +is_running() { + status >/dev/null 2>&1 +} + +case "${1:-}" in + start) + start_service + ;; + stop) + stop_service + ;; + status) + status + ;; + *) + echo "Usage: /etc/init.d/cgconfig {start|stop|restart|status}" + exit 2 + ;; +esac + +exit $? diff --git a/deployment/puppet/cgroups/manifests/init.pp b/deployment/puppet/cgroups/manifests/init.pp index ba31ec787d..52a1f9073b 100644 --- a/deployment/puppet/cgroups/manifests/init.pp +++ b/deployment/puppet/cgroups/manifests/init.pp @@ -13,51 +13,40 @@ class cgroups( $cgroups_set = {}, $packages = $cgroups::params::packages, -) - inherits cgroups::params -{ +) inherits cgroups::params { + validate_hash($cgroups_set) ensure_packages($packages, { tag => 'cgroups' }) - File { ensure => file, owner => 'root', group => 'root', mode => '0644', + notify => Service['cgconfig'], } file { '/etc/cgconfig.conf': content => template('cgroups/cgconfig.conf.erb'), - notify => Service['cgconfigparser'], tag => 'cgroups', } file { '/etc/cgrules.conf': content => template('cgroups/cgrules.conf.erb'), - notify => Service['cgrulesengd'], tag => 'cgroups', } + file { '/etc/init.d/cgconfig': + mode => '0755', + source => "puppet:///modules/${module_name}/cgconfig.init", + tag => 'cgroups', + } + class { '::cgroups::service': cgroups_settings => $cgroups_set, } - Package <| tag == 'cgroups' |> ~> - Service['cgrulesengd'] + Package <| tag == 'cgroups' |> -> File <| tag == 'cgroups' |> + Service['cgconfig'] -> Cgclassify <||> - Package <| tag == 'cgroups' |> -> - File <| tag == 'cgroups' |> - - File <| tag == 'cgroups' |> -> - Service['cgroup-lite'] - - Service['cgroup-lite'] -> - Service['cgconfigparser'] - - Service['cgconfigparser'] -> - Cgclassify <||> - - Cgclassify <||> -> - Service['cgrulesengd'] } diff --git a/deployment/puppet/cgroups/manifests/params.pp b/deployment/puppet/cgroups/manifests/params.pp index 1e3d9c928d..db76f5d103 100644 --- a/deployment/puppet/cgroups/manifests/params.pp +++ b/deployment/puppet/cgroups/manifests/params.pp @@ -2,10 +2,11 @@ class cgroups::params { case $::osfamily { 'Debian': { - $packages = ['cgroup-bin', 'libcgroup1', 'cgroup-upstart'] + $packages = ['cgroup-bin', 'libcgroup1'] } default: { fail("Unsupported platform") } } + } diff --git a/deployment/puppet/cgroups/manifests/service.pp b/deployment/puppet/cgroups/manifests/service.pp index 51506dfd6b..44d691e4a4 100644 --- a/deployment/puppet/cgroups/manifests/service.pp +++ b/deployment/puppet/cgroups/manifests/service.pp @@ -1,26 +1,16 @@ class cgroups::service ( $cgroups_settings = {}, -) -{ - service { 'cgroup-lite': - ensure => running, - enable => true, - } +) { - service { 'cgconfigparser': - ensure => running, - hasstatus => false, - status => '/bin/true', - restart => 'service cgconfigparser restart', - require => Service['cgroup-lite'], - } - - service { 'cgrulesengd': - ensure => running, + service { 'cgconfig': + ensure => running, + enable => true, + provider => 'init', } $cgclass_res = map_cgclassify_opts($cgroups_settings) unless empty($cgclass_res) { create_resources('cgclassify', $cgclass_res, { 'ensure' => present }) } + } diff --git a/deployment/puppet/cgroups/spec/classes/cgroups_init_spec.rb b/deployment/puppet/cgroups/spec/classes/cgroups_init_spec.rb index eb0a945af7..61a04b3266 100644 --- a/deployment/puppet/cgroups/spec/classes/cgroups_init_spec.rb +++ b/deployment/puppet/cgroups/spec/classes/cgroups_init_spec.rb @@ -15,6 +15,7 @@ describe 'cgroups', :type => :class do :owner => 'root', :group => 'root', :mode => '0644', + :notify => 'Service[cgconfig]', :tag => 'cgroups', } end @@ -27,7 +28,7 @@ describe 'cgroups', :type => :class do :cgroups_settings => params[:cgroups_set]) } - %w(libcgroup1 cgroup-bin cgroup-upstart).each do |cg_pkg| + %w(libcgroup1 cgroup-bin).each do |cg_pkg| it { is_expected.to contain_package(cg_pkg) } end @@ -36,7 +37,6 @@ describe 'cgroups', :type => :class do it { p catalogue.resource 'file', cg_file } end - it { is_expected.to contain_file('/etc/cgrules.conf').that_notifies('Service[cgrulesengd]') } - it { is_expected.to contain_file('/etc/cgconfig.conf').that_notifies('Service[cgconfigparser]') } + it { is_expected.to contain_file('/etc/init.d/cgconfig').with(file_defaults.merge({:mode => '0755'})) } end end diff --git a/deployment/puppet/cgroups/spec/classes/cgroups_service_spec.rb b/deployment/puppet/cgroups/spec/classes/cgroups_service_spec.rb index ea39a3ae71..2519815a41 100644 --- a/deployment/puppet/cgroups/spec/classes/cgroups_service_spec.rb +++ b/deployment/puppet/cgroups/spec/classes/cgroups_service_spec.rb @@ -9,8 +9,6 @@ describe 'cgroups::service', :type => :class do } end - %w(cgroup-lite cgconfigparser cgrulesengd).each do |cg_service| - it { is_expected.to contain_service(cg_service) } - end + it { is_expected.to contain_service('cgconfig') } end end