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

Side by Side 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: Rebased, updated from comments. 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/bin/bash
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 METADATA_URL="http://metadata.google.internal"
7
8 _help() {
9 echo -e "Usage: $0 <logdog-coordinator-path>"
10 echo -e ""
11 echo -e " logdog-coordinator-path\tThe path to the application binary."
12 }
13
14 APP=$1; shift
15 if [ -z "${APP}" ]; then
16 echo "ERROR: Missing argument <logdog-coordiantor-path>"
17 _help
18 exit 1
19 fi
20 APP=$(readlink -f "${APP}")
21 if [ ! -x "${APP}" ]; then
22 echo "ERROR: Application path is not an executable file [${APP}]"
23 exit 1
24 fi
25
26 _load_metadata_domain() {
27 local __resultvar=$1; shift
28 local domain=$1; shift
29 local resource=$1; shift
30
31 OUTPUT=$(curl \
32 -s \
33 --fail \
34 "${METADATA_URL}/computeMetadata/v1/${domain}/attributes/${resource}" \
35 -H "Metadata-Flavor: Google")
36 RV=$?
37 if [ ${RV} != 0 ]; then
38 return ${RV}
39 fi
40 if [ -z "${OUTPUT}" ]; then
41 return 1
42 fi
43
44 eval $__resultvar="'${OUTPUT}'"
45 }
46
47 # Loads metadata from the GCE metadata server.
48 _load_metadata() {
49 local __resultvar=$1; shift
50 local resource=$1; shift
51
52 # Try loading from 'instance' domain.
53 _load_metadata_domain "$__resultvar" "instance" "$resource"
54 if [ $? == 0 ]; then
55 return 0
56 fi
57
58 # Try loading from 'project' domain.
59 _load_metadata_domain "$__resultvar" "project" "$resource"
60 if [ $? == 0 ]; then
61 return 0
62 fi
63
64 echo "WARN: Failed to load metadata [${resource}]."
65 return 1
66 }
67
68 _load_metadata_check() {
69 local __resultvar=$1; shift
70 local resource=$1; shift
71
72 _load_metadata "$__resultvar" "$resource"
73 if [ $? != 0 ]; then
74 echo "ERROR: Metadata resource [${resource}] is required."
75 exit 1
76 fi
77
78 return 0
79 }
80
81 _write_credentials() {
82 local path=$1; shift
83 local data=$1; shift
84 echo "${data}" > "${path}"
85 }
86
87 # Test if we're running on a GCE instance.
88 curl \
89 -s \
90 --fail \
91 "${METADATA_URL}" \
92 1>/dev/null
93 if [ $? != 0 ]; then
94 echo "ERROR: Not running on GCE instance."
95 exit 1
96 fi
97
98 # Load metadata.
99 _load_metadata_check COORDINATOR_URL "logdog_coordinator_url"
100
101 _load_metadata LOG_LEVEL "logdog_collector_log_level"
102 _load_metadata STORAGE_CREDENTIALS "logdog_collector_storage_auth_json"
103
104 # Runtime temporary directory.
105 TEMPDIR=$(mktemp -d)
106 trap "rm -rf ${TEMPDIR}" EXIT
107
108 # Compose command line.
109 ARGS=(
110 "-coordinator-url" "${COORDINATOR_URL}"
111 )
112
113 if [ ! -z "${LOG_LEVEL}" ]; then
114 ARGS+=("-log_level" "${LOG_LEVEL}")
115 fi
116 if [ ! -z "${STORAGE_CREDENTIALS}" ]; then
117 STORAGE_CREDENTIALS_JSON_PATH="${TEMPDIR}/storage_service_account_json.json"
118 _write_credentials "${STORAGE_CREDENTIALS_JSON_PATH}" "${STORAGE_CREDENT IALS}"
119 ARGS+=("-storage-credential-json-path" "${STORAGE_CREDENTIALS_JSON_PATH}")
120 fi
121
122 echo "INFO: Running command line args: ${APP} ${ARGS[*]}"
123 "${APP}" ${ARGS[*]}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698