Package flumotion :: Package service :: Module main
[hide private]

Source Code for Module flumotion.service.main

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3  # 
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
 6  # All rights reserved. 
 7   
 8  # This program is free software; you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation; either version 2 of the License, or 
11  # (at your option) any later version. 
12  # See "LICENSE.GPL" in the source distribution for more information. 
13   
14  # This program is also licensed under the Flumotion license. 
15  # See "LICENSE.Flumotion" in the source distribution for more information. 
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 -def main(args):
26 parser = OptionParser(domain=configure.PACKAGE) 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 # Force options down configure's throat 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 # if log file is specified, redirect stdout and stderr 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