AppController/djinn.rb
# Starts all of the services that this node has been assigned to run.
# Also starts all services that all nodes run in an AppScale deployment.
Starts all of the services that this node has been assigned to run.
Also starts all services that all nodes run in an AppScale deployment.
Starts all of the services that this node has been assigned to run . Also starts all services that all nodes run in an AppScale deployment .
def start_api_services()
    @state = "Starting API Services."
    Djinn.log_info("#{@state}")
    threads = []
    threads << Thread.new {
      if not is_zookeeper_running?
        if my_node.is_zookeeper?
          configure_zookeeper(@nodes, @my_index)
          begin
            start_zookeeper(@options['clear_datastore'].downcase == "true")
          rescue FailedZooKeeperOperationException
            @state = "Couldn't start Zookeeper."
            HelperFunctions.log_and_crash(@state, WAIT_TO_CRASH)
          end
          Djinn.log_info("Done configuring zookeeper.")
        end
      else
        Djinn.log_info("Zookeeper already running.")
      end
    }
    if my_node.is_db_master? or my_node.is_db_slave?
      threads << Thread.new {
        Djinn.log_info("Starting database services.")
        clear_datastore = @options['clear_datastore'].downcase == "true"
        db_nodes = @nodes.count{|node| node.is_db_master? or node.is_db_slave?}
        needed_nodes = needed_for_quorum(db_nodes,
                                         Integer(@options['replication']))
        if my_node.is_db_master?
          start_db_master(clear_datastore, needed_nodes)
          prime_database
        else
          start_db_slave(clear_datastore, needed_nodes)
        end
      }
    end
    Djinn.log_info("Waiting for DB services ... ")
    threads.each { |t| t.join() }
    Djinn.log_info('Ensuring necessary database tables are present')
    sleep(SMALL_WAIT) until system("#{PRIME_SCRIPT} --check > /dev/null 2>&1")
    Djinn.log_info('Ensuring data layout version is correct')
    layout_script = "#{APPSCALE_HOME}/AppDB/scripts/appscale-data-layout"
    unless system("#{layout_script} --db-type cassandra > /dev/null 2>&1")
      HelperFunctions.log_and_crash(
        'Unexpected data layout version. Please run "appscale upgrade".')
    end
    if my_node.is_db_master? or my_node.is_db_slave?
      @state = "Starting up SOAP Server and Datastore Server"
      start_datastore_server()
      start_soap_server()
      Djinn.log_info("Done starting database services.")
    end
    HelperFunctions.sleep_until_port_is_open(@my_private_ip,
      UserAppClient::SSL_SERVER_PORT, USE_SSL)
    uac = UserAppClient.new(@my_private_ip, @@secret)
    begin
      uac.does_app_exist?("not-there")
    rescue FailedNodeException
      Djinn.log_debug("UserAppServer not ready yet: retrying.")
      retry
    end
    @done_initializing = true
    Djinn.log_info("UserAppServer is ready.")
    threads = []
    if my_node.is_db_master? or my_node.is_db_slave? or my_node.is_zookeeper?
      threads << Thread.new {
        if my_node.is_db_master?
          if @options['clear_datastore'].downcase == "true"
            erase_app_instance_info
          end
        end
        if my_node.is_db_master? or my_node.is_db_slave?
          start_groomer_service()
        end
        start_backup_service()
      }
    end
    if my_node.is_memcache?
      threads << Thread.new {
        start_memcache()
      }
    end
    if my_node.is_load_balancer?
      threads << Thread.new {
        start_ejabberd()
        configure_tq_routing()
      }
    end
    if my_node.is_shadow?
      threads << Thread.new {
        create_appscale_user()
        prep_app_dashboard()
      }
    end
    threads << Thread.new {
      start_app_manager_server()
    }
    if my_node.is_appengine?
      threads << Thread.new {
        start_blobstore_server()
      }
    end
    if my_node.is_search?
      threads << Thread.new {
        start_search_role()
      }
    end
    if my_node.is_taskqueue_master?
      threads << Thread.new {
        start_taskqueue_master()
      }
    elsif my_node.is_taskqueue_slave?
      threads << Thread.new {
        start_taskqueue_slave()
      }
    end
    Djinn.log_info("Waiting for all services to finish starting up")
    threads.each { |t| t.join() }
    Djinn.log_info("API services have started on this node")
    if my_node.is_shadow?
      update_node_info_cache()
      start_hermes()
      TaskQueue.start_flower(@options['flower_password'])
    end
  end
