50 lines
963 B
Go
50 lines
963 B
Go
package zoopb
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"go.wit.com/lib/config"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
// sent via -ldflags
|
|
var VERSION string
|
|
var BUILDTIME string
|
|
|
|
func (m *Machine) SinceLastUpdate() time.Duration {
|
|
age := m.Laststamp.AsTime()
|
|
return time.Since(age)
|
|
}
|
|
|
|
func InitMachine() (*Machine, string) {
|
|
var fullname string
|
|
var err error
|
|
m := new(Machine)
|
|
if fullname, err = config.LoadPB(m, "forge", "machine"); err != nil {
|
|
log.Info("zoopb.ConfigLoad() failed", err)
|
|
}
|
|
hostname, _ := os.Hostname()
|
|
m.Hostname = hostname
|
|
m.Distro = detectDistro()
|
|
m.initPackages()
|
|
|
|
m.InitWitMirrors()
|
|
config.SavePB(m, fullname)
|
|
|
|
return m, fullname
|
|
}
|
|
|
|
func InitDaemon() (*Machine, string) {
|
|
var fullname string
|
|
var err error
|
|
machine := new(Machine)
|
|
if fullname, err = config.LoadPB(machine, "/etc/zookeeper", "machine"); err != nil {
|
|
log.Info("zoopb.ConfigLoad() failed", err)
|
|
}
|
|
machine.InitWitMirrors()
|
|
config.SavePB(machine, fullname)
|
|
|
|
return machine, fullname
|
|
}
|