コード例 #1
0
    def run_application(self):
        log.debug('pidfile: %s' % self.pidfile)
        log.debug('runing app on port %d' % self.port)

        app_yaml = os.path.join(self.app_path, 'app.yaml')
        if not os.path.exists(app_yaml):
            log.error('there is no app.yaml at %s' % app_yaml)
            return

        #this is application yaml config
        yaml = ApplicationConfiguration(app_yaml)
        sys.path.insert(0, self.app_path)

        if yaml.runtime == 'python':
            yaml.provider = 'boost'
            set_yaml(yaml)

            if self.config.enable_logging:
                enable_logging = eval(self.config.enable_logging)
                appserver.HardenedModulesHook.ENABLE_LOGGING = enable_logging

            def yaml_to_dict(config):
                d = {}
                for attr in dir(config):
                    if not attr.startswith('_'):
                        value = getattr(config, attr)
                        d[attr] = value
                return d['data']

            option_dict = yaml_to_dict(self.config)

            if self.config.debug_mode:
                log_level = logging.DEBUG
            else:
                log_level = logging.INFO
            login_url = option_dict.get('login_url', '/_ah/login')
            template_dir = option_dict.get('template_dir',
                                           os.path.join(SDK_PATH, 'templates'))
            serve_address = option_dict.get('address', 'localhost')
            require_indexes = eval(option_dict.get('require_indexes', 'False'))
            allow_skipped_files = eval(
                option_dict.get('allow_skipped_files', 'False'))
            static_caching = eval(option_dict.get('static_caching', 'True'))
            cpu_monitor_interval = int(
                option_dict.get('cpu_monitor_interval', 1000))

            option_dict['root_path'] = os.path.realpath(self.app_path)
            option_dict['login_url'] = login_url
            option_dict['datastore_path'] = os.path.join(
                tempfile.gettempdir(), 'dev_appserver.datastore')
            option_dict['clear_datastore'] = False
            option_dict['port'] = self.port

            logging.getLogger().setLevel(log_level)

            config = None
            try:
                config, matcher = appserver.LoadAppConfig(self.app_path, {})
            except yaml_errors.EventListenerError, e:
                log.error(
                    'Fatal error when loading application configuration:\n' +
                    str(e))
                return 1
            except appserver.InvalidAppConfigError, e:
                log.error('Application configuration file invalid:\n%s', e)
                return 1
コード例 #2
0
ファイル: server.py プロジェクト: anoopjoe/cyclozzo
	def run_application(self):
		log.debug('pidfile: %s' % self.pidfile)
		log.debug('runing app on port %d' % self.port)

		app_yaml = os.path.join(self.app_path, 'app.yaml')
		if not os.path.exists(app_yaml):
			log.error('there is no app.yaml at %s' % app_yaml)
			return

		#this is application yaml config
		yaml = ApplicationConfiguration(app_yaml)
		sys.path.insert(0, self.app_path)

		if yaml.runtime == 'python':
			yaml.provider = 'boost'
			set_yaml(yaml)

			if self.config.enable_logging:
				enable_logging = eval(self.config.enable_logging)
				appserver.HardenedModulesHook.ENABLE_LOGGING = enable_logging

			def yaml_to_dict(config):
				d = {}
				for attr in dir(config):
					if not attr.startswith('_'):
						value = getattr(config, attr)
						d[attr] = value
				return d['data']

			option_dict = yaml_to_dict(self.config)

			if self.config.debug_mode:
				log_level = logging.DEBUG
			else:
				log_level = logging.INFO
			login_url = option_dict.get('login_url', '/_ah/login')
			template_dir = option_dict.get('template_dir', os.path.join(SDK_PATH, 'templates'))
			serve_address = option_dict.get('address', 'localhost')
			require_indexes = eval(option_dict.get('require_indexes', 'False'))
			allow_skipped_files = eval(option_dict.get('allow_skipped_files', 'False'))
			static_caching = eval(option_dict.get('static_caching', 'True'))
			cpu_monitor_interval = int(option_dict.get('cpu_monitor_interval', 1000))

			option_dict['root_path'] = os.path.realpath(self.app_path)
			option_dict['login_url'] = login_url
			option_dict['datastore_path'] = os.path.join(tempfile.gettempdir(),
														'dev_appserver.datastore')
			option_dict['clear_datastore'] = False
			option_dict['port'] = self.port

			logging.getLogger().setLevel(log_level)

			config = None
			try:
				config, matcher = appserver.LoadAppConfig(self.app_path, {})
			except yaml_errors.EventListenerError, e:
				log.error('Fatal error when loading application configuration:\n' +
						str(e))
				return 1
			except appserver.InvalidAppConfigError, e:
				log.error('Application configuration file invalid:\n%s', e)
				return 1
