Bash 使用云构建在GCE实例上重新启动服务
我有一个GCE实例,我使用云构建将代码推送到它。我需要在推送代码后重新启动该VM上的服务。以下是我的云构建YAML的外观:Bash 使用云构建在GCE实例上重新启动服务,bash,authentication,google-cloud-platform,google-compute-engine,google-cloud-build,Bash,Authentication,Google Cloud Platform,Google Compute Engine,Google Cloud Build,我有一个GCE实例,我使用云构建将代码推送到它。我需要在推送代码后重新启动该VM上的服务。以下是我的云构建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 --z
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.
我尝试过禁用上面提到的交互式身份验证机制,但没有成功。请提供帮助。在调查此问题之后,我建议一种解决方法,即让侦听器以root用户身份运行,以检查文件是否存在。例如,当存在使用touch的构建时,该文件由用户从Cloud Build创建。如果文件存在,侦听器将删除该文件并重新启动服务。守则:
#!/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
试着用这里描述的sudo来运行它。一个能解决你的问题吗?@guillaumeblaquiere,我不这么认为。重置还会导致相当大的停机时间,这是无法承受的。请同意,VM重新启动和停机时间更长。根据您的限制,这可能是一个解决方案。但不是!