Exemplo n.º 1
0
 def SvcDoRun(self):
     import servicemanager
     servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED,(self._svc_display_name_, ''))
     from pulse2.package_server.config import P2PServerCP
     config = P2PServerCP()
     config.setup(self.inifile)
     if config.use_iocp_reactor:
         from twisted.internet import iocpreactor
         iocpreactor.install()
     self.CheckForQuit()
     self.init(config)
     twisted.internet.reactor.run(installSignalHandlers=0)
     servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STOPPED,(self._svc_display_name_, ''))
 def SvcDoRun(self):
     import servicemanager
     servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                           servicemanager.PYS_SERVICE_STARTED,
                           (self._svc_display_name_, ''))
     from pulse2.package_server.config import P2PServerCP
     config = P2PServerCP()
     config.setup(self.inifile)
     if config.use_iocp_reactor:
         from twisted.internet import iocpreactor
         iocpreactor.install()
     self.CheckForQuit()
     self.init(config)
     twisted.internet.reactor.run(installSignalHandlers=0)
     servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                           servicemanager.PYS_SERVICE_STOPPED,
                           (self._svc_display_name_, ''))
Exemplo n.º 3
0
def main():
    try:
        import twisted
    except ImportError:
        print "Orbited requires Twisted, which is not installed. See http://twistedmatrix.com/trac/ for installation instructions."
        sys.exit(1)

    #################
    # This corrects a bug in Twisted 8.2.0 for certain Python 2.6 builds on Windows
    #   Twisted ticket: http://twistedmatrix.com/trac/ticket/3868
    #     -mario
    try:
        from twisted.python import lockfile
    except ImportError:
        from orbited import __path__ as orbited_path
        sys.path.append(os.path.join(orbited_path[0],"hotfixes","win32api"))
        from twisted.python import lockfile
        lockfile.kill = None
    #################

    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option(
        "-c",
        "--config",
        dest="config",
        default=None,
        help="path to configuration file"
    )
    parser.add_option(
        "-v",
        "--version",
        dest="version",
        action="store_true",
        default=False,
        help="print Orbited version"
    )
    parser.add_option(
        "-p",
        "--profile",
        dest="profile",
        action="store_true",
        default=False,
        help="run Orbited with a profiler"
    )
    parser.add_option(
        "-q",
        "--quickstart",
        dest="quickstart",
        action="store_true",
        default=False,
        help="run Orbited on port 8000 and MorbidQ on port 61613"
    )
    parser.add_option( 
        "-d", 
        "--daemon", 
        dest="daemon", 
        action="store_true", 
        default=False, 
        help="run Orbited as a daemon (requires the python-daemon package)"
        )
    parser.add_option(
        "--pid-file",
        dest="pidfile",
        default="/var/run/orbited/orbited.pid",
        help=("use PIDFILE as the orbited daemon pid file",
              "; defaults to '/var/run/orbited/orbited.pid'"),
        )
    
    MemoryUtil.add_options_to_parser(parser)
    
    (options, args) = parser.parse_args()

    if args:
        print 'the "orbited" command does not accept positional arguments. type "orbited -h" for options.'
        sys.exit(1)

    if options.version:
        print "Orbited version: %s" % (version,)
        sys.exit(0)
    
    global logger
    
    if options.quickstart:
        logging.basicConfig()
        logger = logging.getLogger(__name__)
        config.map['[listen]'].append('http://:8000')
        config.map['[listen]'].append('stomp://:61613')
        config.map['[access]'][('localhost',61613)] = ['*']
        logger.info("Quickstarting Orbited")
    else:
        # load configuration from configuration
        # file and from command line arguments.
        config.setup(options=options)
        logging.config.fileConfig(options.config)
        logger = logging.getLogger(__name__)
        logger.info("Starting Orbited with config file %s" % options.config)
    
    if options.daemon:
        try:
            from daemon import DaemonContext
            from daemon.pidfile import PIDLockFile
            pidlock = PIDLockFile(options.pidfile)
            daemon = DaemonContext(pidfile=pidlock)
            logger.debug('daemonizing with pid file %r', options.pidfile)
            daemon.open()
            logger.debug('daemonized!')
        except Exception, exc:
            logger.debug(exc)
 def init(self):
     config = Pulse2InventoryProxyConfig()
     config.setup(self.inifile)
     logging.config.fileConfig(self.inifile)
     initialize(config)
