def run(self):
        """
        Run daemon
         * change effective uid/gid
         * start thread for each check
         * start webserver
        """
        lg.info("Starting daemon")

        # Change effective UID/GID
        if self.conf.has_key('uid') and self.conf.has_key('gid'):
            if os.geteuid != self.conf['uid'] and os.getegid != self.conf['gid']:
                try:
                    os.setegid(self.conf['gid'])
                    os.seteuid(self.conf['uid'])
                except TypeError as e:
                    lg.error("Config parameters uid/gid have to be integers: %s" % e)
                except OSError as e:
                    lg.error("Can't switch effective UID/GID to %s/%s: %s" % (self.conf['uid'], self.conf['gid'], e))
                    lg.exception(e)
                    self._shutdown(exitcode=1)
        else:
            lg.info("Not changing effective UID/GID, keeping %s/%s" % (os.geteuid(), os.getegid()))

        if not isinstance(self.conf['bind_port'], int):
            lg.error("Config parameter bind_port has to be integer")

        # Initialize plugin manager
        config = {}

        for key in ['plugins', 'templates', 'actions']:
            try:
                config[key] = self.conf[key]
            except __HOLE__ as e:
                lg.warn("Config section not found: %s" % e)

        # Check we have some plugins configured
        if not config['plugins']:
            lg.error('No configured plugins')
            self._shutdown(exitcode=1)

        if 'nr_concurrent_plugins' in self.conf:
            config['semaphore_count'] = self.conf['nr_concurrent_plugins']

        try:
            self.pluginmgr = PluginManager(**config)
        except Exception as e:
            lg.error("Can't initialize PluginManager")
            lg.exception(e)
            self._shutdown(exitcode=1)

        lg.info("Starting webserver on %(bind_host)s:%(bind_port)s"
                % self.conf)
        try:
            self.server = RestServer(self.conf['bind_host'],
                                     self.conf['bind_port'], self)
            self.server.start()
        except Exception as e:
            lg.error("Can't start HTTP server: %s" % e)
            lg.exception(e)
            self._shutdown(exitcode=1)

        # Catch SIGINT and SIGTERM if supported
        if hasattr(signal, 'SIGINT'):
            signal.signal(signal.SIGINT, self._shutdown)

        if hasattr(signal, 'SIGTERM'):
            signal.signal(signal.SIGTERM, self._shutdown)

        if hasattr(signal, 'SIGHUP'):
            signal.signal(signal.SIGHUP, self._reopen_logfiles)

        self._watchdog()
dataset/ETHPy150Open gooddata/smoker/smoker/server/daemon.py/Smokerd.run