Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Unified Diff: server/cmd/logdog_collector/run.sh

Issue 1610993002: LogDog: Add collector service implementation. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Post-splitting rebase. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: server/cmd/logdog_collector/run.sh
diff --git a/server/cmd/logdog_collector/run.sh b/server/cmd/logdog_collector/run.sh
new file mode 100755
index 0000000000000000000000000000000000000000..9530a720152a63a0084c48d85c34b10b9c92856f
--- /dev/null
+++ b/server/cmd/logdog_collector/run.sh
@@ -0,0 +1,123 @@
+#!/bin/bash
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+METADATA_URL="http://metadata.google.internal"
+
+_help() {
+ echo -e "Usage: $0 <logdog-coordinator-path>"
+ echo -e ""
+ echo -e " logdog-coordinator-path\tThe path to the application binary."
+}
+
+APP=$1; shift
+if [ -z "${APP}" ]; then
+ echo "ERROR: Missing argument <logdog-coordiantor-path>"
+ _help
+ exit 1
+fi
+APP=$(readlink -f "${APP}")
+if [ ! -x "${APP}" ]; then
+ echo "ERROR: Application path is not an executable file [${APP}]"
+ exit 1
+fi
+
+_load_metadata_domain() {
+ local __resultvar=$1; shift
+ local domain=$1; shift
+ local resource=$1; shift
+
+ OUTPUT=$(curl \
+ -s \
+ --fail \
+ "${METADATA_URL}/computeMetadata/v1/${domain}/attributes/${resource}" \
+ -H "Metadata-Flavor: Google")
+ RV=$?
+ if [ ${RV} != 0 ]; then
+ return ${RV}
+ fi
+ if [ -z "${OUTPUT}" ]; then
+ return 1
+ fi
+
+ eval $__resultvar="'${OUTPUT}'"
+}
+
+# Loads metadata from the GCE metadata server.
+_load_metadata() {
+ local __resultvar=$1; shift
+ local resource=$1; shift
+
+ # Try loading from 'instance' domain.
+ _load_metadata_domain "$__resultvar" "instance" "$resource"
+ if [ $? == 0 ]; then
+ return 0
+ fi
+
+ # Try loading from 'project' domain.
+ _load_metadata_domain "$__resultvar" "project" "$resource"
+ if [ $? == 0 ]; then
+ return 0
+ fi
+
+ echo "WARN: Failed to load metadata [${resource}]."
+ return 1
+}
+
+_load_metadata_check() {
+ local __resultvar=$1; shift
+ local resource=$1; shift
+
+ _load_metadata "$__resultvar" "$resource"
+ if [ $? != 0 ]; then
+ echo "ERROR: Metadata resource [${resource}] is required."
+ exit 1
+ fi
+
+ return 0
+}
+
+_write_credentials() {
+ local path=$1; shift
+ local data=$1; shift
+ echo "${data}" > "${path}"
+}
+
+# Test if we're running on a GCE instance.
+curl \
+ -s \
+ --fail \
+ "${METADATA_URL}" \
+ 1>/dev/null
+if [ $? != 0 ]; then
+ echo "ERROR: Not running on GCE instance."
+ exit 1
+fi
+
+# Load metadata.
+_load_metadata_check COORDINATOR_URL "logdog_coordinator_url"
+
+_load_metadata LOG_LEVEL "logdog_collector_log_level"
+_load_metadata STORAGE_CREDENTIALS "logdog_collector_storage_auth_json"
+
+# Runtime temporary directory.
+TEMPDIR=$(mktemp -d)
+trap "rm -rf ${TEMPDIR}" EXIT
+
+# Compose command line.
+ARGS=(
+ "-coordinator-url" "${COORDINATOR_URL}"
+ )
+
+if [ ! -z "${LOG_LEVEL}" ]; then
+ ARGS+=("-log_level" "${LOG_LEVEL}")
+fi
+if [ ! -z "${STORAGE_CREDENTIALS}" ]; then
+ STORAGE_CREDENTIALS_JSON_PATH="${TEMPDIR}/storage_service_account_json.json"
+ _write_credentials "${STORAGE_CREDENTIALS_JSON_PATH}" "${STORAGE_CREDENTIALS}"
+ ARGS+=("-storage-credential-json-path" "${STORAGE_CREDENTIALS_JSON_PATH}")
+fi
+
+echo "INFO: Running command line args: ${APP} ${ARGS[*]}"
+"${APP}" ${ARGS[*]}

Powered by Google App Engine
This is Rietveld 408576698