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

Source Code for Module flumotion.job.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 file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import optparse 
 23  import os 
 24   
 25  from twisted.internet import reactor 
 26   
 27  from flumotion.configure import configure 
 28  from flumotion.common import log, keycards, common, errors 
 29  from flumotion.job import job 
 30  from flumotion.twisted import credentials, fdserver 
 31   
32 -def main(args):
33 parser = optparse.OptionParser() 34 parser.add_option('', '--version', 35 action="store_true", dest="version", 36 help="show version information") 37 38 log.debug('job', 'Parsing arguments (%r)' % ', '.join(args)) 39 options, args = parser.parse_args(args) 40 41 # handle all options 42 if options.version: 43 print common.version("flumotion-job") 44 return 0 45 46 # check if a config file was specified; if so, parse config and copy over 47 if len(args) != 3: 48 parser.error("must pass an avatarId and a path to the socket: %r" % 49 args) 50 avatarId = args[1] 51 socket = args[2] 52 53 # log our standardized starting marker 54 log.info('job', "Starting job '%s'" % avatarId) 55 56 # register all package paths (FIXME: this should go away when 57 # components and all deps come from manager) 58 # this is still necessary so that code from other projects can be imported 59 from flumotion.common import setup 60 setup.setupPackagePath() 61 62 log.info('job', 'Connecting to worker on socket %s' % (socket)) 63 64 job_factory = job.JobClientFactory(avatarId) 65 reactor.connectWith(fdserver.FDConnector, socket, job_factory, 66 10, checkPID=False) 67 68 # should probably move this to boot 69 if 'FLU_PROFILE' in os.environ: 70 try: 71 import statprof 72 statprof.start() 73 print 'Profiling started.' 74 75 def stop_profiling(): 76 statprof.stop() 77 statprof.display()
78 79 reactor.addSystemEventTrigger('before', 'shutdown', 80 stop_profiling) 81 except ImportError, e: 82 print ('Profiling requested, but statprof is not available (%s)' 83 % e) 84 85 reactor.addSystemEventTrigger('before', 'shutdown', 86 job_factory.medium.shutdownHandler) 87 88 # log our standardized started marker 89 log.info('job', "Started job '%s'" % avatarId) 90 91 reactor.run() 92 93 # log our standardized stopping marker 94 log.info('job', "Stopping job '%s'" % avatarId) 95 # log our standardized stopped marker 96 log.info('job', "Stopped job '%s'" % avatarId) 97 98 return 0 99