[MediaWiki-commits] [Gerrit] Labs: clean exec resources in gridengine class - change (operations/puppet)
coren has submitted this change and it was merged. Change subject: Labs: clean exec resources in gridengine class .. Labs: clean exec resources in gridengine class Rather than attempt overcomplicated command => invocations, move them to cleaner script files and invoke those instead. Change-Id: Ibc76809bc84879938593ce79f7fa12842ca5d6d9 --- A modules/gridengine/files/mergeconf A modules/gridengine/files/runpurge A modules/gridengine/files/trackpurge M modules/gridengine/manifests/master.pp M modules/gridengine/manifests/resource.pp M modules/gridengine/manifests/resourcedir.pp 6 files changed, 99 insertions(+), 25 deletions(-) Approvals: coren: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/gridengine/files/mergeconf b/modules/gridengine/files/mergeconf new file mode 100755 index 000..3824d22 --- /dev/null +++ b/modules/gridengine/files/mergeconf @@ -0,0 +1,32 @@ +#! /bin/bash +# +# mergconf outfile [infile...] +# +# This does a line-by-line merge of the configuration files +# specified by infile into outfile, keeping only the first +# of each line that start with the same whitespace-separated +# keyword, into the outfile iff it differs from any existing +# outfile. +# +# It will try to glob the infile arguments as guard against +# puppet overquoting globs if they are not readable files. +# +# returns true if there is a new outfile in place + +conf="$1" && shift + +shopt -s nullglob + +if [ $# -gt 0 ]; then + (for f in "$@"; do + if [ -r "$f" ]; then /bin/cat "$f"; else /bin/cat $f 2>/dev/null; fi + done) | /usr/bin/sort -ufst ' ' -k 1,1 >"$conf~" + if [ -r "$conf~" ]; then +if ! diff -qbBZN "$conf~" "$conf" >/dev/null; then + mv "$conf~" "$conf" && exit 0 +fi +rm -f "$conf~" + fi +fi +exit 1 + diff --git a/modules/gridengine/files/runpurge b/modules/gridengine/files/runpurge new file mode 100755 index 000..4f375c7 --- /dev/null +++ b/modules/gridengine/files/runpurge @@ -0,0 +1,20 @@ +#! /bin/bash +# +# runpurge tracker dir +# +# For every file in tracker that does not have a corresponding +# file (of the same name) in dir, run the content of the file +# then remove it if succesful. +# +# This allows running a command when a configured resource no +# longer exists, something that puppet does not otherwise allow. + +test $# -eq 2 || exit 1 +cd "$1" || exit 1 + +for f in *; do + if [ ! -f "$2/$f" ]; then +/bin/bash "$f" && /bin/rm "$f" + fi +done + diff --git a/modules/gridengine/files/trackpurge b/modules/gridengine/files/trackpurge new file mode 100755 index 000..fc6a14e --- /dev/null +++ b/modules/gridengine/files/trackpurge @@ -0,0 +1,14 @@ +#! /bin/bash +# +# trackpurge tracker delcmd addcmd [args...] +# + +test $# -gt 2 || exit 1 +tracker="$1" +delcmd="$2" +addcmd="$3" +shift 3 + +if "$addcmd" "$@"; then + echo "$delcmd" >"$tracker" +fi diff --git a/modules/gridengine/manifests/master.pp b/modules/gridengine/manifests/master.pp index 0088874..101bc5e 100644 --- a/modules/gridengine/manifests/master.pp +++ b/modules/gridengine/manifests/master.pp @@ -26,13 +26,26 @@ file { "$etcdir/.tracker": ensure => directory, -require => Package['gridengine-master'], force => true, owner => 'sgeadmin', group => 'sgeadmin', mode=> '0775', recurse => false, purge => true, +} + +file { "$etcdir/bin": +ensure => directory, +force=> true, +owner=> 'root', +group=> 'root', +mode => '0755', +recurse => true, +purge=> true, +sourceselect => all, +source => [ 'puppet:///modules/gridengine/mergeconf', + 'puppet:///modules/gridengine/trackpurge', + 'puppet:///modules/gridengine/runpurge' ], } gridengine::resourcedir { 'queues': } @@ -57,14 +70,13 @@ owner => 'sgeadmin', group => 'sgeadmin', mode=> '0664', -source => 'puppet:///modules/gridengine/99-default'; +source => 'puppet:///modules/gridengine/99-default', } -exec { "create-complex-conf": -cwd => $etcdir, -path=> '/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin', -command => "bash -c '/usr/bin/sort -ufst \" \" -k 1,1 complex/* >complex.conf && echo /usr/bin/qconf -Mc complex.conf'", -require => File["$etcdir/complex/99-default"], +exec { "update-complex-conf": +onlyif => "$etcdir/bin/mergeconf $etcdir/complex.conf $etcdir/complex/*", +command => "/bin/echo /usr/bin/qconf -Mc $etcdir/complex.conf'", +require => File[ "$etcdir/bin", "$etcdir/complex/99-default" ], } file { "$etcdir/config": @@ -82,14 +94,13 @@ owner => 'sgeadmin', group => 'sgeadmin', m
[MediaWiki-commits] [Gerrit] Labs: clean exec resources in gridengine class - change (operations/puppet)
coren has uploaded a new change for review. https://gerrit.wikimedia.org/r/167200 Change subject: Labs: clean exec resources in gridengine class .. Labs: clean exec resources in gridengine class Rather than attempt overcomplicated command => invocations, move them to cleaner script files and invoke those instead. Change-Id: Ibc76809bc84879938593ce79f7fa12842ca5d6d9 --- A modules/gridengine/files/mergeconf A modules/gridengine/files/runpurge A modules/gridengine/files/trackpurge M modules/gridengine/manifests/master.pp M modules/gridengine/manifests/resource.pp M modules/gridengine/manifests/resourcedir.pp 6 files changed, 99 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/00/167200/1 diff --git a/modules/gridengine/files/mergeconf b/modules/gridengine/files/mergeconf new file mode 100755 index 000..3824d22 --- /dev/null +++ b/modules/gridengine/files/mergeconf @@ -0,0 +1,32 @@ +#! /bin/bash +# +# mergconf outfile [infile...] +# +# This does a line-by-line merge of the configuration files +# specified by infile into outfile, keeping only the first +# of each line that start with the same whitespace-separated +# keyword, into the outfile iff it differs from any existing +# outfile. +# +# It will try to glob the infile arguments as guard against +# puppet overquoting globs if they are not readable files. +# +# returns true if there is a new outfile in place + +conf="$1" && shift + +shopt -s nullglob + +if [ $# -gt 0 ]; then + (for f in "$@"; do + if [ -r "$f" ]; then /bin/cat "$f"; else /bin/cat $f 2>/dev/null; fi + done) | /usr/bin/sort -ufst ' ' -k 1,1 >"$conf~" + if [ -r "$conf~" ]; then +if ! diff -qbBZN "$conf~" "$conf" >/dev/null; then + mv "$conf~" "$conf" && exit 0 +fi +rm -f "$conf~" + fi +fi +exit 1 + diff --git a/modules/gridengine/files/runpurge b/modules/gridengine/files/runpurge new file mode 100755 index 000..4f375c7 --- /dev/null +++ b/modules/gridengine/files/runpurge @@ -0,0 +1,20 @@ +#! /bin/bash +# +# runpurge tracker dir +# +# For every file in tracker that does not have a corresponding +# file (of the same name) in dir, run the content of the file +# then remove it if succesful. +# +# This allows running a command when a configured resource no +# longer exists, something that puppet does not otherwise allow. + +test $# -eq 2 || exit 1 +cd "$1" || exit 1 + +for f in *; do + if [ ! -f "$2/$f" ]; then +/bin/bash "$f" && /bin/rm "$f" + fi +done + diff --git a/modules/gridengine/files/trackpurge b/modules/gridengine/files/trackpurge new file mode 100755 index 000..fc6a14e --- /dev/null +++ b/modules/gridengine/files/trackpurge @@ -0,0 +1,14 @@ +#! /bin/bash +# +# trackpurge tracker delcmd addcmd [args...] +# + +test $# -gt 2 || exit 1 +tracker="$1" +delcmd="$2" +addcmd="$3" +shift 3 + +if "$addcmd" "$@"; then + echo "$delcmd" >"$tracker" +fi diff --git a/modules/gridengine/manifests/master.pp b/modules/gridengine/manifests/master.pp index 0088874..47d7818 100644 --- a/modules/gridengine/manifests/master.pp +++ b/modules/gridengine/manifests/master.pp @@ -26,13 +26,26 @@ file { "$etcdir/.tracker": ensure => directory, -require => Package['gridengine-master'], force => true, owner => 'sgeadmin', group => 'sgeadmin', mode=> '0775', recurse => false, purge => true, +} + +file { "$etcdir/bin": +ensure => directory, +force=> true, +owner=> 'root', +group=> 'root', +mode => '0755', +recurse => true, +purge=> true, +sourceselect => all, +source => [ 'puppet:///modules/gridengine/mergeconf', + 'puppet:///modules/gridengine/trackpurge', + 'puppet:///modules/gridengine/runpurge' ], } gridengine::resourcedir { 'queues': } @@ -57,14 +70,13 @@ owner => 'sgeadmin', group => 'sgeadmin', mode=> '0664', -source => 'puppet:///modules/gridengine/99-default'; +source => 'puppet:///modules/gridengine/99-default', } -exec { "create-complex-conf": -cwd => $etcdir, -path=> '/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin', -command => "bash -c '/usr/bin/sort -ufst \" \" -k 1,1 complex/* >complex.conf && echo /usr/bin/qconf -Mc complex.conf'", -require => File["$etcdir/complex/99-default"], +exec { "update-complex-conf": +onlyif => "$etcdir/bin/mergeconf $etcdir/complex.conf $etcdir/complex/*", +command => "/bin/echo /usr/bin/qconf -Mc $etcdir/complex.conf'", +require => File["$etcdir/bin", "$etcdir/complex/99-default"], } file { "$etcdir/config": @@ -82,14 +94,13 @@ owner => 'sgeadm