2020-10-29 21:35:48 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
2020-10-31 22:59:44 +01:00
|
|
|
"os/signal"
|
2020-10-29 21:35:48 +01:00
|
|
|
"path"
|
2020-10-31 22:59:44 +01:00
|
|
|
"syscall"
|
2020-10-29 21:35:48 +01:00
|
|
|
)
|
|
|
|
|
2020-10-30 01:17:23 +01:00
|
|
|
func init() {
|
|
|
|
log.SetOutput(os.Stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
var verbose bool
|
|
|
|
|
2020-10-29 21:35:48 +01:00
|
|
|
func main() {
|
|
|
|
configFile := flag.String("config", "", "path to configuration file")
|
2020-10-30 01:17:23 +01:00
|
|
|
flag.BoolVar(&verbose, "verbose", false, "print request and response information")
|
2020-10-29 21:35:48 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *configFile == "" {
|
|
|
|
homedir, err := os.UserHomeDir()
|
|
|
|
if err == nil && homedir != "" {
|
|
|
|
*configFile = path.Join(homedir, ".config", "twins", "config.yaml")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 22:59:44 +01:00
|
|
|
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 21:35:48 +01:00
|
|
|
err := readconfig(*configFile)
|
2020-10-29 22:58:12 +01:00
|
|
|
if err != nil {
|
2020-10-29 21:35:48 +01:00
|
|
|
log.Fatalf("failed to read configuration file at %s: %v\nSee CONFIGURATION.md for information on configuring twins", *configFile, err)
|
|
|
|
}
|
|
|
|
|
2020-10-30 21:30:09 +01:00
|
|
|
log.Printf("twins running on %s:%d", config.hostname, config.port)
|
2020-10-30 19:19:16 +01:00
|
|
|
|
2020-10-31 22:59:44 +01:00
|
|
|
listen(config.Listen)
|
2020-10-29 21:35:48 +01:00
|
|
|
}
|