You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.4 KiB

package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/pkg/errors"
"github.com/urfave/cli"
"golang.org/x/sys/unix"
)
const appDescription = `
`
// AppVersion is the version number of the application.
const AppVersion = "dirty" // to be compiled in
func main() {
app := cli.NewApp()
app.Name = "achtung"
app.Usage = "The simplest of host monitoring solutions"
app.Version = AppVersion
app.Author = "Erik Hollensbe <erik+github@hollensbe.org>"
app.ArgsUsage = "[flags] [configuration filename]"
app.Description = appDescription
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug logging",
},
}
app.Action = run
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
func handleTerminationSignals(cancel context.CancelFunc) {
sigChan := make(chan os.Signal, 2)
signal.Notify(sigChan, unix.SIGTERM, unix.SIGINT)
for range sigChan {
cancel()
}
}
func run(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return errors.New("invalid arguments; seek --help")
}
a := &agent{
debug: ctx.Bool("debug"),
}
if err := a.parseConfig(ctx.Args()[0]); err != nil {
return errors.Wrap(err, "during the parse of the configuration file")
}
goCtx, cancel := context.WithCancel(context.Background())
go handleTerminationSignals(cancel)
return a.boot(goCtx)
}