virtigo/main.go

62 lines
1014 B
Go
Raw Normal View History

// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
package main
import (
"embed"
"os"
"time"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
)
var Version string
//go:embed resources/*
var resources embed.FS
func main() {
pp := arg.MustParse(&argv)
if !argv.Uptime {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
if argv.Daemon {
log.DaemonMode(true)
}
readDropletFile("droplets")
readHypervisorFile("hypervisor")
// initialize the grid as unstable
me.unstable = time.Now()
log.Info("create cluser for", argv.Hosts)
for _, name := range argv.Hosts {
h := addHypervisor(name)
h.Active = true
}
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)
}
// start the watchdog polling for each hypervisor
for _, h := range me.hypers {
log.Info("starting watchdog here for hostname =", h.Hostname)
go h.NewWatchdog()
}
// sit here
startHTTP()
}