| diff --git a/google_guest_agent/instance_setup.go b/google_guest_agent/instance_setup.go |
| index 6288c18..70391ac 100644 |
| --- a/google_guest_agent/instance_setup.go |
| +++ b/google_guest_agent/instance_setup.go |
| @@ -156,7 +156,12 @@ func agentInit(ctx context.Context) { |
| // Check if instance ID has changed, and if so, consider this |
| // the first boot of the instance. |
| // TODO Also do this for windows. liamh@13-11-2019 |
| - instanceIDFile := config.Section("Instance").Key("instance_id_dir").MustString("/etc") + "/google_instance_id" |
| + instanceIDDir := config.Section("Instance").Key("instance_id_dir").MustString("/etc") |
| + // Create the instance ID directory, if it doesn't exist. |
| + if err := os.MkdirAll(instanceIDDir, 0755); err != nil { |
| + logger.Warningf("Failed to create instance ID directory: %v", err) |
| + } |
| + instanceIDFile := instanceIDDir + "/google_instance_id" |
| instanceID, err := ioutil.ReadFile(instanceIDFile) |
| if err != nil && !os.IsNotExist(err) { |
| logger.Warningf("Not running first-boot actions, error reading instance ID: %v", err) |
| @@ -197,6 +202,11 @@ func agentInit(ctx context.Context) { |
| |
| func generateSSHKeys() error { |
| hostKeyDir := config.Section("InstanceSetup").Key("host_key_dir").MustString("/etc/ssh") |
| + // Create the host key directory, if it doesn't exist. |
| + if err := os.MkdirAll(hostKeyDir, 0755); err != nil { |
| + logger.Warningf("Failed to create host key directory: %v", err) |
| + } |
| + |
| dir, err := os.Open(hostKeyDir) |
| if err != nil { |
| return err |