fix: gitea controller
This commit is contained in:
@@ -652,21 +652,26 @@ gcr_vm_verify_rebuilt() {
|
||||
# The controller starts the service only after the claim record is written.
|
||||
gcr_vm_runner_service() {
|
||||
vm_id="$1"; action="$2"
|
||||
ip="$(gcr_vm_public_ip "$vm_id")" || return 1
|
||||
[ -n "$ip" ] || return 1
|
||||
gcr_vm_runner_service_pinned "$ip" \
|
||||
"${GCR_SSH_KNOWN_HOSTS_FILE:-}" "$action"
|
||||
}
|
||||
|
||||
gcr_vm_runner_service_pinned() {
|
||||
ip="$1"; known_hosts_file="$2"; action="$3"
|
||||
case "$action" in
|
||||
start|stop) service_command="systemctl $action gitea-runner.service" ;;
|
||||
health) service_command="systemctl is-active --quiet gitea-runner.service" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
ip="$(gcr_vm_public_ip "$vm_id")" || return 1
|
||||
[ -n "$ip" ] || return 1
|
||||
test -n "${GCR_SSH_PRIVKEY_FILE:-}" && test -r "$GCR_SSH_PRIVKEY_FILE" || return 1
|
||||
test -n "${GCR_SSH_KNOWN_HOSTS_FILE:-}" \
|
||||
&& test -r "$GCR_SSH_KNOWN_HOSTS_FILE" || return 1
|
||||
test -n "$known_hosts_file" && test -r "$known_hosts_file" || return 1
|
||||
key_tmp="$(mktemp "${TMPDIR:-/tmp}/gcr-runner-sshkey.XXXXXX")"
|
||||
cat "$GCR_SSH_PRIVKEY_FILE" > "$key_tmp"
|
||||
printf '\n' >> "$key_tmp"
|
||||
chmod 0600 "$key_tmp"
|
||||
ssh_opts="-i $key_tmp -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$GCR_SSH_KNOWN_HOSTS_FILE -o ConnectTimeout=5 -o BatchMode=yes"
|
||||
ssh_opts="-i $key_tmp -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$known_hosts_file -o ConnectTimeout=5 -o BatchMode=yes"
|
||||
if timeout 30 ssh $ssh_opts "root@$ip" "$service_command"; then
|
||||
rm -f "$key_tmp"
|
||||
return 0
|
||||
@@ -1015,6 +1020,7 @@ token_file=/run/gcr-registration-token
|
||||
umask 077
|
||||
printf '%s' '$reg_token_b64' | base64 -d > "\$token_file"
|
||||
trap 'rm -f "\$token_file"' EXIT HUP INT TERM
|
||||
systemctl disable --now gitea-runner.service 2>/dev/null || true
|
||||
if [ ! -s /var/lib/gitea-runner/.runner ]; then
|
||||
/usr/local/bin/gitea-runner register --no-interactive --ephemeral \
|
||||
--instance '$GCR_GITEA_URL' --token "\$(cat "\$token_file")" \
|
||||
@@ -1024,12 +1030,12 @@ fi
|
||||
rm -f "\$token_file"
|
||||
trap - EXIT HUP INT TERM
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now gitea-runner.service
|
||||
BSEOF
|
||||
}
|
||||
|
||||
# gcr_vm_bootstrap_ssh IP LABEL REG_TOKEN RUNNER_NAME KNOWN_HOSTS JOB ATTEMPT VM
|
||||
# Waits for strict-pinned SSH readiness, then pushes the bootstrap script.
|
||||
# Waits for strict-pinned SSH readiness, then installs and registers without
|
||||
# starting the daemon. Controller persists exact runner ID before activation.
|
||||
gcr_vm_bootstrap_ssh() (
|
||||
ip="$1"; label="$2"; reg_token="$3"; runner_name="$4"
|
||||
known_hosts_file="${5:-${GCR_SSH_KNOWN_HOSTS_FILE:-}}"
|
||||
|
||||
Reference in New Issue
Block a user