Example #1
0
    def mainloop(self):
        # we don't expect non-option arguments
        if self.args:
            self.parser.error("incorrect number of arguments")

        pidfile = "moin.pid"
        if self.options.pidfile:
            pidfile = self.options.pidfile

        if self.options.stop:
            try:
                pids = open(pidfile, "r").read()
            except IOError:
                print "pid file not found (server not running?)"
            else:
                try:
                    os.kill(int(pids), signal.SIGTERM)
                except OSError:
                    print "kill failed (server not running?)"
            os.remove(pidfile)
        else:
            try:
                if self.options.config_dir:
                    sys.path.insert(0, self.options.config_dir)
                from wikiserverconfig import Config
            except ImportError, err:
                if 'wikiserverconfig' in str(err):
                    # we are unable to import from wikiserverconfig module
                    Config = DefaultConfig
                else:
                    # some other import went wrong
                    raise

            # intialize some defaults if missing
            kwargs = {}
            for option in (
                    'user',
                    'group',
                    'hostname',
                    'port',
                    'threaded',
                    'processes',
                    'debug',
                    'use_evalex',
                    'use_reloader',
                    'extra_files',
                    'reloader_interval',
                    'docs',
                    'static_files',
            ):
                if hasattr(Config, option):
                    kwargs[option] = getattr(Config, option)
                else:
                    # usually inheriting from DefaultConfig should make this superfluous,
                    # but who knows what users write into their config...
                    kwargs[option] = getattr(DefaultConfig, option)

            # override config settings with cmdline options:
            if self.options.docs:
                kwargs['docs'] = self.options.docs
            if self.options.user:
                kwargs['user'] = self.options.user
            if self.options.group:
                kwargs['group'] = self.options.group
            if self.options.debug:
                kwargs['debug'] = self.options.debug

            if self.options.hostname is not None:  # needs to work for "" value also
                kwargs['hostname'] = self.options.hostname
            if self.options.port:
                kwargs['port'] = self.options.port

            if self.options.start:
                daemon = Daemon('moin', pidfile, run_server, **kwargs)
                daemon.do_start()
            else:
                run_server(**kwargs)
Example #2
0
File: ssh.py Project: happytk/moin
                      }
        application = make_application(shared=docs)

        if debug == 'external':
            # no threading is better for debugging, the main (and only)
            # thread then will just terminate when an exception happens
            threaded = False

        app = flask.Flask(__name__)
        app.register_blueprint(easy_attach_page, url_prefix='/easy_attach')
        application = DispatcherMiddleware(application, {
            '/archive':  application,
            '/ntuning':  application,
            '/mei':      application,
            '/master':   application,
            '/__moinfbp': app,
        })

        kwargs = dict(hostname=hostname, port=port,
                       application=application,
                       threaded=threaded,
                       use_debugger=(debug == 'web'),
                       passthrough_errors=(debug == 'external'),
                       request_handler=RequestHandler,
                       ssl_context=ctx)
        if len(sys.argv) > 1 and sys.argv[1] in ['start', 'restart']:
            daemon = Daemon('moin', pidfile, run_simple, **kwargs)
            daemon.do_start()
        else:
            run_simple(**kwargs)
Example #3
0
    def mainloop(self):
        # we don't expect non-option arguments
        if self.args:
            self.parser.error("incorrect number of arguments")

        pidfile = "moin.pid"
        if self.options.pidfile:
            pidfile = self.options.pidfile

        if self.options.stop:
            try:
                pids = open(pidfile, "r").read()
            except IOError:
                print "pid file not found (server not running?)"
            else:
                try:
                    os.kill(int(pids), signal.SIGTERM)
                except OSError:
                    print "kill failed (server not running?)"
            os.remove(pidfile)
        else:
            try:
                if self.options.config_dir:
                    sys.path.insert(0, self.options.config_dir)
                from wikiserverconfig import Config
            except ImportError, err:
                if 'wikiserverconfig' in str(err):
                    # we are unable to import from wikiserverconfig module
                    Config = DefaultConfig
                else:
                    # some other import went wrong
                    raise

            # intialize some defaults if missing
            kwargs = {}
            for option in ('user', 'group',
                           'hostname', 'port',
                           'threaded', 'processes',
                           'debug', 'use_evalex',
                           'use_reloader', 'extra_files', 'reloader_interval',
                           'docs', 'static_files', ):
                if hasattr(Config, option):
                    kwargs[option] = getattr(Config, option)
                else:
                    # usually inheriting from DefaultConfig should make this superfluous,
                    # but who knows what users write into their config...
                    kwargs[option] = getattr(DefaultConfig, option)

            # override config settings with cmdline options:
            if self.options.docs:
                kwargs['docs'] = self.options.docs
            if self.options.user:
                kwargs['user'] = self.options.user
            if self.options.group:
                kwargs['group'] = self.options.group
            if self.options.debug:
                kwargs['debug'] = self.options.debug

            if self.options.hostname is not None: # needs to work for "" value also
                kwargs['hostname'] = self.options.hostname
            if self.options.port:
                kwargs['port'] = self.options.port

            if self.options.start:
                daemon = Daemon('moin', pidfile, run_server, **kwargs)
                daemon.do_start()
            else:
                run_server(**kwargs)