setup: allow running when uuid can not be read or saved
This commit is contained in:
parent
e3b080ba7f
commit
1f3eca1b1b
25
node.go
25
node.go
@ -25,6 +25,7 @@ func InitNodeUUID() (*uuid.UUID, error) {
|
||||
}
|
||||
}
|
||||
|
||||
slog.Debug("UUID: Reading UUID")
|
||||
f, err := os.Open(UUID_PATH)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -41,23 +42,33 @@ func InitNodeUUID() (*uuid.UUID, error) {
|
||||
}
|
||||
|
||||
func createNodeUUID() (*uuid.UUID, error) {
|
||||
err := os.MkdirAll(CONFIG_PATH, 0755)
|
||||
uuid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = os.MkdirAll(CONFIG_PATH, 0755)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
slog.Warn("Could not create /etc/hvpn directory!")
|
||||
slog.Info("Proccedig without saving node UUID")
|
||||
return &uuid, nil
|
||||
}
|
||||
|
||||
mode := os.O_RDWR | os.O_CREATE | os.O_EXCL
|
||||
f, err := os.OpenFile(UUID_PATH, mode, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uuid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
slog.Error(err.Error())
|
||||
slog.Warn("Could not open uuid file")
|
||||
slog.Info("Proccedig without saving node UUID")
|
||||
return &uuid, nil
|
||||
}
|
||||
n, err := f.Write(uuid[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
slog.Error(err.Error())
|
||||
slog.Warn("Could not write to uuid file")
|
||||
slog.Info("Proccesing without saving node UUID")
|
||||
return &uuid, nil
|
||||
}
|
||||
slog.Debug("UUID: Wrote " + fmt.Sprint(n) + "bytes")
|
||||
return &uuid, nil
|
||||
|
Loading…
Reference in New Issue
Block a user