Beispiel #1
0
    def __init__(self):

        bottle.TEMPLATE_PATH.insert(0,
                                    os.path.join(
                                        get_directory_location('share'),
                                        "views"))
        bottle.TEMPLATE_PATH.insert(0,
                                    os.path.join(
                                        get_directory_location('share')))

        #
        # Load from config (.ini)
        #
        config = SafeConfigParser()
        config.read(os.path.join(get_directory_location('etc'), 'service.ini'))

        self._reloader = config.get('global', 'reloader')
        self._quiet = config.get('global', 'quiet')
        self._debug = config.get('global', 'debug')

        self.service_url = config.get('global', 'service_url')

        #
        # username/password are for basic-auth access
        #
        self.username = config.get('global', 'username')
        self.password = config.get('global', 'password')

        if self._debug in ['true', 'True']:
            self._debug = True
        else:
            self._debug = False
        if self._quiet in ['true', 'True']:
            self._quiet = True
        else:
            self._quiet = False
        if self._reloader in ['true', 'True']:
            self._reloader = True
        else:
            self._reloader = False

        #
        # Set the PID
        #
        self.pid = os.getpid()
        f = open(os.path.join(get_directory_location('run'),
                              'service.pid'), 'w')
        f.write("%d" % self.pid)
        f.close()

        #
        # Setup logging
        #
        self.log = setupLogging(get_directory_location('log'),
                                'service.log', mode='prod')

        self._host = configutils.get_host_name(self.service_url)
        self._port = int(configutils.get_host_port(self.service_url))
        self._app = bottle.Bottle()
        self._server_backend = config.get('global', 'server_backend')

        # log the pid
        self.log.info('Service running pid (%d)' % self.pid)

        # resources available
        self.resources = []

        # setup routes
        self._route()
Beispiel #2
0
 def stop(self):
     os.unlink(os.path.join(get_directory_location('run'), 'service.pid'))