2024-10-11 13:55:13 -05:00
|
|
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-12 00:17:26 -05:00
|
|
|
"embed"
|
2024-10-11 13:55:13 -05:00
|
|
|
"os"
|
2024-10-13 04:34:55 -05:00
|
|
|
"time"
|
2024-10-11 13:55:13 -05:00
|
|
|
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
2024-10-12 00:17:26 -05:00
|
|
|
"go.wit.com/log"
|
2024-10-11 13:55:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var Version string
|
2024-10-12 00:17:26 -05:00
|
|
|
|
|
|
|
//go:embed resources/*
|
|
|
|
var resources embed.FS
|
2024-10-11 13:55:13 -05:00
|
|
|
|
|
|
|
func main() {
|
2024-10-12 00:17:26 -05:00
|
|
|
pp := arg.MustParse(&argv)
|
2024-10-11 13:55:13 -05:00
|
|
|
|
2024-10-12 10:59:11 -05:00
|
|
|
if !argv.Uptime {
|
2024-10-11 13:55:13 -05:00
|
|
|
pp.WriteHelp(os.Stdout)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-10-12 19:44:43 -05:00
|
|
|
if argv.Daemon {
|
|
|
|
log.DaemonMode(true)
|
|
|
|
}
|
|
|
|
|
2024-10-13 03:04:46 -05:00
|
|
|
readDropletFile("droplets")
|
|
|
|
readHypervisorFile("hypervisor")
|
2024-10-12 12:45:43 -05:00
|
|
|
|
2024-10-13 04:34:55 -05:00
|
|
|
// initialize the grid as unstable
|
|
|
|
me.unstable = time.Now()
|
|
|
|
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Info("create cluser for", argv.Hosts)
|
2024-10-13 03:04:46 -05:00
|
|
|
for _, name := range argv.Hosts {
|
|
|
|
h := addHypervisor(name)
|
|
|
|
h.Active = true
|
2024-10-12 10:59:11 -05:00
|
|
|
}
|
|
|
|
|
2024-10-13 02:23:30 -05:00
|
|
|
if argv.Start != "" {
|
|
|
|
d := findDroplet(argv.Start)
|
|
|
|
if d == nil {
|
|
|
|
log.Info("droplet is unknown:", argv.Start)
|
|
|
|
} else {
|
|
|
|
log.Info("start droplet here:", d.Hostname)
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-10-12 11:54:01 -05:00
|
|
|
// start the watchdog polling for each hypervisor
|
2024-10-12 10:59:11 -05:00
|
|
|
for _, h := range me.hypers {
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Info("starting watchdog here for hostname =", h.Hostname)
|
2024-10-12 11:21:45 -05:00
|
|
|
go h.NewWatchdog()
|
2024-10-12 00:17:26 -05:00
|
|
|
}
|
|
|
|
|
2024-10-12 11:21:45 -05:00
|
|
|
// sit here
|
|
|
|
startHTTP()
|
2024-10-11 13:55:13 -05:00
|
|
|
}
|