1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import os
18 import sys
19 import optparse
20
21 from flumotion.common import common, log
22 from flumotion.configure import configure
23 from flumotion.service import service
24
26 parser = optparse.OptionParser()
27 parser.add_option('-d', '--debug',
28 action="store", type="string", dest="debug",
29 help="set debug levels")
30 parser.add_option('', '--version',
31 action="store_true", dest="version",
32 default=False,
33 help="show version information")
34
35 parser.add_option('-l', '--logfile',
36 action="store", dest="logfile",
37 help="flumotion service log file")
38 parser.add_option('-C', '--configdir',
39 action="store", dest="configdir",
40 help="flumotion configuration directory (default: %s)" %
41 configure.configdir)
42 parser.add_option('-L', '--logdir',
43 action="store", dest="logdir",
44 help="flumotion log directory (default: %s)" %
45 configure.logdir)
46 parser.add_option('-R', '--rundir',
47 action="store", dest="rundir",
48 help="flumotion run directory (default: %s)" %
49 configure.rundir)
50
51 options, args = parser.parse_args(args)
52
53
54 for d in ['configdir', 'logdir', 'rundir']:
55 o = getattr(options, d, None)
56 if o:
57 log.debug('service', 'Setting configure.%s to %s' % (d, o))
58 setattr(configure, d, o)
59
60 if options.version:
61 print common.version("flumotion")
62 return 0
63
64 if options.debug:
65 log.setFluDebug(options.debug)
66
67
68 if options.logfile:
69 try:
70 out = open(options.logfile, 'a+')
71 err = open(options.logfile, 'a+', 0)
72 except IOError, e:
73 sys.stderr.write("Could not open file '%s' for writing:\n%s\n" % (
74 options.logfile, e.strerror))
75 sys.exit(1)
76
77 os.dup2(out.fileno(), sys.stdout.fileno())
78 os.dup2(err.fileno(), sys.stderr.fileno())
79
80 servicer = service.Servicer(options.configdir, options.logdir,
81 options.rundir)
82 try:
83 command = args[1]
84 except IndexError:
85 print "Usage: flumotion {list|start|stop|restart|status|clean} [which]"
86 sys.exit(0)
87
88 if command == "list":
89 return servicer.list()
90 elif command == "start":
91 return servicer.start(args[2:])
92 elif command == "stop":
93 return servicer.stop(args[2:])
94 elif command == "restart":
95 return servicer.stop(args[2:]) + servicer.start(args[2:])
96 elif command == "status":
97 return servicer.status(args[2:])
98 elif command == "create":
99 return servicer.create(args[2:])
100 elif command == "clean":
101 return servicer.clean(args[2:])
102
103 sys.stderr.write("No such command '%s'\n" % command)
104 return 1
105