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