From 31652d945b348175b6fe3a43880a2448a324787b Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Tue, 15 Mar 2011 20:04:18 -0400 Subject: instead of using $RANDOM, which isn't POSIX, we get even more esoteric by pulling 2 bytes from /dev/urandom, giving them to od which turns them into unsigned decimals, and then we bitshift the output, either by 5 or 6 depending on if we are replacing $RANDOM/1000*60 (right sift by 5 is the same as dividing by 2^N, or /32) or $RANDOM/2000*60 (range of [0,983]) Thanks to dkg for working through this with me, not only did he come up with it faster than a human brain should be able to function, he had the patience to explain all the individual pieces that I did not understand to me. --- files/cron.d/puppetd | 4 ++-- files/cron.d/puppetd.CentOS | 4 ++-- files/cron.d/puppetd.Gentoo | 4 ++-- manifests/openbsd.pp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/files/cron.d/puppetd b/files/cron.d/puppetd index 8b2c289..0a68f4d 100644 --- a/files/cron.d/puppetd +++ b/files/cron.d/puppetd @@ -1,5 +1,5 @@ # check if puppet is running -0 * * * * root /bin/ps ax | /bin/grep -v grep | /bin/grep -q puppetd || (sleep $(($RANDOM/2000*60)) && /etc/init.d/puppet restart) +0 * * * * root /bin/ps ax | /bin/grep -v grep | /bin/grep -q puppetd || (sleep $(( $(> 6 )) && /etc/init.d/puppet restart) # restart puppet once in a while and randomly delay the restart between 0 and 32 minutes -> splay puppetmaster hammering -0 22 * * */2 root sleep $(($RANDOM/1000*60)) && /etc/init.d/puppet restart > /dev/null +0 22 * * */2 root sleep $(( $( > 5 )) && /etc/init.d/puppet restart > /dev/null diff --git a/files/cron.d/puppetd.CentOS b/files/cron.d/puppetd.CentOS index 65239ce..a4f84e9 100644 --- a/files/cron.d/puppetd.CentOS +++ b/files/cron.d/puppetd.CentOS @@ -1,5 +1,5 @@ # check if puppet is running -0 * * * * root /etc/init.d/puppet status > /dev/null || (sleep $(($RANDOM/2000*60)) && /etc/init.d/puppet restart) +0 * * * * root /etc/init.d/puppet status > /dev/null || (sleep $(( $(> 6 )) && /etc/init.d/puppet restart) # restart puppet once in a while and randomly delay the restart between 0 and 32 minutes -> splay puppetmaster hammering -0 22 * * */2 root sleep $(($RANDOM/1000*60)) && /etc/init.d/puppet restart > /dev/null +0 22 * * */2 root sleep $(( $(> 5 )) && /etc/init.d/puppet restart > /dev/null diff --git a/files/cron.d/puppetd.Gentoo b/files/cron.d/puppetd.Gentoo index c9811c2..00c5ac0 100644 --- a/files/cron.d/puppetd.Gentoo +++ b/files/cron.d/puppetd.Gentoo @@ -1,5 +1,5 @@ # check if puppet is running -# 0 * * * * root /bin/ps ax | /bin/grep -v grep | /bin/grep -q puppetd || ( sleep $(($RANDOM/2000*60)) && /etc/init.d/puppet restart ) +# 0 * * * * root /bin/ps ax | /bin/grep -v grep | /bin/grep -q puppetd || ( sleep $(( $(> 6 )) && /etc/init.d/puppet restart ) # restart puppet once in a while and randomly delay the restart between 0 and 32 minutes -> splay puppetmaster hammering -# 0 22 * * */2 root sleep $(($RANDOM/1000*60)) && /etc/init.d/puppet restart > /dev/null +# 0 22 * * */2 root sleep $(( $(> 5 )) && /etc/init.d/puppet restart > /dev/null diff --git a/manifests/openbsd.pp b/manifests/openbsd.pp index 2e3c493..1df5a9e 100644 --- a/manifests/openbsd.pp +++ b/manifests/openbsd.pp @@ -19,12 +19,12 @@ class puppet::openbsd inherits puppet::base { cron { 'puppetd_check': - command => '/bin/ps ax | /usr/bin/grep -v grep | /usr/bin/grep -q "puppet agent" || (sleep $(($RANDOM/2000*60)) && /usr/local/bin/puppet agent)', + command => '/bin/ps ax | /usr/bin/grep -v grep | /usr/bin/grep -q "puppet agent" || (sleep $(( $(> 6 )) && /usr/local/bin/puppet agent)', user => root, minute => 0; 'puppetd_restart': - command => 'sleep $((echo $RANDOM/2000*60)) && /bin/kill `/bin/cat /var/run/puppet/agent.pid`; /usr/local/bin/puppet agent', + command => 'sleep $(( $(> 6 )) && /bin/kill `/bin/cat /var/run/puppet/agent.pid`; /usr/local/bin/puppet agent', minute => 0, hour => 22, monthday => '*/2', -- cgit v1.2.3