Skip to content

Commit 433a0c5

Browse files
Merge pull request #20 from gabriel-samfira/add-systeminfo-callback
Add system-info callback
2 parents 893c93e + f5de9c2 commit 433a0c5

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

cloudconfig/templates.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,30 @@ function call() {
4747
curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || echo "failed to call home: exit code ($?)"
4848
}
4949
50+
function systemInfo() {
51+
if [ -f "/etc/os-release" ];then
52+
. /etc/os-release
53+
fi
54+
OS_NAME=${NAME:-""}
55+
OS_VERSION=${VERSION_ID:-""}
56+
AGENT_ID=${1:-null}
57+
# strip status from the callback url
58+
[[ $CALLBACK_URL =~ ^(.*)/status(/)?$ ]] && CALLBACK_URL="${BASH_REMATCH[1]}" || true
59+
SYSINFO_URL="${CALLBACK_URL}/system-info/"
60+
PAYLOAD="{\"os_name\": \"$OS_NAME\", \"os_version\": \"$OS_VERSION\", \"agent_id\": $AGENT_ID}"
61+
curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${SYSINFO_URL}" || true
62+
}
63+
5064
function sendStatus() {
5165
MSG="$1"
5266
call "{\"status\": \"installing\", \"message\": \"$MSG\"}"
5367
}
5468
55-
{{- if .UseJITConfig }}
5669
function success() {
5770
MSG="$1"
58-
call "{\"status\": \"idle\", \"message\": \"$MSG\"}"
59-
}
60-
{{- else}}
61-
function success() {
62-
MSG="$1"
63-
ID=$2
71+
ID=${2:-null}
6472
call "{\"status\": \"idle\", \"message\": \"$MSG\", \"agent_id\": $ID}"
6573
}
66-
{{- end}}
6774
6875
function fail() {
6976
MSG="$1"
@@ -199,9 +206,9 @@ if [ -e "/sys/fs/selinux" ];then
199206
sudo chcon -R -h {{ .RunnerUsername }}:object_r:bin_t /home/runner/* || fail "failed to change selinux context"
200207
fi
201208
209+
AGENT_ID=""
202210
{{- if .UseJITConfig }}
203211
sudo systemctl start $SVC_NAME || fail "failed to start service"
204-
success "runner successfully installed"
205212
{{- else}}
206213
sendStatus "starting service"
207214
sudo ./svc.sh start || fail "failed to start service"
@@ -212,8 +219,9 @@ if [ $? -ne 0 ];then
212219
fail "failed to get agent ID"
213220
fi
214221
set -e
215-
success "runner successfully installed" $AGENT_ID
216222
{{- end}}
223+
systemInfo $AGENT_ID
224+
success "runner successfully installed" $AGENT_ID
217225
`
218226

219227
var WindowsSetupScriptTemplate = `#ps1_sysnative

0 commit comments

Comments
 (0)