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