1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import os
23 import sys
24
25 from twisted.internet import reactor
26
27 from flumotion.configure import configure
28 from flumotion.common import log, keycards, common, errors
29 from flumotion.common import connection
30 from flumotion.admin.rrdmon import rrdmon, config
31 from flumotion.twisted import pb
32 from flumotion.common.options import OptionGroup, OptionParser
33
34
36 parser = OptionParser(domain="flumotion-rrdmon")
37
38 group = OptionGroup(parser, "rrdmon")
39 group.add_option('-s', '--service-name',
40 action="store", type="string", dest="serviceName",
41 help="name to use for log and pid files "
42 "when run as a daemon")
43 group.add_option('-D', '--daemonize',
44 action="store_true", dest="daemonize",
45 help="run in background as a daemon")
46 group.add_option('', '--daemonize-to',
47 action="store", dest="daemonizeTo",
48 help="what directory to run from when daemonizing")
49
50 parser.add_option('-L', '--logdir',
51 action="store", dest="logdir",
52 help="flumotion log directory (default: %s)" %
53 configure.logdir)
54 parser.add_option('-R', '--rundir',
55 action="store", dest="rundir",
56 help="flumotion run directory (default: %s)" %
57 configure.rundir)
58 parser.add_option_group(group)
59
60 return parser
61
71
73 parser = _createParser()
74 log.debug('rrdmon', 'Parsing arguments (%r)' % ', '.join(args))
75 options, args = parser.parse_args(args)
76
77
78 for d in ['logdir', 'rundir']:
79 o = getattr(options, d, None)
80 if o:
81 log.debug('rrdmon', 'Setting configure.%s to %s' % (d, o))
82 setattr(configure, d, o)
83
84
85 if len(args) != 2:
86 raise SystemExit('usage: flumotion-rrdtool [OPTIONS] CONFIG-FILE')
87
88 confXml = args[1]
89 cfg = _readConfig(confXml, options)
90
91
92 if options.debug:
93 log.setFluDebug(options.debug)
94
95 if options.daemonizeTo and not options.daemonize:
96 sys.stderr.write(
97 'ERROR: --daemonize-to can only be used with -D/--daemonize.\n')
98 return 1
99
100 if options.serviceName and not options.daemonize:
101 sys.stderr.write(
102 'ERROR: --service-name can only be used with -D/--daemonize.\n')
103 return 1
104
105 monitor = rrdmon.RRDMonitor(cfg['sources'])
106
107 name = 'rrdmon'
108 if options.daemonize:
109 if options.serviceName:
110 name = options.serviceName
111 if not options.daemonizeTo:
112 options.daemonizeTo = "/"
113
114 common.startup("rrdmon", name, options.daemonize, options.daemonizeTo)
115
116 log.debug('rrdmon', 'Running Flumotion version %s' %
117 configure.version)
118 import twisted.copyright
119 log.debug('rrdmon', 'Running against Twisted version %s' %
120 twisted.copyright.version)
121
122
123 reactor.run()
124
125 return 0
126