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,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import os 
 19  import sys 
 20   
 21  from flumotion.common import common, log 
 22  from flumotion.configure import configure 
 23  from flumotion.service import service 
 24  from flumotion.common.options import OptionParser 
 25   
 26   
27 -def main(args):
28 parser = OptionParser(domain=configure.PACKAGE) 29 30 parser.add_option('-l', '--logfile', 31 action="store", dest="logfile", 32 help="flumotion service log file") 33 parser.add_option('-C', '--configdir', 34 action="store", dest="configdir", 35 help="flumotion configuration directory (default: %s)" % 36 configure.configdir) 37 parser.add_option('-L', '--logdir', 38 action="store", dest="logdir", 39 help="flumotion log directory (default: %s)" % 40 configure.logdir) 41 parser.add_option('-R', '--rundir', 42 action="store", dest="rundir", 43 help="flumotion run directory (default: %s)" % 44 configure.rundir) 45 46 options, args = parser.parse_args(args) 47 48 # Force options down configure's throat 49 for d in ['configdir', 'logdir', 'rundir']: 50 o = getattr(options, d, None) 51 if o: 52 log.debug('service', 'Setting configure.%s to %s' % (d, o)) 53 setattr(configure, d, o) 54 55 # if log file is specified, redirect stdout and stderr 56 if options.logfile: 57 try: 58 out = open(options.logfile, 'a+') 59 err = open(options.logfile, 'a+', 0) 60 except IOError, e: 61 sys.stderr.write("Could not open file '%s' for writing:\n%s\n" % ( 62 options.logfile, e.strerror)) 63 sys.exit(1) 64 65 os.dup2(out.fileno(), sys.stdout.fileno()) 66 os.dup2(err.fileno(), sys.stderr.fileno()) 67 68 servicer = service.Servicer(options.configdir, options.logdir, 69 options.rundir) 70 try: 71 command = args[1] 72 except IndexError: 73 print "Usage: flumotion " \ 74 "{list|start|stop|restart|condrestart|status|clean|" \ 75 "enable|disable} [which]" 76 sys.exit(0) 77 78 if command == "list": 79 return servicer.list() 80 elif command == "start": 81 return servicer.start(args[2:]) 82 elif command == "stop": 83 return servicer.stop(args[2:]) 84 elif command == "restart": 85 return servicer.stop(args[2:]) + servicer.start(args[2:]) 86 elif command == "condrestart": 87 return servicer.condrestart(args[2:]) 88 elif command == "status": 89 return servicer.status(args[2:]) 90 elif command == "create": 91 return servicer.create(args[2:]) 92 elif command == "clean": 93 return servicer.clean(args[2:]) 94 elif command == "enable": 95 return servicer.enable(args[2:]) 96 elif command == "disable": 97 return servicer.disable(args[2:]) 98 99 sys.stderr.write("No such command '%s'\n" % command) 100 return 1
101