def __init__(self, args):
		win32serviceutil.ServiceFramework.__init__(self, args)
		
		# Give the multiprocessing module a python interpreter to run
		if sys.argv[0].endswith("exe"):
			basedir = os.path.dirname(sys.argv[0])
			multiprocessing.set_executable(os.path.join(basedir, "ulteo-ovd-slaveserver.exe"))
	
		# Init the logger instance
		Win32Logger.initialize("OVD", Config.log_level, None)
		ConfigModule.report_error = WinReport_error
		
		config_file = os.path.join(Platform.System.get_default_config_dir(), "slaveserver.conf")
		if not Config.read(config_file):
			Logger.error("invalid configuration file '%s'"%(config_file))
			sys.exit(1)
	
		if not Config.is_valid():
			Logger.error("invalid config")
			sys.exit(1)
		
		Win32Logger.initialize("OVD", Config.log_level, Config.log_file)
		
		
		SlaveServer.__init__(self, Communication)
		self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
Exemple #2
0
    def SvcDoRun(self):
        config_file = os.path.join(System.get_default_config_dir(),
                                   "slaveserver.conf")
        if not Config.read(ConfigReader.process(None)):
            return

        if not Config.is_valid():
            return

        Win32Logger.initialize("OVD", Config.log_level, Config.log_file)

        try:
            ServerCheckup.check()
        except:
            Logger.exception("Server checkup")
            return

        slave = SlaveServer(Communication)

        if not slave.load_roles():
            return

        if not slave.init():
            Logger.error("Unable to initialize SlaveServer")
            slave.stop()
            return

        inited = False
        rc = win32event.WAIT_TIMEOUT
        while rc == win32event.WAIT_TIMEOUT:
            if not inited:
                ret = slave.push_production()
                if ret:
                    inited = True
                    Logger.info("SlaveServer started")
                else:
                    Logger.warn(
                        "Session Manager not connected. Sleeping for a while ..."
                    )

            if inited:
                slave.loop_procedure()

            rc = win32event.WaitForSingleObject(self.hWaitStop, 30 * 1000)

        if not slave.stopped:
            slave.stop()

        Logger.info("SlaveServer stopped")
	def SvcDoRun(self):
		config_file = os.path.join(System.get_default_config_dir(), "slaveserver.conf")
		if not Config.read(ConfigReader.process(None)):
			return
		
		if not Config.is_valid():
			return
		
		Win32Logger.initialize("OVD", Config.log_level, Config.log_file)
		
		try:
			ServerCheckup.check()
		except:
			Logger.exception("Server checkup")
			return
		
		slave = SlaveServer(Communication)
		
		if not slave.load_roles():
			return
		
		if not slave.init():
			Logger.error("Unable to initialize SlaveServer")
			slave.stop()
			return
		
		inited = False
		rc = win32event.WAIT_TIMEOUT
		while rc == win32event.WAIT_TIMEOUT:
			if not inited:
				ret = slave.push_production()
				if ret:
					inited = True
					Logger.info("SlaveServer started")
				else:
					Logger.warn("Session Manager not connected. Sleeping for a while ...")
			
			if inited:
				slave.loop_procedure()
			
			rc = win32event.WaitForSingleObject(self.hWaitStop, 30 * 1000)
		
		if not slave.stopped:
			slave.stop()
		
		Logger.info("SlaveServer stopped")
def main(queue, config_file, pid_file):
    daemonize = bool(queue)

    def _exit(code, msg=''):
        if daemonize:
            queue.put((code, msg))
        else:
            return (code, msg)

    if not Config.read(
            ConfigReader.process(config_file)) or not Config.is_valid():
        return _exit(1, "wrong config file")

    Logger.initialize("OVD", Config.log_level, Config.log_file, not daemonize,
                      Config.log_threaded)

    server = SlaveServer(Communication)

    signal.signal(signal.SIGINT, stop)
    signal.signal(signal.SIGTERM, stop)

    try:
        if pid_file is not None:
            try:
                f = open(pid_file, "w")
                f.write(str(os.getpid()))
                f.close()
            except IOError:
                raise InterruptedException(
                    2, "Unable to write pid-file '%s'" % pid_file)

        if not server.load_roles():
            raise InterruptedException(3, "Cannot load some Roles")

        if not server.init():
            raise InterruptedException(4, "Server initialization failed")

    except InterruptedException, e:
        code, msg = e.args
        return _exit(code, msg)
def main(queue, config_file, pid_file):
	daemonize = bool(queue)
	
	def _exit(code, msg=''):
		if daemonize:
			queue.put((code, msg))
		else:
			return (code, msg)
	
	if not Config.read(ConfigReader.process(config_file)) or not Config.is_valid():
		return _exit(1, "wrong config file")
	
	Logger.initialize("OVD", Config.log_level, Config.log_file, not daemonize, Config.log_threaded)
	
	server = SlaveServer(Communication)
	
	signal.signal(signal.SIGINT, stop)
	signal.signal(signal.SIGTERM, stop)
	
	try:
		if pid_file is not None:
			try:
				f = open(pid_file, "w")
				f.write(str(os.getpid()))
				f.close()
			except IOError:
				raise InterruptedException(2, "Unable to write pid-file '%s'" % pid_file)
		
		if not server.load_roles():
			raise InterruptedException(3, "Cannot load some Roles")
		
		if not server.init():
			raise InterruptedException(4, "Server initialization failed")
	
	except InterruptedException, e:
		code, msg = e.args
		return _exit(code, msg)