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  import optparse 
 20   
 21  from flumotion.common import common, log 
 22  from flumotion.configure import configure 
 23  from flumotion.service import service 
 24   
25 -def main(args):
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 # Force options down configure's throat 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 # if log file is specified, redirect stdout and stderr 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