Пример #1
0
        msg.append(' http://%s:%s/' % (hostname, port))
        for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
            msg.append(' http://%s:%s/' % (ip, port))
    else:
        msg.append(' http://%s:%s/' % (address, port))
    log(''.join(msg))
    log("frePPLe using %s database '%s' as '%s' on '%s:%s'" %
        (settings.DATABASES[DEFAULT_DB_ALIAS].get('ENGINE', '').split('.')[-1],
         settings.DATABASES[DEFAULT_DB_ALIAS].get(
             'NAME', ''), settings.DATABASES[DEFAULT_DB_ALIAS].get('USER', ''),
         settings.DATABASES[DEFAULT_DB_ALIAS].get('HOST', ''),
         settings.DATABASES[DEFAULT_DB_ALIAS].get('PORT', '')))

    # Start a separate thread that will check for updates.
    # We don't wait for it to finish.
    CheckUpdates().start()

    # Run the WSGI server in a new thread
    wsgi = RunWSGIServer(address, port)
    wsgi.start()

    # Run an icon in the system tray
    SysTrayIcon(
        1,  #  Icon. If integer it is loaded from the executable, otherwise loaded from file.
        'frePPLe server on port %s' %
        port,  # Text displayed when hovering over the icon
        (  # Menu_options
            ('Open browser', None, OpenBrowser),
            ('Show log directory', None, ShowLogDirectory),
            ('Show configuration directory', None, ShowConfigDirectory),
            ('Open command window', None, OpenCommandWindow),
Пример #2
0
    def SvcDoRun(self):
        # Environment settings (which are used in the Django settings file and need
        # to be updated BEFORE importing the settings)
        os.environ['DJANGO_SETTINGS_MODULE'] = 'freppledb.settings'
        os.environ['FREPPLE_APP'] = os.path.join(os.path.split(sys.path[0])[0],'custom')
        os.environ['FREPPLE_HOME'] = os.path.abspath(os.path.dirname(sys.argv[0]))

        # Add the custom directory to the Python path.
        sys.path = [ os.environ['FREPPLE_APP'], sys.path[0] ]

        # Import modules
        from django.conf import settings
        import cherrypy
        from cherrypy.wsgiserver import CherryPyWSGIServer
        import django
        from django.core.handlers.wsgi import WSGIHandler
        from django.contrib.staticfiles.handlers import StaticFilesHandler
        from stat import S_ISDIR, ST_MODE

        # Override the debugging settings
        settings.DEBUG = False
        settings.TEMPLATE_DEBUG = False

        # Pick up port and adress
        try: address = socket.gethostbyname(socket.gethostname())
        except: address = '127.0.0.1'
        port = settings.PORT

        cherrypy.config.update({
            'global':{
                'log.screen': False,
                'tools.log_tracebacks.on': True,
                'engine.autoreload.on': False,
                'engine.SIGHUP': None,
                'engine.SIGTERM': None
                }
            })
        self.server = CherryPyWSGIServer((address, port),
          StaticFilesHandler(WSGIHandler())
          )

        # Redirect all output and log a start event
        try:
          log = os.path.join(settings.FREPPLE_LOGDIR,'service.log')
          sys.stdout = open(log, 'a', 0)
          msg = "frePPLe web server listening on http://%s:%d and logging to %s" % (address, port, log)
          servicemanager.LogInfoMsg(msg)
          print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg)
        except:
          # Too bad if we can't write log info
          servicemanager.LogInfoMsg("frePPLe web server listening on http://%s:%d without log file" % (address, port))

        # Log usage
        from freppledb.execute.management.commands.frepple_runserver import CheckUpdates
        CheckUpdates().start()

        # Infinite loop serving requests
        try:
          self.server.start()
        except Exception as e:
          # Log an error event
          msg = "frePPLe web server failed to start:\n%s" % e
          servicemanager.LogErrorMsg(msg)
          print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg)