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 os 
23   
24  from twisted.internet import reactor 
25   
26  from flumotion.configure import configure 
27  from flumotion.common import log, keycards, common, errors 
28  from flumotion.job import job 
29  from flumotion.twisted import credentials, fdserver 
30  from flumotion.common.options import OptionParser 
31   
32  __version__ = "$Rev: 6125 $" 
33   
34   
35 -def main(args):
36 parser = OptionParser(domain="flumotion-job") 37 38 log.debug('job', 'Parsing arguments (%r)' % ', '.join(args)) 39 options, args = parser.parse_args(args) 40 41 # check if a config file was specified; if so, parse config and copy over 42 if len(args) != 3: 43 parser.error("must pass an avatarId and a path to the socket: %r" % 44 args) 45 avatarId = args[1] 46 socket = args[2] 47 48 # log our standardized starting marker 49 log.info('job', "Starting job '%s'" % avatarId) 50 51 # register all package paths (FIXME: this should go away when 52 # components and all deps come from manager) 53 # this is still necessary so that code from other projects can be imported 54 from flumotion.common import setup 55 setup.setupPackagePath() 56 57 log.info('job', 'Connecting to worker on socket %s' % (socket)) 58 59 job_factory = job.JobClientFactory(avatarId) 60 reactor.connectWith(fdserver.FDConnector, socket, job_factory, 61 10, checkPID=False) 62 63 # should probably move this to boot 64 if 'FLU_PROFILE' in os.environ: 65 try: 66 import statprof 67 statprof.start() 68 print 'Profiling started.' 69 70 def stop_profiling(): 71 statprof.stop() 72 statprof.display()
73 74 reactor.addSystemEventTrigger('before', 'shutdown', 75 stop_profiling) 76 except ImportError, e: 77 print ('Profiling requested, but statprof is not available (%s)' 78 % e) 79 80 reactor.addSystemEventTrigger('before', 'shutdown', 81 job_factory.medium.shutdownHandler) 82 83 # log our standardized started marker 84 log.info('job', "Started job '%s'" % avatarId) 85 86 reactor.run() 87 88 # log our standardized stopping marker 89 log.info('job', "Stopping job '%s'" % avatarId) 90 # log our standardized stopped marker 91 log.info('job', "Stopped job '%s'" % avatarId) 92 93 return 0 94