Exemplo n.º 5
0
def main():
    try:
        import twisted
    except ImportError:
        print "Orbited requires Twisted, which is not installed. See http://twistedmatrix.com/trac/ for installation instructions."
        sys.exit(1)

    #################
    # This corrects a bug in Twisted 8.2.0 for certain Python 2.6 builds on Windows
    #   Twisted ticket: http://twistedmatrix.com/trac/ticket/3868
    #     -mario
    try:
        from twisted.python import lockfile
    except ImportError:
        from orbited import __path__ as orbited_path
        sys.path.append(os.path.join(orbited_path[0],"hotfixes","win32api"))
        from twisted.python import lockfile
        lockfile.kill = None
    #################

    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option(
        "-c",
        "--config",
        dest="config",
        default=None,
        help="path to configuration file"
    )
    parser.add_option(
        "-v",
        "--version",
        dest="version",
        action="store_true",
        default=False,
        help="print Orbited version"
    )
    parser.add_option(
        "-p",
        "--profile",
        dest="profile",
        action="store_true",
        default=False,
        help="run Orbited with a profiler"
    )
    parser.add_option(
        "-q",
        "--quickstart",
        dest="quickstart",
        action="store_true",
        default=False,
        help="run Orbited on port 8000 and MorbidQ on port 61613"
    )

    (options, args) = parser.parse_args()

    if args:
        print 'the "orbited" command does not accept positional arguments. type "orbited -h" for options.'
        sys.exit(1)

    if options.version:
        print "Orbited version: %s" % (version,)
        sys.exit(0)

    if options.quickstart:
        config.map['[listen]'].append('http://:8000')
        config.map['[listen]'].append('stomp://:61613')
        config.map['[access]'][('localhost',61613)] = ['*']
        print "Quickstarting Orbited"
    else:
        # load configuration from configuration
        # file and from command line arguments.
        config.setup(options=options)

    logging.config.fileConfig(options.config)
    
    # NB: we need to install the reactor before using twisted.
    reactor_name = config.map['[global]'].get('reactor')
    if reactor_name:
        install = _import('twisted.internet.%sreactor.install' % reactor_name)
        install()
        logger.info('using %s reactor' % reactor_name)

    ############
    # This crude garbage corrects a bug in twisted
    #   Orbited ticket: http://orbited.org/ticket/111
    #   Twisted ticket: http://twistedmatrix.com/trac/ticket/2447
    import twisted.web.http
    twisted.web.http.HTTPChannel.setTimeout = lambda self, arg: None
    twisted.web.http.HTTPChannel.resetTimeout = lambda self: None
    ############

    from twisted.internet import reactor
    from twisted.web import resource
    from twisted.web import server
    from twisted.web import static
    import orbited.system

    root = resource.Resource()
    static_files = static.File(os.path.join(os.path.dirname(__file__), 'static'))
    root.putChild('static', static_files)
    root.putChild('system', orbited.system.SystemResource())
    
    if config.map['[test]']['stompdispatcher.enabled'] == '1':
        logger.info('stompdispatcher enabled')



    #gc.enable()
    #gc.set_debug(gc.DEBUG_LEAK)
    
    #reactor.callLater(1, cleanup, reactor)
    
    #static_files.putChild('orbited.swf', static.File(os.path.join(os.path.dirname(__file__), 'flash', 'orbited.swf')))
    site = server.Site(root)

    _setup_protocols(root)
    _setup_static(root, config.map)
    start_listening(site, config.map, logger)
    
    #reactor.callWhenRunning( createShellServer(reactor) )
    

    # switch uid and gid to configured user and group.
    if os.name == 'posix' and os.getuid() == 0:
        user = config.map['[global]'].get('user')
        group = config.map['[global]'].get('group')
        if user:
            import pwd
            import grp
            try:
                pw = pwd.getpwnam(user)
                uid = pw.pw_uid
                if group:
                    gr = grp.getgrnam(group)
                    gid = gr.gr_gid
                else:
                    gid = pw.pw_gid
                    gr = grp.getgrgid(gid)
                    group = gr.gr_name
            except Exception, e:
                logger.error('Aborting; Unknown user or group: %s' % e)
                sys.exit(1)
            logger.info('switching to user %s (uid=%d) and group %s (gid=%d)' % (user, uid, group, gid))
            os.setgid(gid)
            os.setuid(uid)
        else:
            logger.error('Aborting; You must define a user (and optionally a group) in the configuration file.')
            sys.exit(1)
Exemplo n.º 6
0
    return endBack()


def callFunction(deffered):
    """
        XMLRPC request handling

        attach callBack() and errorBack() to the deferred
    """
    deffered.addCallbacks( # deferred handling
        callBack,
        errorBack)

# Parse the command line
config = pulse2.imaging_server.config.ImagingConfig() #: ConfigParser object
config.setup(CONFIG_FILE)
logging.config.fileConfig(CONFIG_FILE)

