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')
def notifyDebug(msg, info=None, debug=None, failure=None, exception=None, documents=None): """ This function can be used from anywere to notify debug information (like traceback) when no Notifier reference is available. Do not raise any exception. """ global _shutingDown if _shutingDown: return try: sender = _debugSender recipients = _debugRecipients log.info("Try sending a debug notification to %s from %s", recipients, sender, category=adminconsts.NOTIFIER_LOG_CATEGORY) body = _buildBody(sender, recipients, msg, msg, info, debug, failure, exception, documents) d = _postNotification(_smtpServer, _smtpPort, _smtpRequireTLS, sender, recipients, body) args = ("Debug",) d.addCallbacks(_cbNotificationDone, _ebNotificationFailed, callbackArgs=args, errbackArgs=args) except Exception, e: log.warning("Debug Notification Failed: %s", log.getExceptionMessage(e), category=adminconsts.NOTIFIER_LOG_CATEGORY)
def prepare(self, workerCtx): adminCtx = workerCtx.getAdminContext() adminLocal = adminCtx.getLocal() localPath = self._configPath.localize(adminLocal) # The .ini file is created here... saver = inifile.IniFile() # Set the datetime of file creation self._config.touch() try: fileutils.ensureDirExists(os.path.dirname(localPath), "transcoding config", self._pathAttr) saver.saveToFile(self._config, localPath) except Exception, e: message = ("Failed to save transcoder config file '%s': %s" % (localPath, log.getExceptionMessage(e))) log.warning("%s", message) raise admerrs.PropertiesError(message)
def createFromComponentDict(cls, workerCtx, props): niceLevel = props.get("nice-level", None) name = props.get("admin-id", "") configPath = virtualpath.VirtualPath(props.get("config", None)) pathAttr = fileutils.PathAttributes.createFromComponentProperties(props) adminCtx = workerCtx.getAdminContext() adminLocal = adminCtx.getLocal() localPath = configPath.localize(adminLocal) if not os.path.exists(localPath): message = ("Transcoder config file not found ('%s')" % localPath) log.warning("%s", message) raise admerrs.PropertiesError(message) loader = inifile.IniFile() config = transconfig.TranscodingConfig() try: loader.loadFromFile(config, localPath) except Exception, e: message = ("Failed to load transcoder config file '%s': %s" % (localPath, log.getExceptionMessage(e))) log.warning("%s", message) raise admerrs.PropertiesError(message)
def _ebNotificationFailed(failure, kind): log.warning("%s notification failed: %s", kind, log.getFailureMessage(failure), category=adminconsts.NOTIFIER_LOG_CATEGORY)