示例#1
0
def start_service(service_name):
  """ Creates a monit configuration file and prompts Monit to start service.
  Args:
    service_name: The name of the service to start.
  """
  logging.info("Starting " + service_name)
  watch_name = ""
  if service_name == datastore_upgrade.CASSANDRA_WATCH_NAME:
    start_cmd = CASSANDRA_EXECUTABLE + " start -p " + PID_FILE
    stop_cmd = "/usr/bin/python2 " + APPSCALE_HOME + "/scripts/stop_service.py java cassandra"
    watch_name = datastore_upgrade.CASSANDRA_WATCH_NAME
    ports = [CASSANDRA_PORT]
    match_cmd = cassandra_interface.CASSANDRA_INSTALL_DIR

  if service_name == datastore_upgrade.ZK_WATCH_NAME:
    zk_server="zookeeper-server"
    command = 'service --status-all|grep zookeeper$'
    if subprocess.call(command, shell=True) == 0:
      zk_server = "zookeeper"

    start_cmd = "/usr/sbin/service " + zk_server + " start"
    stop_cmd = "/usr/sbin/service " + zk_server + " stop"
    watch_name = datastore_upgrade.ZK_WATCH_NAME
    match_cmd = "org.apache.zookeeper.server.quorum.QuorumPeerMain"
    ports = [zk.DEFAULT_PORT]

  monit_app_configuration.create_config_file(watch_name, start_cmd, stop_cmd,
    ports, upgrade_flag=True, match_cmd=match_cmd)

  if not monit_interface.start(watch_name):
    logging.error("Monit was unable to start " + service_name)
    return 1
  else:
    logging.info('Monit configured for {}'.format(service_name))
    return 0
    def test_start(self):
        testing.disable_logging()

        flexmock(file_io)\
          .should_receive('delete')\
          .and_return()

        flexmock(subprocess)\
          .should_receive('call')\
          .and_return(0)

        self.assertEqual(True, monit_interface.start("watch_name"))

        flexmock(subprocess)\
          .should_receive('call')\
          .and_return(1)

        self.assertEqual(False, monit_interface.start("watch_name"))
  def test_start(self):
    testing.disable_logging()

    flexmock(file_io)\
      .should_receive('delete')\
      .and_return()

    flexmock(subprocess)\
      .should_receive('call')\
      .and_return(0) 

    self.assertEqual(True, monit_interface.start("watch_name"))

    flexmock(subprocess)\
      .should_receive('call')\
      .and_return(1) 

    self.assertEqual(False, monit_interface.start("watch_name"))
示例#4
0
def restart_app_instances_for_app(app_name, language):
  """ Restarts all instances of a Google App Engine application on this machine.

  Args:
    app_name: The application ID corresponding to the app to restart.
    language: The language the application is written in.
  Returns:
    True if successful, and False otherwise.
  """
  if not misc.is_app_name_valid(app_name):
    logging.error("Unable to kill app process %s on because of " \
      "invalid name for application" % (app_name))
    return False
  if language == "java":
    remove_conflicting_jars(app_name)
    copy_modified_jars(app_name)
  logging.info("Restarting application %s" % app_name)
  watch = "app___" + app_name
  monit_interface.stop(watch)
  time.sleep(1)
  return monit_interface.start(watch)
示例#5
0
def start_service(service_name):
    """ Creates a monit configuration file and prompts Monit to start service.
  Args:
    service_name: The name of the service to start.
  """
    logging.info("Starting " + service_name)
    watch_name = ""
    if service_name == datastore_upgrade.CASSANDRA_WATCH_NAME:
        start_cmd = CASSANDRA_EXECUTABLE + " start -p " + PID_FILE
        stop_cmd = "/usr/bin/python2 " + APPSCALE_HOME + "/scripts/stop_service.py java cassandra"
        watch_name = datastore_upgrade.CASSANDRA_WATCH_NAME
        ports = [CASSANDRA_PORT]
        match_cmd = cassandra_interface.CASSANDRA_INSTALL_DIR

    if service_name == datastore_upgrade.ZK_WATCH_NAME:
        zk_server = "zookeeper-server"
        command = 'service --status-all|grep zookeeper$'
        if subprocess.call(command, shell=True) == 0:
            zk_server = "zookeeper"

        start_cmd = "/usr/sbin/service " + zk_server + " start"
        stop_cmd = "/usr/sbin/service " + zk_server + " stop"
        watch_name = datastore_upgrade.ZK_WATCH_NAME
        match_cmd = "org.apache.zookeeper.server.quorum.QuorumPeerMain"
        ports = [zk.DEFAULT_PORT]

    monit_app_configuration.create_config_file(watch_name,
                                               start_cmd,
                                               stop_cmd,
                                               ports,
                                               upgrade_flag=True,
                                               match_cmd=match_cmd)

    if not monit_interface.start(watch_name):
        logging.error("Monit was unable to start " + service_name)
        return 1
    else:
        logging.info('Monit configured for {}'.format(service_name))
        return 0
