0

I have a GCE instance that I push code to using Cloud Build. I need to restart services on that VM once the code has been pushed. Here's what my Cloud Build YAML looks like:

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

While the first step works fine, while trying to restart the service, I receive the following error:

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.

I've tried disabling the interactive authentication mechanism as mentioned here and here but that hasn't worked. Please help.

Pranay Nanda
  • 179
  • 3
  • 21

1 Answers1

1

After investigating this issue, I suggest a workaround, which is to make a listener run by root, that checks if a file exists. This file is created by the user from Cloud Build when there is a build (with touch, for example). If the file exists, the listener deletes it and restarts the service. The code:

#!/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
asbovelw
  • 552
  • 2
  • 9