summaryrefslogtreecommitdiff
path: root/main.go
blob: f8a0fb13f46c874934320a6a3e55b5bd4f7915ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"embed"
	"os"
	"time"

	"go.wit.com/dev/alexflint/arg"
	"go.wit.com/gui"
	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

var VERSION string
var BUILDTIME string

//go:embed resources/*
var resources embed.FS

func main() {
	log.Warn("zookeeper PID:", os.Getpid(), os.Args)
	var pp *arg.Parser
	gui.InitArg()             // include the 'gui' package command line arguements
	pp = arg.MustParse(&argv) // parse the command line

	if pp == nil {
		pp.WriteHelp(os.Stdout)
		os.Exit(0)
	}

	// check if the binary is being called to test
	// if the plugin can actually loaded. This is a hack
	// around needing a Test() plugin load function in GO
	if gui.IsGoPluginTestHack() {
		argv.NoPort = true
		gui.CheckPlugin()
		os.Exit(0)
		// if argv.GuiCheck != "" {
		// }
	}

	if argv.Daemon {
		// turn off timestamps for STDOUT (systemd adds them)
		log.DaemonMode(true)
	}

	me = new(zookeep)
	me.hostname, _ = os.Hostname()
	me.pollDelay = time.Hour
	me.machines = zoopb.NewMachines()
	if err := me.machines.ConfigLoad(); err != nil {
		log.Warn("load config failed", err)
		os.Exit(-1)
	}
	// me.upgrade = make(map[string]bool) // used to trigger upgrade attempts

	// log.Sleep(3)

	go NewWatchdog()
	if !argv.NoPort {
		go startHTTP()
	}
	doGui()
}