]> git.ipfire.org Git - collecty.git/blob - collectyd
Add ability to run as a daemon.
[collecty.git] / collectyd
1 #!/usr/bin/python
2
3 import os
4 import sys
5
6 import daemon
7 import optparse
8
9 import collecty
10
11 c = collecty.Collecty()
12
13 # Parse command line options
14 op = optparse.OptionParser(usage="usage: %prog [options] <configfile1> ... <configfileN>")
15 op.add_option("-d", "--daemon", action="store_true", default=False,
16 help="Run as a daemon in background.")
17 (options, configfiles) = op.parse_args()
18
19 if configfiles:
20 for file in configfiles:
21 c.read_config(file)
22 else:
23 # Load default config file
24 c.read_config("/etc/collecty/collecty.conf")
25
26 if not c.instances:
27 print >>sys.stderr, "Error: No instances were configured."
28 sys.exit(1)
29
30 if options.daemon:
31 with daemon.DaemonContext(stdout=sys.stdout, stderr=sys.stderr):
32 c.run()
33 else:
34 c.run()
35