@@ -126,6 +126,7 @@ log_date() { #{{{
126
126
127
127
err () { #{{{
128
128
printf " %s ${C_RED_BOLD} ERROR: ${C_RESET} %s${C_BOLD} %s${C_RESET} %s\n" " $( log_date) " " ${1} " " ${2} " " ${@: 3} " >&2
129
+ update_runner_group " ${1} ${2} ${@: 3} "
129
130
}
130
131
# }}}: err
131
132
@@ -135,6 +136,7 @@ log_err() { #{{{
135
136
msg=" $( tail -n1 " $LOG_FILE " | cut -d" :" -f2-) "
136
137
err=" $( tail -n1 " $LOG_FILE " | cut -d" :" -f1) "
137
138
printf " %s ${C_RED_BOLD} ERROR: ${C_RESET} %s${C_BOLD} %s${C_RESET} \n" " $( log_date) " " $err " " $msg " >&2
139
+ update_runner_group " ${err} ${msg} "
138
140
}
139
141
# }}}: log_err
140
142
@@ -491,18 +493,34 @@ cgroupsv2() { #{{{
491
493
}
492
494
# }}}: cgroupsv2
493
495
496
+ update_runner_group (){
497
+ url=" ${SG_BASE_API} /orgs/${ORGANIZATION_ID} /runnergroups/${RUNNER_GROUP_ID} /"
498
+
499
+ err_msg=$( echo -n " $1 " | tr -cd " [:print:]" )
500
+
501
+ debug " Error message ${err_msg} "
502
+
503
+ payload=" { \" RunnerRegistrationErrors\" : { \" $( ip route | grep default | cut -d" " -f9) \" : { \" RunnerId\" : \" ${RUNNER_ID} \" , \" error\" : \" ${err_msg} \" , \" timestamp\" : \" $( date -u -Iseconds ) \" , \" command\" : \" ${0} ${@ } \" } } }"
504
+
505
+ if api_call " PATCH" " $payload " ; then
506
+ debug " updated runner group with error msg"
507
+ else
508
+ debug " failed to update runner group with error msg"
509
+ fi
510
+ }
511
+
494
512
api_call () { #{{{
495
513
# TODO: Support draining of instance
496
- if [[ -n " $1 " ]]; then
514
+ if [[ -n " $2 " ]]; then
497
515
response=$( curl --max-time 10 -i -s \
498
- -X POST \
516
+ -X " $1 " \
499
517
-H " Authorization: apikey ${SG_NODE_TOKEN} " \
500
518
-H " Content-Type: application/json" \
501
- -d " $1 " \
519
+ -d " $2 " \
502
520
" ${url} " )
503
521
else
504
522
response=$( curl --max-time 10 -i -s \
505
- -X POST \
523
+ -X " $1 " \
506
524
-H " Authorization: apikey ${SG_NODE_TOKEN} " \
507
525
-H " Content-Type: application/json" \
508
526
" ${url} " )
@@ -694,6 +712,8 @@ clean_local_setup() { #{{{
694
712
695
713
clean_cron
696
714
715
+ [[ -e " /tmp/env_variables.sh" ]] && source /tmp/env_variables.sh || :
716
+
697
717
# Wait for AWS SSM Managed Instance to deregister on AWS side
698
718
sleep 10s
699
719
@@ -998,7 +1018,7 @@ fetch_organization_info() { #{{{
998
1018
999
1019
debug " Calling URL:" " ${url} "
1000
1020
1001
- if api_call; then
1021
+ if api_call " POST " ; then
1002
1022
spinner_msg " Trying to fetch registration data" 0
1003
1023
spinner_wait " Preparing environment.."
1004
1024
metadata=" $( echo " ${response} " | jq -r ' .data.RegistrationMetadata[0]' ) "
@@ -1310,7 +1330,7 @@ deregister_instance() { #{{{
1310
1330
1311
1331
spinner_wait " Trying to deregister instance.."
1312
1332
if [[ " $LOG_DEBUG " =~ true| True ]]; then printf " \n" ; fi
1313
- if api_call " $payload " ; then
1333
+ if api_call " POST " " $payload " ; then
1314
1334
spinner_msg " Trying to deregister instance" 0
1315
1335
# if deregister_ssm_instance_response is [], remove /var/lib/amazon/ssm dir as the MI does not exist anymore, the below logic fails if the ssm deregister api does not return a response but the instance is still alive
1316
1336
# echo $data
0 commit comments