def start_api_services ( ) @state = "Starting API Services." Djinn . log_info ( "#{@state}" ) threads = [ ] threads << Thread . new { if not is_zookeeper_running? if my_node . is_zookeeper? configure_zookeeper ( @nodes , @my_index ) begin start_zookeeper ( @options [ 'clear_datastore' ] . downcase == "true" ) rescue FailedZooKeeperOperationException @state = "Couldn't start Zookeeper." HelperFunctions . log_and_crash ( @state , WAIT_TO_CRASH ) end Djinn . log_info ( "Done configuring zookeeper." ) end else Djinn . log_info ( "Zookeeper already running." ) end } if my_node . is_db_master? or my_node . is_db_slave? threads << Thread . new { Djinn . log_info ( "Starting database services." ) clear_datastore = @options [ 'clear_datastore' ] . downcase == "true" db_nodes = @nodes . count { | node | node . is_db_master? or node . is_db_slave? } needed_nodes = needed_for_quorum ( db_nodes , Integer ( @options [ 'replication' ] ) ) if my_node . is_db_master? start_db_master ( clear_datastore , needed_nodes ) prime_database else start_db_slave ( clear_datastore , needed_nodes ) end } end Djinn . log_info ( "Waiting for DB services ... " ) threads . each { | t | t . join ( ) } Djinn . log_info ( 'Ensuring necessary database tables are present' ) sleep ( SMALL_WAIT ) until system ( "#{PRIME_SCRIPT} --check > /dev/null 2>&1" ) Djinn . log_info ( 'Ensuring data layout version is correct' ) layout_script = "#{APPSCALE_HOME}/AppDB/scripts/appscale-data-layout" unless system ( "#{layout_script} --db-type cassandra > /dev/null 2>&1" ) HelperFunctions . log_and_crash ( 'Unexpected data layout version. Please run "appscale upgrade".' ) end if my_node . is_db_master? or my_node . is_db_slave? @state = "Starting up SOAP Server and Datastore Server" start_datastore_server ( ) start_soap_server ( ) Djinn . log_info ( "Done starting database services." ) end HelperFunctions . sleep_until_port_is_open ( @my_private_ip , UserAppClient :: SSL_SERVER_PORT , USE_SSL ) uac = UserAppClient . new ( @my_private_ip , @@secret ) begin uac . does_app_exist? ( "not-there" ) rescue FailedNodeException Djinn . log_debug ( "UserAppServer not ready yet: retrying." ) retry end @done_initializing = true Djinn . log_info ( "UserAppServer is ready." ) threads = [ ] if my_node . is_db_master? or my_node . is_db_slave? or my_node . is_zookeeper? threads << Thread . new { if my_node . is_db_master? if @options [ 'clear_datastore' ] . downcase == "true" erase_app_instance_info end end if my_node . is_db_master? or my_node . is_db_slave? start_groomer_service ( ) end start_backup_service ( ) } end if my_node . is_memcache? threads << Thread . new { start_memcache ( ) } end if my_node . is_load_balancer? threads << Thread . new { start_ejabberd ( ) configure_tq_routing ( ) } end if my_node . is_shadow? threads << Thread . new { create_appscale_user ( ) prep_app_dashboard ( ) } end threads << Thread . new { start_app_manager_server ( ) } if my_node . is_appengine? threads << Thread . new { start_blobstore_server ( ) } end if my_node . is_search? threads << Thread . new { start_search_role ( ) } end if my_node . is_taskqueue_master? threads << Thread . new { start_taskqueue_master ( ) } elsif my_node . is_taskqueue_slave? threads << Thread . new { start_taskqueue_slave ( ) } end Djinn . log_info ( "Waiting for all services to finish starting up" ) threads . each { | t | t . join ( ) } Djinn . log_info ( "API services have started on this node" ) if my_node . is_shadow? update_node_info_cache ( ) start_hermes ( ) TaskQueue . start_flower ( @options [ 'flower_password' ] ) end end
Starts all of the services that this node has been assigned to run.
Starts all of the services that this node has been assigned to run .
# We now wait for the essential services to go up. # Always colocate the Datastore Server and UserAppServer (soap_server). # Start the UserAppServer and wait till it's ready. # All nodes wait for the UserAppServer now. The call here is just to # ensure the UserAppServer is talking to the persistent state. # The services below depends directly or indirectly on the UAServer to # be operational. So we start them after we test the UAServer. # The headnode needs to ensure we have the appscale user, and it needs # to prepare the dashboard to be started. # App Engine apps rely on the above services to be started, so # join all our threads here # Leader node starts additional services.