Skip to content

Commit

Permalink
Nicer etcd ismounted handling
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Apr 2, 2024
1 parent a1a56e0 commit f62fbae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/metal-stack/v v1.0.3
// archiver must stay in version v2.1.0, see replace below
github.com/mholt/archiver v3.1.1+incompatible
github.com/moby/sys/mountinfo v0.7.1
github.com/pierrec/lz4/v4 v4.1.21
github.com/prometheus/common v0.51.1
github.com/samber/slog-loki/v3 v3.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0Gq
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g=
github.com/moby/sys/mountinfo v0.7.1/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/moby/sys/signal v0.6.0/go.mod h1:GQ6ObYZfqacOwTtlXvcmh9A26dVRul/hbOZn88Kg8Tg=
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
github.com/moby/sys/symlink v0.2.0/go.mod h1:7uZVF2dqJjG/NsClqul95CqKOBRQyYSNnJ6BMgR/gFs=
Expand Down
26 changes: 17 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,39 @@ import (
"github.com/metal-stack/metal-hammer/cmd/event"
"github.com/metal-stack/metal-hammer/cmd/network"
"github.com/metal-stack/metal-hammer/pkg/kernel"
"github.com/moby/sys/mountinfo"
)

func main() {
jsonHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
log := slog.New(jsonHandler)

fmt.Print(cmd.HammerBanner)
if len(os.Args) > 1 {
panic("cmd args are not supported")
}

err := syscall.Unmount("/etc", syscall.MNT_FORCE)
mounted, err := mountinfo.Mounted("/etc")
if err != nil {
fmt.Printf("unable to umount /etc, which is overmounted with tmpfs %s", err)
// os.Exit(1) // FIXME enable again
log.Error("unable to check if /etc is a mountpoint", "error", err)
os.Exit(1)
}
if mounted {
err := syscall.Unmount("/etc", syscall.MNT_FORCE)
if err != nil {
log.Error("unable to umount /etc, which is overmounted with tmpfs", "error", err)
os.Exit(1)
}
}

err = updateResolvConf()
if err != nil {
fmt.Printf("error updating resolv.conf %s", err)
log.Error("error updating resolv.conf", "error", err)
os.Exit(1)
}

jsonHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
log := slog.New(jsonHandler)

// Reboot if metal-hammer crashes after 60sec.
go kernel.Watchdog(log)

Expand Down

0 comments on commit f62fbae

Please sign in to comment.