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,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  from twisted.internet import reactor 
19   
20  from flumotion.twisted import credentials, fdserver 
21  from flumotion.common import log, common, options 
22  from flumotion.job import job 
23   
24  # register serializables 
25  from flumotion.common import keycards 
26   
27  __version__ = "$Rev$" 
28   
29   
30 -def main(args):
31 parser = options.OptionParser(domain="flumotion-job") 32 33 log.debug('job', 'Parsing arguments (%r)' % ', '.join(args)) 34 opts, args = parser.parse_args(args) 35 36 # check if a config file was specified; if so, parse config and copy over 37 if len(args) != 3: 38 parser.error("must pass an avatarId and a path to the socket: %r" % 39 args) 40 avatarId = args[1] 41 socket = args[2] 42 43 # log our standardized starting marker 44 log.info('job', "Starting job '%s'" % avatarId) 45 46 # register all package paths (FIXME: this should go away when 47 # components and all deps come from manager) 48 # this is still necessary so that code from other projects can be imported 49 from flumotion.common import setup 50 setup.setupPackagePath() 51 52 log.info('job', 'Connecting to worker on socket %s' % (socket)) 53 54 job_factory = job.JobClientFactory(avatarId) 55 reactor.connectWith(fdserver.FDConnector, socket, job_factory, 56 10, checkPID=False) 57 58 reactor.addSystemEventTrigger('before', 'shutdown', 59 job_factory.medium.shutdownHandler) 60 61 # log our standardized started marker 62 log.info('job', "Started job '%s'" % avatarId) 63 64 reactor.run() 65 66 # log our standardized stopping marker 67 log.info('job', "Stopping job '%s'" % avatarId) 68 # log our standardized stopped marker 69 log.info('job', "Stopped job '%s'" % avatarId) 70 71 return 0
72