コード例 #3
0
            f = open(dp, 'r')
            dpid = int(f.readline())
            f.close()
            return dpid

        else:
            return '-'

    this_dir = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    yaml_path = os.path.join(this_dir, 'appserver.yaml')
    if not os.path.exists(yaml_path):
        print 'No configuration yaml for satellite found.'
        sys.exit(1)

    yaml = ApplicationConfiguration(yaml_path)

    parser = OptionParser()
    parser.add_option("-n", "--name", help="Application name")
    parser.add_option("-r", "--revision", help="Application revision")
    parser.add_option("-p", "--port", help="Listen port number")
    parser.add_option("-k", "--key", help="Server key")

    parser.add_option("-s",
                      "--start",
                      action="store_true",
                      default=False,
                      help="Sends START command")
    parser.add_option("-t",
                      "--stop",
                      action="store_true",
コード例 #4
0
def main():
    """Commandline utility for configuring Cyclozzo Nodes.
    """
    # path to the master configuration file
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 
                               'settings.yaml')
    config = ApplicationConfiguration(config_file)
    fabfile.update_roles(config)

    # define commandline options
    usage = 'cyclozzo-lite [options]'
    parser = OptionParser(usage)
    parser.add_option('-e', '--exchange-keys', action='store_true', 
                      default=False,
                      help='Exchange SSH keys between Master and Slaves',
                      dest='exchange_keys')
    parser.add_option('-t', '--settings', action='store_true', default=False,
                      help='Configuration file for Cyclozzo node settings.')
    parser.add_option('-c', '--configure', action='store_true', default=False,
                      help='Configure Cyclozzo Master/Client Services')
    parser.add_option('-f', '--format', default=False, dest='format',
                      help='Format DFS and DS. Options: [dfs, ds, all]',
                      choices=['ds', 'dfs', 'all'])
    parser.add_option('-s', '--start', default=False, dest='start',
                      help='Start Cyclozzo Cluster/Application. ' \
                      'Options: [cluster, application]',
                      choices=['cluster', 'application'])
    parser.add_option('-k', '--stop', default=False, dest='stop',
                      help='Stop Cyclozzo Cluster/Application Services. ' \
                      'Options: [cluster, application]',
                      choices=['cluster', 'application'])
    parser.add_option('--status', default=False, dest='status',
                      help='List Cluster/Application status. ' \
                      'Options: [cluster, application]',
                      choices=['cluster', 'application'])

    parser.add_option('--dir',  help='Application Directory', dest='app_dir')
    parser.add_option('--port', help='Listen port number', type='int')
    parser.add_option('--debug', action='store_true', default=False,
                        help='Run the application in foreground')


    # parse the options
    (options, args) = parser.parse_args()

    if options.exchange_keys:
        fabfile.exchange_keys()

    elif options.settings:
        print config_file

    elif options.configure:
        if not config.slaves:
            config.slaves=[]
        # configure hadoop and hypertable on (this) master
        configure_hadoop(primary=config.master, 
                         secondary=config.slaves)
        configure_hypertable(primary=config.master, 
                             secondary=config.slaves)
        # configure Redis for pubsub
        configure_redis()
        fabfile.rsync()
        if options.format == 'dfs' or options.format == 'all':
            fabfile.start_hadoop_namenode()
            fabfile.start_hadoop_datanode()
            fabfile.format_hadoop_datanode()
            fabfile.format_hadoop_namenode()
            fabfile.stop_hadoop_datanode()
            fabfile.stop_hadoop_namenode()
            print '--> Waiting for Name/Datanode to stop (5 secs)'
            sleep(5)
        if options.format == 'ds' or options.format == 'all':
            fabfile.start_hadoop_namenode()
            fabfile.start_hadoop_datanode()
            fabfile.start_dfsbrokers()
            fabfile.format_hypertable()
            fabfile.stop_hadoop_datanode()
            fabfile.stop_hadoop_namenode()
            print '--> Waiting for Name/Datanode to stop (5 secs)'
            sleep(5)
                    
    elif options.start == 'cluster':
        fabfile.start()

    elif options.stop == 'cluster':
        fabfile.stop()

    elif options.start == 'application':
        if not options.app_dir or not options.port:
            print 'Missing arguments: --app_dir, --port'
            parser.print_help()
        else:
            print 'Starting application from %s on port %d' % \
                            (options.app_dir, options.port)
            appserver_yaml = os.path.join(
                                          os.path.dirname(                                                     
                                                    os.path.abspath(
                                                    appserver.__file__
                                                    )
                                                          ), 
                                          'appserver.yaml')
            appserver_yaml = ApplicationConfiguration(appserver_yaml)
            if options.debug:
                appserver_yaml.debug_mode = True
            daemon = AppDaemon(appserver_yaml, 
                               options.app_dir, 
                               None, 
                               options.port, 
                               None, 
                               None
                               )
            if options.debug:
                daemon.run_application()
            else:
                daemon.start()

    elif options.stop == 'application':
        if not options.app_dir:
            print 'Missing arguments: --app_dir'
            parser.print_help()
        else:
            pid = get_pid(options.app_dir)
            if pid == 0:
                print 'No instance running'
                sys.exit(1)
            print 'Stopping instance with pid %d' % pid
            os.kill(pid, signal.SIGTERM)

    elif options.status == 'application':
        if not options.app_dir:
            print 'Missing arguments: --app_dir'
            parser.print_help()
        pid = get_pid(options.app_dir)
        running = os.path.exists('/proc/%d' %pid)
        if pid and running:
            print 'Application with process id %d is running' %pid
        elif pid:
            print 'Application with process id %d is stopped' %pid
        else:
            print 'Application is not running'
    elif options.status == 'cluster':
        print 'Cluster status not available.'
    else:
        parser.print_help()