package main import ( "flag" "fmt" "log" "os" "os/signal" "syscall" "path/filepath" "xengineering.eu/ceres/model" ) func main() { flag.Parse() if printVersion { fmt.Println(version) os.Exit(0) } log.Println("Ceres recipe server started") defer log.Println("Ceres recipe server stopped") if config.Path != "" { config.Read() } storage := model.NewStorage(config.StorageFilePath) if !storage.Exists() { storage.Create() } log.Printf("Storage directory: %s\n", storage.Path) model.InitDatabase(filepath.Join(storage.Path, "ceres.sqlite3")) defer model.CloseDatabase() model.InjectTestRecipes() server := NewServer(config.HttpAddress) go server.Start() defer server.Stop() await(syscall.SIGTERM, syscall.SIGINT) } func await(signals ...syscall.Signal) { listener := make(chan os.Signal) for _, s := range signals { signal.Notify(listener, s) } sig := <-listener log.Printf("Received OS signal '%v'\n", sig) }