diff options
author | Rick Bradshow <bradshaw@mcs.anl.gov> | 2006-08-28 15:47:59 +0000 |
---|---|---|
committer | Rick Bradshow <bradshaw@mcs.anl.gov> | 2006-08-28 15:47:59 +0000 |
commit | 1261ac4e903a78421282ed1118d603188834c1df (patch) | |
tree | ecb85fe2c33721460fd99e963f5b6a38fc2433d4 /src/lib/Server/Plugins/Crontab.py | |
parent | 0d023775f6107b13e727f02dee739764302fee18 (diff) | |
download | bcfg2-1261ac4e903a78421282ed1118d603188834c1df.tar.gz bcfg2-1261ac4e903a78421282ed1118d603188834c1df.tar.bz2 bcfg2-1261ac4e903a78421282ed1118d603188834c1df.zip |
added my hot crontab hacker which randomizes the times at which cron.daily runs.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2126 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/Crontab.py')
-rw-r--r-- | src/lib/Server/Plugins/Crontab.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/Server/Plugins/Crontab.py b/src/lib/Server/Plugins/Crontab.py new file mode 100644 index 000000000..fcdf58f42 --- /dev/null +++ b/src/lib/Server/Plugins/Crontab.py @@ -0,0 +1,39 @@ +'''This module manages the crontab file for bcfg2''' +__revision__ = '$Revision: 1887 $' + +import binascii, os, socket, Bcfg2.Server.Plugin, random + +class Crontab(Bcfg2.Server.Plugin.Plugin): + '''This Generates a random set of times for the cron.daily entries to run. + The goal is to ensure that our Configuration Server/network does get crushed + all in a 5-10 minute period. +''' + __name__ = 'Crontab' + __version__ = '$Id: Crontab 1887 2006-06-18 02:35:54Z desai $' + __author__ = 'bcfg-dev@mcs.anl.gov' + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + try: + self.repository = Bcfg2.Server.Plugin.DirectoryBacked(self.data, self.core.fam) + except OSError, ioerr: + self.logger.error("Failed to load Crontab repository from %s" % (self.data)) + self.logger.error(ioerr) + raise Bcfg2.Server.Plugin.PluginInitError + try: + prefix = open("%s/prefix" % (self.data)).read().strip() + except IOError: + prefix = '' + self.Entries = {'ConfigFile': + {prefix + '/etc/crontab':self.build_crontab}} + + + def build_crontab(self, entry, metadata): + '''This function builds builds a crontab file with a random time for cron.daily''' + random.seed(metadata.hostname) + hour = random.randrange(0,6) + minute = random.randrange(0,59) + entry.text = self.repository.entries['crontab.template'].data% (minute, hour) + permdata = {'owner':'root', 'group':'root', 'perms':'0644'} + [entry.attrib.__setitem__(key, permdata[key]) for key in permdata] + |