# Instanciate the API
imagingAPI = pulse2.apis.clients.imaging.ImagingApi({
    "server" : config.pserver_host,
    "port" : config.pserver_port,
    "mountpoint" : config.pserver_mount_point,
    "enablessl" : config.pserver_enablessl,
    "username" : config.pserver_username,
    "password" : config.pserver_password,
    "verifypeer" : config.pserver_verifypeer,
    "localcert" : config.pserver_localcert,
    "cacert" : config.pserver_cacert,
}) #: Object which will be used to speak with our pserver
Exemplo n.º 7
0
    return endBack()


def callFunction(deffered):
    """
        XMLRPC request handling

        attach callBack() and errorBack() to the deferred
    """
    deffered.addCallbacks(  # deferred handling
        callBack, errorBack)


# Parse the command line
config = pulse2.imaging_server.config.ImagingConfig()  #: ConfigParser object
config.setup(CONFIG_FILE)
logging.config.fileConfig(CONFIG_FILE)

# Instanciate the API
imagingAPI = pulse2.apis.clients.imaging.ImagingApi({
    "server":
    config.pserver_host,
    "port":
    config.pserver_port,
    "mountpoint":
    config.pserver_mount_point,
    "enablessl":
    config.pserver_enablessl,
    "username":
    config.pserver_username,
    "password":
Exemplo n.º 8
0
def main():
    try:
        import twisted
    except ImportError:
        print "Orbited requires Twisted, which is not installed. See http://twistedmatrix.com/trac/ for installation instructions."
        sys.exit(1)

    #################
    # This corrects a bug in Twisted 8.2.0 for certain Python 2.6 builds on Windows
    #   Twisted ticket: http://twistedmatrix.com/trac/ticket/3868
    #     -mario
    try:
        from twisted.python import lockfile
    except ImportError:
        from orbited import __path__ as orbited_path
        sys.path.append(os.path.join(orbited_path[0], "hotfixes", "win32api"))
        from twisted.python import lockfile
        lockfile.kill = None
    #################

    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-c",
                      "--config",
                      dest="config",
                      default=None,
                      help="path to configuration file")
    parser.add_option("-v",
                      "--version",
                      dest="version",
                      action="store_true",
                      default=False,
                      help="print Orbited version")
    parser.add_option("-p",
                      "--profile",
                      dest="profile",
                      action="store_true",
                      default=False,
                      help="run Orbited with a profiler")
    parser.add_option(
        "-q",
        "--quickstart",
        dest="quickstart",
        action="store_true",
        default=False,
        help="run Orbited on port 8000 and MorbidQ on port 61613")
    parser.add_option(
        "-d",
        "--daemon",
        dest="daemon",
        action="store_true",
        default=False,
        help="run Orbited as a daemon (requires the python-daemon package)")
    parser.add_option(
        "--pid-file",
        dest="pidfile",
        default="/var/run/orbited/orbited.pid",
        help=("use PIDFILE as the orbited daemon pid file",
              "; defaults to '/var/run/orbited/orbited.pid'"),
    )

    MemoryUtil.add_options_to_parser(parser)

    (options, args) = parser.parse_args()

    if args:
        print 'the "orbited" command does not accept positional arguments. type "orbited -h" for options.'
        sys.exit(1)

    if options.version:
        print "Orbited version: %s" % (version, )
        sys.exit(0)

    global logger

    if options.quickstart:
        logging.basicConfig()
        logger = logging.getLogger(__name__)
        config.map['[listen]'].append('http://:8000')
        config.map['[listen]'].append('stomp://:61613')
        config.map['[access]'][('localhost', 61613)] = ['*']
        logger.info("Quickstarting Orbited")
    else:
        # load configuration from configuration
        # file and from command line arguments.
        config.setup(options=options)
        logging.config.fileConfig(options.config)
        logger = logging.getLogger(__name__)
        logger.info("Starting Orbited with config file %s" % options.config)

    if options.daemon:
        try:
            from daemon import DaemonContext
            from daemon.pidfile import PIDLockFile
            pidlock = PIDLockFile(options.pidfile)
            daemon = DaemonContext(pidfile=pidlock)
            logger.debug('daemonizing with pid file %r', options.pidfile)
            daemon.open()
            logger.debug('daemonized!')
        except Exception, exc:
            logger.debug(exc)
Exemplo n.º 9
0
        try:
            opts, args = getopt.getopt(sys.argv[1:], "hac:",
                                       ["help", "autostart", "config="])
        except getopt.GetoptError as err:
            print(str(err), file=sys.stderr)
            usage(2)
        for o, a in opts:
            if o in ('-h', '--help'):
                usage()
                pass
            elif o in ('-a', '--autostart'):
                self.autostart = True
            elif o in ('-c', '--config'):
                self.configfile = a
            else:
                print('Uhandled option', file=sys.stderr)


if __name__ == '__main__':
    config = ConfigHandler()
    runner = CommandRunner(config)
    console = Console(runner)
    config.read_ops()
    config.setup()

    if config.autostart:
        runner.start()

    console.interact()