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