【问题标题】:Restart Services on GCE Instance Using Cloud Build使用 Cloud Build 重启 GCE 实例上的服务
【发布时间】:2020-06-01 09:38:35
【问题描述】:

我有一个 GCE 实例,我将代码推送到使用 Cloud Build。推送代码后,我需要重新启动该 VM 上的服务。这是我的 Cloud Build YAML 的样子:

steps:

- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args: 
  - '-c'
  -  |
      for d in *; do
              gcloud compute scp $d user@instance-1:/path/to/directory --zone=asia-south1-a --recurse

      done

- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  -  |
      gcloud compute ssh user@instance-1 --zone=asia-south1-a --command="service uwsgi restart"

timeout: 1200s

虽然第一步工作正常,但在尝试重新启动服务时,我收到以下错误:

Already have image (with digest): gcr.io/cloud-builders/gcloud
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 error=n/a
Got message type=method_return sender=org.freedesktop.DBus destination=:1.3477 object=n/a interface=n/a member=n/a cookie=1 reply_cookie=1 error=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=AddMatch cookie=2 reply_cookie=0 error=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=AddMatch cookie=3 reply_cookie=0 error=n/a
Calling manager for ReloadUnit on uwsgi.service, replace
Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=ReloadUnit cookie=4 reply_cookie=0 error=n/a
Failed to reload uwsgi.service: Interactive authentication required.
See system logs and 'systemctl status uwsgi.service' for details.
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RemoveMatch cookie=5 reply_cookie=0 error=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RemoveMatch cookie=6 reply_cookie=0 error=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=ReloadUnit cookie=4 reply_cookie=0 error=n/a
Failed to reload uwsgi.service: Interactive authentication required.
See system logs and 'systemctl status uwsgi.service' for details.

我已尝试禁用herehere 中提到的交互式身份验证机制,但没有奏效。请帮忙。

【问题讨论】:

  • 尝试使用此处描述的 sudo 运行它stackoverflow.com/questions/51500748/…
  • reset 可以解决您的问题吗?
  • @guillaumeblaquiere 我不这么认为。重置也会导致相当长的停机时间,这是无法承受的。
  • 同意,虚拟机重启,停机时间更长。根据您的限制,这可能是一个解决方案。但不是!

标签: bash authentication google-cloud-platform google-compute-engine google-cloud-build


【解决方案1】:

在调查了这个问题之后,我建议了一个解决方法,即让一个由 root 运行的侦听器来检查文件是否存在。此文件由用户在有构建时从 Cloud Build 创建(例如,使用 touch)。如果该文件存在,则侦听器将其删除并重新启动服务。代码:

#!/bin/bash

# Listener to be run by root. When user from
# Cloud Build touches $FILE, root removes it
# and restarts the service from within the VM.

FILE="/home/user/file"

function listen()
{
        if [ -f "$FILE" ]; then
            rm $FILE
            service uwsgi restart
            sleep 60
        else
            sleep 10
        fi
}

while true
do
    listen
done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    相关资源
    最近更新 更多