GoogleCloudPlatform / guest-agent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusing error message when SSH service is called 'sshd'

glaubitz opened this issue · comments

The change in #106 added the capability to start the SSH service:

	// SSH should be explicitly started if not running.
	for _, svc := range []string{"ssh", "sshd"} {
		if err := startService(svc, true); err != nil {
			logger.Errorf("Error restarting service: %v.", err)
		} else {
			// Stop on first matching, to avoid double restarting.
			break
		}

On openSUSE/SLE systems, the SSH service is called sshd which causes the above code snippet to output a confusing error message into the daemon's log due to the fact that the agent tries to start ssh first, then prints an error message and then tries to start sshd which is successful.

May 11 11:07:33 sle-15-jpag-test GCEGuestAgent[1147]: 2021-05-11T11:07:33.2492Z GCEGuestAgent Error oslogin.go:115: Error restarting service: Failed to start ssh.service: Unit ssh.service not found.
                                                      .
May 11 11:07:33 sle-15-jpag-test google_guest_agent[1147]: 2021/05/11 11:07:33 logging client: rpc error: code = PermissionDenied desc = Cloud Logging API has not been used in project 284177885636 before or it is disabled. Enable it by visiting https://console.develope>
May 11 11:10:33 sle-15-jpag-test GCEGuestAgent[1147]: 2021-05-11T11:10:33.5435Z GCEGuestAgent Info: Updating keys for user suse_gce.
May 11 11:10:34 sle-15-jpag-test google_guest_agent[1147]: 2021/05/11 11:10:34 logging client: rpc error: code = PermissionDenied desc = Cloud Logging API has not been used in project 284177885636 before or it is disabled. Enable it by visiting https://console.develope>
May 11 11:13:27 sle-15-jpag-test systemd[1]: Stopping Google Compute Engine Guest Agent...
May 11 11:13:27 sle-15-jpag-test GCEGuestAgent[1147]: 2021-05-11T11:13:27.9713Z GCEGuestAgent Info: GCE Agent Stopped
May 11 11:13:27 sle-15-jpag-test systemd[1]: Stopped Google Compute Engine Guest Agent.
May 11 11:13:27 sle-15-jpag-test systemd[1]: Started Google Compute Engine Guest Agent

The code should probably check first what the name of the SSH service is before trying to start it. This way the value of err will actually reflect whether the failure of starting the service was not caused by trying to start ssh on a system where the service is actually called sshd.