def order_services(running_services):
  """ Arranges a list of running services in the order they should be stopped.

  Args:
    running_services: A list of strings specifying running services.
  Returns:
    A tuple with two items. The first is a list of ordered services. The second
    is a list of remaining services that are not recognized.
  """
  service_order = [
    # First, stop the services that manage other services.
    'controller',
    'admin_server',
    'appmanagerserver',

    # Next, stop routing requests to running instances.
    'nginx',
    'app_haproxy',

    # Next, stop application runtime instances.
    'app___',
    'api-server_',

    # Next, stop services that depend on other services.
    'service_haproxy',
    'blobstore',
    'celery-',
    'flower',
    'groomer_service',
    'hermes',
    'iaas_manager',
    'log_service',
    'taskqueue-',
    'transaction_groomer',
    'uaserver',

    # Finally, stop the underlying backend services.
    'cassandra',
    'ejabberd',
    'memcached',
    'rabbitmq',
    'zookeeper'
  ]

  ordered_services = []
  for service_type in service_order:
    relevant_entries = [service for service in running_services
                        if service.startswith(service_type)]
    for entry in relevant_entries:
      index = running_services.index(entry)
      ordered_services.append(running_services.pop(index))

  return ordered_services, running_services