示例#6
0
def run(): 
  """ Starts up cassandra. """ 
  logging.warning("Starting Cassandra.")
  monit_interface.start(cassandra_interface.CASSANDRA_MONIT_WATCH_NAME,
    is_group=False)
  logging.warning("Done!") 
示例#7
0
def start_app(config):
    """ Starts a Google App Engine application on this machine. It
      will start it up and then proceed to fetch the main page.

  Args:
    config: a dictionary that contains
       app_name: Name of the application to start
       app_port: Port to start on
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       xmpp_ip: IP of XMPP service
       dblocations: List of database locations
       env_vars: A dict of environment variables that should be passed to the
        app.
       max_memory: An int that names the maximum amount of memory that this
        App Engine app is allowed to consume before being restarted.
  Returns:
    PID of process on success, -1 otherwise
  """
    config = convert_config_from_json(config)
    if config == None:
        logging.error("Invalid configuration for application")
        return BAD_PID

    if not misc.is_app_name_valid(config['app_name']):
        logging.error("Invalid app name for application: " +\
                      config['app_name'])
        return BAD_PID
    logging.info("Starting %s application %s" %
                 (config['language'], config['app_name']))

    start_cmd = ""
    stop_cmd = ""
    env_vars = config['env_vars']
    env_vars['GOPATH'] = '/root/appscale/AppServer/gopath/'
    env_vars['GOROOT'] = '/root/appscale/AppServer/goroot/'
    watch = "app___" + config['app_name']

    if config['language'] == constants.PYTHON27 or \
         config['language'] == constants.GO or \
         config['language'] == constants.PHP:
        start_cmd = create_python27_start_cmd(config['app_name'],
                                              config['load_balancer_ip'],
                                              config['app_port'],
                                              config['load_balancer_ip'],
                                              config['xmpp_ip'])
        logging.info(start_cmd)
        stop_cmd = create_python27_stop_cmd(config['app_port'])
        env_vars.update(
            create_python_app_env(config['load_balancer_ip'],
                                  config['app_name']))
    elif config['language'] == constants.JAVA:
        remove_conflicting_jars(config['app_name'])
        copy_successful = copy_modified_jars(config['app_name'])
        if not copy_successful:
            return BAD_PID
        start_cmd = create_java_start_cmd(config['app_name'],
                                          config['app_port'],
                                          config['load_balancer_ip'])
        stop_cmd = create_java_stop_cmd(config['app_port'])
        env_vars.update(create_java_app_env())
    else:
        logging.error("Unknown application language %s for appname %s"\
                      %(config['language'], config['app_name']))
        return BAD_PID

    logging.info("Start command: " + str(start_cmd))
    logging.info("Stop command: " + str(stop_cmd))
    logging.info("Environment variables: " + str(env_vars))

    monit_app_configuration.create_config_file(str(watch), str(start_cmd),
                                               str(stop_cmd),
                                               [config['app_port']], env_vars,
                                               config['max_memory'])

    if not monit_interface.start(watch):
        logging.error("Unable to start application server with monit")
        return BAD_PID

    if not wait_on_app(int(config['app_port'])):
        logging.error("Application server did not come up in time, " + \
                       "removing monit watch")
        monit_interface.stop(watch)
        return BAD_PID

    return 0
