|
3 |
@!@ |
3 |
@!@ |
4 |
import sys |
4 |
import sys |
5 |
|
5 |
|
6 |
jobs = [] |
6 |
|
7 |
def setup_cronjob(key): |
7 |
def collect_cronjobs(): |
8 |
global jobs |
8 |
jobs = {} |
9 |
if not key.startswith('cron/') or key == 'cron/autostart' or key == 'cron/path' or key == 'cron/ucrdisabled': |
9 |
for key, value in configRegistry.items(): |
10 |
return |
10 |
try: |
11 |
job = '' |
11 |
prefix, job, setting = key.split('/') |
12 |
try: |
12 |
if prefix == 'cron': |
13 |
tmp = key.split('/') |
13 |
jobs.setdefault(job, {})[setting] = value |
14 |
if len(tmp) != 3: |
14 |
except ValueError: |
15 |
raise IndexError() |
15 |
continue |
16 |
job = tmp[1] |
16 |
return jobs |
17 |
except IndexError: |
17 |
|
18 |
print >> sys.stderr, "E: This cron UCR key is not properly formatted: %s" % key |
18 |
|
19 |
return |
19 |
def process_cronjob(job, settings): |
20 |
if job not in jobs: |
20 |
if configRegistry.is_true(value=settings.get("disabled"), default=False): |
21 |
jobs.append(job) |
|
|
22 |
_tmpkey = 'cron/%s/' % job |
23 |
time = configRegistry.get(_tmpkey + 'time', None) |
24 |
command = configRegistry.get(_tmpkey + 'command', None) |
25 |
description = configRegistry.get(_tmpkey + 'description', None) |
26 |
user = configRegistry.get(_tmpkey + 'user', 'root') |
27 |
mailto = configRegistry.get(_tmpkey + 'mailto', user) |
28 |
disabled = configRegistry.is_true(_tmpkey + 'disabled', False) |
29 |
|
30 |
if disabled: |
31 |
return |
21 |
return |
32 |
|
22 |
|
33 |
if not (time and command): |
23 |
try: |
|
|
24 |
time = settings["time"] |
25 |
command = settings["command"] |
26 |
except KeyError: |
34 |
print >> sys.stderr, "E: Time or command is missing for cron job cron/%s" % job |
27 |
print >> sys.stderr, "E: Time or command is missing for cron job cron/%s" % job |
35 |
return |
28 |
return |
36 |
|
29 |
|
37 |
print '\n' |
30 |
print '\n' |
38 |
if description: |
31 |
try: |
39 |
print "# %s" % description |
32 |
print "# %(description)s" % settings |
|
|
33 |
except KeyError: |
34 |
pass |
35 |
user = settings.get("user", "root") |
36 |
mailto = settings.get("mailto", user) |
40 |
if mailto == "NONE": |
37 |
if mailto == "NONE": |
41 |
mailto = '""' |
38 |
mailto = '""' |
42 |
print "MAILTO=%s" % mailto |
39 |
print "MAILTO=%s" % mailto |
43 |
print "%s %s %s" % (time, user, command) |
40 |
print "%s %s %s" % (time, user, command) |
44 |
|
41 |
|
45 |
path = configRegistry.get('cron/path', '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/opt/scalix/bin') |
|
|
46 |
print 'PATH="%s"' % path |
47 |
|
42 |
|
48 |
disabled_globally = configRegistry.is_true('cron/ucrdisabled', False) |
43 |
print 'PATH="%s"' % configRegistry.get('cron/path', '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') |
49 |
if disabled_globally: |
44 |
|
50 |
print '\n# cron jobs defined by UCR have been disabled by cron/ucr/disabled' |
45 |
if configRegistry.is_true('cron/ucrdisabled', False): |
|
|
46 |
print '\n# cron jobs defined by UCR have been disabled by cron/ucrdisabled' |
51 |
else: |
47 |
else: |
52 |
for key in configRegistry.keys(): |
48 |
jobs = collect_cronjobs() |
53 |
if key.startswith('cron/'): |
49 |
for job, settings in jobs.items(): |
54 |
setup_cronjob(key) |
50 |
process_cronjob(job, settings) |
55 |
@!@ |
51 |
@!@ |