Esempio n. 1
0
def possess(daemonizeTo=None):
    fileutils.ensureDirExists(configure.logdir, "log file")
    fileutils.ensureDirExists(configure.rundir, "run file")
    if not daemonizeTo:
        daemonizeTo = '/'

    pid = process.getPid('transcoder-admin')
    if pid:
        if process.checkPidRunning(pid):
            raise iherrors.SystemError(
                'A flumotion-transcoder-admin is already running '
                + 'as pid %d' % pid)
        else:
            log.warning("flumotion-transcoder-admin should have been "
                        "running with pid %s.  Restarting", str(pid))
            process.deletePidFile('transcoder-admin')

    logPath = os.path.join(configure.logdir, 'transcoder-admin.log')

    # here we daemonize; so we also change our pid
    if not daemonizeTo:
        daemonizeTo = '/'
    process.daemonize(stdout=logPath, stderr=logPath,
                      directory=daemonizeTo)

    log.info('Started daemon')

    # from now on I should keep running, whatever happens
    log.debug('writing pid file')
    process.writePidFile('transcoder-admin')
Esempio n. 2
0
def parse_options(args):
    usage = 'usage: flumotion-transcoder-admin [options] CONFIG-FILE'
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('', '--version',
                      action="store_true", dest="version",
                      default=False,
                      help="show version information")
    parser.add_option('-D', '--daemonize',
                     action="store_true", dest="daemonize",
                     default=False,
                     help="run in background as a daemon")
    parser.add_option('', '--daemonize-to',
                     action="store", dest="daemonizeTo",
                     help="what directory to run from when daemonizing; "
                          "default: '/'")
    parser.add_option('-d', '--debug',
                     action="store", dest="debug",
                     help="override the configuration debug level")

    parser.add_option('-L', '--logdir',
                      action="store", dest="logdir",
                      help="flumotion log directory (default: %s)" %
                        configure.logdir)
    parser.add_option('-R', '--rundir',
                      action="store", dest="rundir",
                      help="flumotion run directory (default: %s)" %
                        configure.rundir)

    options, args = parser.parse_args(args)

    # Force options down configure's throat
    for d in ['logdir', 'rundir']:
        o = getattr(options, d, None)
        if o:
            log.debug('Setting configure.%s to %s' % (d, o))
            setattr(configure, d, o)

    if options.version:
        print common.version("flumotion-transcoder-admin")
        sys.exit(0)

    if options.daemonizeTo and not options.daemonize:
        raise iherrors.SystemError(
            '--daemonize-to can only be used with -D/--daemonize.')

    if len(args) != 2:
        sys.exit(usage)

    configPath = args[1]
    if not os.path.exists(configPath):
        raise iherrors.SystemError("Configuration file '%s' not found"
                                 % configPath)

    return options, configPath
Esempio n. 3
0
 def createFromContext(cls, profCtx, params=None):
     custCtx = profCtx.getCustomerContext()
     name = "%s/%s" % (custCtx.name, profCtx.name)
     configPath = profCtx.configPath
     pathAttr = custCtx.pathAttributes
     config = createTranscodingConfigFromContext(profCtx)
     log.debug("PARAMS %r", params)
     if params:
         update_config(config, params)
     priority = profCtx.processPriority
     # for priority in [0,100] the nice level will be in  [19,0]
     # and for priority in [100-200] the nice level will be in [0,-15]
     niceLevel = (19 - (19 * min(100, max(0, priority)) / 100)
                  - (15 * (min(200, max(100, priority)) - 100) / 100))
     return cls(name, configPath, config, niceLevel, pathAttr)
Esempio n. 4
0
def exorcize():
    log.debug('deleting pid file')
    process.deletePidFile('transcoder-admin')