示例#8
0
                   "--concurrency=" + str(TaskQueueConfig.CELERY_CONCURRENCY),
                   "--soft-time-limit=" + str(self.TASK_SOFT_TIME_LIMIT),
                   "--pidfile=" + self.PID_FILE_LOC + 'celery___' + \
                                 app_id + ".pid",
                   "--statedb=" + TaskQueueConfig.CELERY_STATE_DIR + 'worker___' + \
                                 app_id + ".db",
                   "--autoreload -Ofair"]
        start_command = str(' '.join(command))
        stop_command = self.get_worker_stop_command(app_id)
        watch = "celery-" + str(app_id)
        monit_app_configuration.create_config_file(
            watch,
            start_command,
            stop_command, [self.CELERY_PORT],
            env_vars=self.CELERY_ENV_VARS)
        if monit_interface.start(watch):
            json_response = {'error': False}
        else:
            json_response = {
                'error': True,
                'reason': "Start of monit watch for %s failed" % watch
            }
        return json.dumps(json_response)

    def fetch_queue_stats(self, app_id, http_data):
        """ Gets statistics about tasks in queues.

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.
    Returns:
示例#9
0
def start_app(config):
    """ Starts a Google App Engine application on this machine. It
      will start it up and then proceed to fetch the main page.

  Args:
    config: a dictionary that contains
       app_name: Name of the application to start
       app_port: Port to start on
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       xmpp_ip: IP of XMPP service
       env_vars: A dict of environment variables that should be passed to the
        app.
       max_memory: An int that names the maximum amount of memory that this
        App Engine app is allowed to consume before being restarted.
       syslog_server: The IP of the syslog server to send the application
         logs to. Usually it's the login private IP.
  Returns:
    PID of process on success, -1 otherwise
  """
    config = convert_config_from_json(config)
    if config is None:
        logging.error("Invalid configuration for application")
        return BAD_PID

    if not misc.is_app_name_valid(config['app_name']):
        logging.error("Invalid app name for application: " +
                      config['app_name'])
        return BAD_PID
    logging.info("Starting %s application %s" %
                 (config['language'], config['app_name']))

    env_vars = config['env_vars']
    env_vars['GOPATH'] = '/root/appscale/AppServer/gopath/'
    env_vars['GOROOT'] = '/root/appscale/AppServer/goroot/'
    watch = "app___" + config['app_name']
    match_cmd = ""

    if config['language'] == constants.PYTHON27 or \
        config['language'] == constants.GO or \
        config['language'] == constants.PHP:
        start_cmd = create_python27_start_cmd(config['app_name'],
                                              config['load_balancer_ip'],
                                              config['app_port'],
                                              config['load_balancer_ip'],
                                              config['xmpp_ip'])
        stop_cmd = create_python27_stop_cmd(config['app_port'])
        env_vars.update(
            create_python_app_env(config['load_balancer_ip'],
                                  config['app_name']))
    elif config['language'] == constants.JAVA:
        remove_conflicting_jars(config['app_name'])
        copy_successful = copy_modified_jars(config['app_name'])
        if not copy_successful:
            return BAD_PID

        # Account for MaxPermSize (~170MB), the parent process (~50MB), and thread
        # stacks (~20MB).
        max_heap = config['max_memory'] - 250
        if max_heap <= 0:
            return BAD_PID
        start_cmd = create_java_start_cmd(config['app_name'],
                                          config['app_port'],
                                          config['load_balancer_ip'], max_heap)
        match_cmd = "java -ea -cp.*--port={}.*{}".format(
            str(config['app_port']),
            os.path.dirname(
                locate_dir("/var/apps/" + config['app_name'] + "/app/",
                           "WEB-INF")))

        stop_cmd = create_java_stop_cmd(config['app_port'])
        env_vars.update(create_java_app_env(config['app_name']))
    else:
        logging.error("Unknown application language %s for appname %s" \
          % (config['language'], config['app_name']))
        return BAD_PID

    logging.info("Start command: " + str(start_cmd))
    logging.info("Stop command: " + str(stop_cmd))
    logging.info("Environment variables: " + str(env_vars))

    # Set the syslog_server is specified.
    syslog_server = ""
    if 'syslog_server' in config:
        syslog_server = config['syslog_server']
    monit_app_configuration.create_config_file(str(watch),
                                               str(start_cmd),
                                               str(stop_cmd),
                                               [config['app_port']],
                                               env_vars,
                                               config['max_memory'],
                                               syslog_server,
                                               appscale_info.get_private_ip(),
                                               match_cmd=match_cmd)

    # We want to tell monit to start the single process instead of the
    # group, since monit can get slow if there are quite a few processes in
    # the same group.
    full_watch = "{}-{}".format(str(watch), str(config['app_port']))
    if not monit_interface.start(full_watch, is_group=False):
        logging.warning("Monit was unable to start {}:{}".format(
            str(config['app_name']), config['app_port']))
        return BAD_PID

    # Since we are going to wait, possibly for a long time for the
    # application to be ready, we do it in a thread.
    threading.Thread(target=add_routing,
                     args=(config['app_name'], config['app_port'])).start()

    if 'log_size' in config.keys():
        log_size = config['log_size']
    else:
        if config['app_name'] == APPSCALE_DASHBOARD_ID:
            log_size = DASHBOARD_LOG_SIZE
        else:
            log_size = APP_LOG_SIZE

    if not setup_logrotate(config['app_name'], watch, log_size):
        logging.error(
            "Error while setting up log rotation for application: {}".format(
                config['app_name']))

    return 0
示例#10
0
               "--concurrency=" + str(TaskQueueConfig.CELERY_CONCURRENCY),
               "--soft-time-limit=" + str(self.TASK_SOFT_TIME_LIMIT),
               "--pidfile=" + self.PID_FILE_LOC + 'celery___' + \
                             app_id + ".pid",
               "--statedb=" + TaskQueueConfig.CELERY_STATE_DIR + 'worker___' + \
                             app_id + ".db",
               "--autoreload"]
    start_command = str(' '.join(command))
    stop_command = self.get_worker_stop_command(app_id)
    watch = "celery-" + str(app_id)
    monit_app_configuration.create_config_file(watch,
                                               start_command, 
                                               stop_command, 
                                               [self.CELERY_PORT],
                                               env_vars=self.CELERY_ENV_VARS)
    if monit_interface.start(watch):
      json_response = {'error': False}
    else:
      json_response = {'error': True, 
                       'reason': "Start of monit watch for %s failed" % watch}
    return json.dumps(json_response)

  def fetch_queue_stats(self, app_id, http_data):
    """ Gets statistics about tasks in queues.

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.
    Returns:
      A tuple of a encoded response, error code, and error detail.
    """
示例#11
0
def start_app(config):
    """ Starts a Google App Engine application on this machine. It
      will start it up and then proceed to fetch the main page.

  Args:
    config: a dictionary that contains
       app_name: Name of the application to start
       app_port: Port to start on
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       xmpp_ip: IP of XMPP service
       env_vars: A dict of environment variables that should be passed to the
        app.
       max_memory: An int that names the maximum amount of memory that this
        App Engine app is allowed to consume before being restarted.
       syslog_server: The IP of the syslog server to send the application
         logs to. Usually it's the login private IP.
  Returns:
    PID of process on success, -1 otherwise
  """
    config = convert_config_from_json(config)
    if config is None:
        logging.error("Invalid configuration for application")
        return BAD_PID

    if not misc.is_app_name_valid(config['app_name']):
        logging.error("Invalid app name for application: " +
                      config['app_name'])
        return BAD_PID
    logging.info("Starting %s application %s" %
                 (config['language'], config['app_name']))

    env_vars = config['env_vars']
    env_vars['GOPATH'] = '/root/appscale/AppServer/gopath/'
    env_vars['GOROOT'] = '/root/appscale/AppServer/goroot/'
    watch = "app___" + config['app_name']

    if config['language'] == constants.PYTHON27 or \
        config['language'] == constants.GO or \
        config['language'] == constants.PHP:
        start_cmd = create_python27_start_cmd(config['app_name'],
                                              config['load_balancer_ip'],
                                              config['app_port'],
                                              config['load_balancer_ip'],
                                              config['xmpp_ip'])
        stop_cmd = create_python27_stop_cmd(config['app_port'])
        env_vars.update(
            create_python_app_env(config['load_balancer_ip'],
                                  config['app_name']))
    elif config['language'] == constants.JAVA:
        remove_conflicting_jars(config['app_name'])
        copy_successful = copy_modified_jars(config['app_name'])
        if not copy_successful:
            return BAD_PID
        start_cmd = create_java_start_cmd(config['app_name'],
                                          config['app_port'],
                                          config['load_balancer_ip'])
        stop_cmd = create_java_stop_cmd(config['app_port'])
        env_vars.update(create_java_app_env(config['app_name']))
    else:
        logging.error("Unknown application language %s for appname %s" \
          % (config['language'], config['app_name']))
        return BAD_PID

    logging.info("Start command: " + str(start_cmd))
    logging.info("Stop command: " + str(stop_cmd))
    logging.info("Environment variables: " + str(env_vars))

    # Set the syslog_server is specified.
    syslog_server = ""
    if 'syslog_server' in config:
        syslog_server = config['syslog_server']
    monit_app_configuration.create_config_file(str(watch), str(start_cmd),
                                               str(stop_cmd),
                                               [config['app_port']], env_vars,
                                               config['max_memory'],
                                               syslog_server,
                                               appscale_info.get_private_ip())

    if not monit_interface.start(watch):
        logging.error("Unable to start application server with monit")
        return BAD_PID

    if not wait_on_app(int(config['app_port'])):
        logging.error("Application server did not come up in time, "
                      "removing monit watch")
        monit_interface.stop(watch)
        return BAD_PID

    threading.Thread(target=add_routing,
                     args=(config['app_name'], config['app_port'])).start()

    if 'log_size' in config.keys():
        log_size = config['log_size']
    else:
        if config['app_name'] == APPSCALE_DASHBOARD_ID:
            log_size = DASHBOARD_LOG_SIZE
        else:
            log_size = APP_LOG_SIZE

    if not setup_logrotate(config['app_name'], watch, log_size):
        logging.error(
            "Error while setting up log rotation for application: {}".format(
                config['app_name']))

    return 0
示例#12
0
def run():
    """ Starts up cassandra. """
    logging.warning("Starting Cassandra.")
    monit_interface.start(cassandra_interface.CASSANDRA_MONIT_WATCH_NAME,
                          is_group=False)
    logging.warning("Done!")
示例#13
0
def start_app(config):
  """ Starts a Google App Engine application on this machine. It
      will start it up and then proceed to fetch the main page.

  Args:
    config: a dictionary that contains
       app_name: Name of the application to start
       app_port: Port to start on
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       xmpp_ip: IP of XMPP service
       env_vars: A dict of environment variables that should be passed to the
        app.
       max_memory: An int that names the maximum amount of memory that this
        App Engine app is allowed to consume before being restarted.
       syslog_server: The IP of the syslog server to send the application
         logs to. Usually it's the login private IP.
  Returns:
    PID of process on success, -1 otherwise
  """
  config = convert_config_from_json(config)
  if config is None:
    logging.error("Invalid configuration for application")
    return BAD_PID

  if not misc.is_app_name_valid(config['app_name']):
    logging.error("Invalid app name for application: " + config['app_name'])
    return BAD_PID
  logging.info("Starting %s application %s" % (
    config['language'], config['app_name']))

  env_vars = config['env_vars']
  env_vars['GOPATH'] = '/root/appscale/AppServer/gopath/'
  env_vars['GOROOT'] = '/root/appscale/AppServer/goroot/'
  watch = "app___" + config['app_name']
  match_cmd = ""

  if config['language'] == constants.PYTHON27 or \
      config['language'] == constants.GO or \
      config['language'] == constants.PHP:
    start_cmd = create_python27_start_cmd(
      config['app_name'],
      config['load_balancer_ip'],
      config['app_port'],
      config['load_balancer_ip'],
      config['xmpp_ip'])
    stop_cmd = create_python27_stop_cmd(config['app_port'])
    env_vars.update(create_python_app_env(
      config['load_balancer_ip'],
      config['app_name']))
  elif config['language'] == constants.JAVA:
    remove_conflicting_jars(config['app_name'])
    copy_successful = copy_modified_jars(config['app_name'])
    if not copy_successful:
      return BAD_PID

    # Account for MaxPermSize (~170MB), the parent process (~50MB), and thread
    # stacks (~20MB).
    max_heap = config['max_memory'] - 250
    if max_heap <= 0:
      return BAD_PID
    start_cmd = create_java_start_cmd(
      config['app_name'],
      config['app_port'],
      config['load_balancer_ip'],
      max_heap
    )
    match_cmd = "java -ea -cp.*--port={}.*{}".format(str(config['app_port']),
      os.path.dirname(locate_dir("/var/apps/" + config['app_name'] + "/app/",
      "WEB-INF")))

    stop_cmd = create_java_stop_cmd(config['app_port'])
    env_vars.update(create_java_app_env(config['app_name']))
  else:
    logging.error("Unknown application language %s for appname %s" \
      % (config['language'], config['app_name']))
    return BAD_PID

  logging.info("Start command: " + str(start_cmd))
  logging.info("Stop command: " + str(stop_cmd))
  logging.info("Environment variables: " + str(env_vars))

  # Set the syslog_server is specified.
  syslog_server = ""
  if 'syslog_server' in config:
    syslog_server = config['syslog_server']
  monit_app_configuration.create_config_file(
    str(watch),
    str(start_cmd),
    str(stop_cmd),
    [config['app_port']],
    env_vars,
    config['max_memory'],
    syslog_server,
    appscale_info.get_private_ip(),
    match_cmd=match_cmd)

  # We want to tell monit to start the single process instead of the
  # group, since monit can get slow if there are quite a few processes in
  # the same group.
  full_watch = "{}-{}".format(str(watch), str(config['app_port']))
  if not monit_interface.start(full_watch, is_group=False):
    logging.warning("Monit was unable to start {}:{}".
      format(str(config['app_name']), config['app_port']))
    return BAD_PID

  # Since we are going to wait, possibly for a long time for the
  # application to be ready, we do it in a thread.
  threading.Thread(target=add_routing,
    args=(config['app_name'], config['app_port'])).start()

  if 'log_size' in config.keys():
    log_size = config['log_size']
  else:
    if config['app_name'] == APPSCALE_DASHBOARD_ID:
      log_size = DASHBOARD_LOG_SIZE
    else:
      log_size = APP_LOG_SIZE

  if not setup_logrotate(config['app_name'], watch, log_size):
    logging.error("Error while setting up log rotation for application: {}".
      format(config['app_name']))

  return 0
示例#14
0
def run(): 
  """ Starts up cassandra. """ 
  logging.warning("Starting Zookeeper.")
  monit_interface.start('zookeeper-9999', is_group=False)
  logging.warning("Done!") 
示例#15
0
def start_app(config):
  """ Starts a Google App Engine application on this machine. It
      will start it up and then proceed to fetch the main page.

  Args:
    config: a dictionary that contains
       app_name: Name of the application to start
       app_port: Port to start on
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       xmpp_ip: IP of XMPP service
       env_vars: A dict of environment variables that should be passed to the
        app.
       max_memory: An int that names the maximum amount of memory that this
        App Engine app is allowed to consume before being restarted.
       syslog_server: The IP of the syslog server to send the application
         logs to. Usually it's the login private IP.
  Returns:
    PID of process on success, -1 otherwise
  """
  config = convert_config_from_json(config)
  if config == None:
    logging.error("Invalid configuration for application")
    return BAD_PID

  if not misc.is_app_name_valid(config['app_name']):
    logging.error("Invalid app name for application: " + config['app_name'])
    return BAD_PID
  logging.info("Starting %s application %s" % (
    config['language'], config['app_name']))

  env_vars = config['env_vars']
  env_vars['GOPATH'] = '/var/lib/appscale/AppServer/gopath/'
  env_vars['GOROOT'] = '/var/lib/appscale/AppServer/goroot/'
  watch = "app___" + config['app_name']

  if config['language'] == constants.PYTHON27 or \
      config['language'] == constants.GO or \
      config['language'] == constants.PHP:
    start_cmd = create_python27_start_cmd(
      config['app_name'],
      config['load_balancer_ip'],
      config['app_port'],
      config['load_balancer_ip'],
      config['xmpp_ip'])
    stop_cmd = create_python27_stop_cmd(config['app_port'])
    env_vars.update(create_python_app_env(
      config['load_balancer_ip'],
      config['app_name']))
  elif config['language'] == constants.JAVA:
    remove_conflicting_jars(config['app_name'])
    copy_successful = copy_modified_jars(config['app_name'])
    if not copy_successful:
      return BAD_PID
    start_cmd = create_java_start_cmd(
      config['app_name'],
      config['app_port'],
      config['load_balancer_ip'])
    stop_cmd = create_java_stop_cmd(config['app_port'])
    env_vars.update(create_java_app_env(config['app_name']))
  else:
    logging.error("Unknown application language %s for appname %s" \
      % (config['language'], config['app_name']))
    return BAD_PID

  logging.info("Start command: " + str(start_cmd))
  logging.info("Stop command: " + str(stop_cmd))
  logging.info("Environment variables: " + str(env_vars))

  # Set the syslog_server is specified.
  syslog_server = ""
  if 'syslog_server' in config:
    syslog_server = config['syslog_server']
  monit_app_configuration.create_config_file(
    str(watch),
    str(start_cmd),
    str(stop_cmd),
    [config['app_port']],
    env_vars,
    config['max_memory'],
    syslog_server,
    appscale_info.get_private_ip())

  if not monit_interface.start(watch):
    logging.error("Unable to start application server with monit")
    return BAD_PID

  if not wait_on_app(int(config['app_port'])):
    logging.error("Application server did not come up in time, "
      "removing monit watch")
    monit_interface.stop(watch)
    return BAD_PID

  threading.Thread(target=add_routing,
    args=(config['app_name'], config['app_port'])).start()

  if 'log_size' in config.keys():
    log_size = config['log_size']
  else:
    if config['app_name'] == APPSCALE_DASHBOARD_ID:
      log_size = DASHBOARD_LOG_SIZE
    else:
      log_size = APP_LOG_SIZE

  if not setup_logrotate(config['app_name'], watch, log_size):
    logging.error("Error while setting up log rotation for application: {}".
      format(config['app_name']))


  return 0
示例#16
0
def start_app(config):
  """ Starts a Google App Engine application on this machine. It
      will start it up and then proceed to fetch the main page.

  Args:
    config: a dictionary that contains
       app_name: Name of the application to start
       app_port: Port to start on
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       xmpp_ip: IP of XMPP service
       dblocations: List of database locations
       env_vars: A dict of environment variables that should be passed to the
        app.
       max_memory: An int that names the maximum amount of memory that this
        App Engine app is allowed to consume before being restarted.
  Returns:
    PID of process on success, -1 otherwise
  """
  config = convert_config_from_json(config)
  if config == None:
    logging.error("Invalid configuration for application")
    return BAD_PID

  if not misc.is_app_name_valid(config['app_name']):
    logging.error("Invalid app name for application: " +\
                  config['app_name'])
    return BAD_PID
  logging.info("Starting %s application %s"%(config['language'],
                                             config['app_name']))

  start_cmd = ""
  stop_cmd = ""
  env_vars = config['env_vars']
  env_vars['GOPATH'] = '/root/appscale/AppServer/gopath/'
  env_vars['GOROOT'] = '/root/appscale/AppServer/goroot/'
  watch = "app___" + config['app_name']

  if config['language'] == constants.PYTHON27 or \
       config['language'] == constants.GO or \
       config['language'] == constants.PHP:
    start_cmd = create_python27_start_cmd(config['app_name'],
                            config['load_balancer_ip'],
                            config['app_port'],
                            config['load_balancer_ip'],
                            config['xmpp_ip'])
    logging.info(start_cmd)
    stop_cmd = create_python27_stop_cmd(config['app_port'])
    env_vars.update(create_python_app_env(config['load_balancer_ip'],
                            config['app_name']))
  elif config['language'] == constants.JAVA:
    remove_conflicting_jars(config['app_name'])
    copy_successful = copy_modified_jars(config['app_name'])
    if not copy_successful:
      return BAD_PID
    start_cmd = create_java_start_cmd(config['app_name'],
                            config['app_port'],
                            config['load_balancer_ip'])
    stop_cmd = create_java_stop_cmd(config['app_port'])
    env_vars.update(create_java_app_env())
  else:
    logging.error("Unknown application language %s for appname %s"\
                  %(config['language'], config['app_name']))
    return BAD_PID

  logging.info("Start command: " + str(start_cmd))
  logging.info("Stop command: " + str(stop_cmd))
  logging.info("Environment variables: " +str(env_vars))

  monit_app_configuration.create_config_file(str(watch),
                                             str(start_cmd),
                                             str(stop_cmd),
                                             [config['app_port']],
                                             env_vars,
                                             config['max_memory'])

  if not monit_interface.start(watch):
    logging.error("Unable to start application server with monit")
    return BAD_PID

  if not wait_on_app(int(config['app_port'])):
    logging.error("Application server did not come up in time, " + \
                   "removing monit watch")
    monit_interface.stop(watch)
    return BAD_PID

  return 0
def run():
    """ Starts up cassandra. """
    logging.warning("Starting Zookeeper.")
    monit_interface.start('zookeeper-9999', is_group=False)
    logging.warning("Done!")