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