forked from tslocum/twins
1
0
Fork 0
twins/main.go

54 lines
1.1 KiB
Go
Raw Normal View History

2020-10-29 20:35:48 +00:00
package main
import (
"flag"
"log"
"os"
"os/signal"
2020-10-29 20:35:48 +00:00
"path"
"syscall"
2020-10-29 20:35:48 +00:00
)
2020-10-30 00:17:23 +00:00
func init() {
log.SetOutput(os.Stdout)
}
2020-11-17 04:21:00 +00:00
var quiet bool
2021-07-10 16:13:39 +00:00
var debug bool
2020-10-30 00:17:23 +00:00
2020-10-29 20:35:48 +00:00
func main() {
2020-11-12 17:56:59 +00:00
log.SetFlags(0)
2020-10-29 20:35:48 +00:00
configFile := flag.String("config", "", "path to configuration file")
2020-11-17 04:21:00 +00:00
flag.BoolVar(&quiet, "quiet", false, "do not print access log")
2021-07-10 16:13:39 +00:00
flag.BoolVar(&debug, "debug", false, "print debug information")
2020-10-29 20:35:48 +00:00
flag.Parse()
if *configFile == "" {
homedir, err := os.UserHomeDir()
if err == nil && homedir != "" {
*configFile = path.Join(homedir, ".config", "twins", "config.yaml")
}
}
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP)
go func() {
for {
<-sig
err := readconfig(*configFile)
if err != nil {
log.Fatalf("failed to reload configuration file at %s: %v", *configFile, err)
}
log.Println("configuration reloaded successfully")
}
}()
2020-10-29 20:35:48 +00:00
err := readconfig(*configFile)
if err != nil {
2020-10-29 20:35:48 +00:00
log.Fatalf("failed to read configuration file at %s: %v\nSee CONFIGURATION.md for information on configuring twins", *configFile, err)
}
listen(config.Listen)
2020-10-29 20:35:48 +00:00
}