From 1df45dc7b3745d0b1f8fffaed8a9b4ed6d6cfd6f Mon Sep 17 00:00:00 2001 From: Carlo Strub Date: Sat, 16 Sep 2017 22:33:24 +0200 Subject: [PATCH] - we go 12factor - remove daemon stuff - change logo --- CHANGELOG.md | 4 ++- sisyphus/sisyphus.go | 86 ++++++-------------------------------------- 2 files changed, 14 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0ef62..8b4e999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ - ## Changed -- +- Converted the entire app to a [Twelve-Factor App](https://12factor.net/). + This has consequences in how you launch it, i.e. use environment variables + instead of flags. ## Fixed - Only permit unicode characters of bitsize larger than 2, this guarantees we diff --git a/sisyphus/sisyphus.go b/sisyphus/sisyphus.go index dc7271a..eb47bda 100644 --- a/sisyphus/sisyphus.go +++ b/sisyphus/sisyphus.go @@ -3,9 +3,7 @@ package main import ( "fmt" "os" - "os/signal" "strings" - "syscall" "time" "github.com/boltdb/bolt" @@ -81,48 +79,22 @@ func main() { Usage: "run sisyphus", Action: func(c *cli.Context) { - // check if daemon already running. - if _, err := os.Stat(*pidfile); err == nil { - log.WithFields(log.Fields{ - "pidfile": *pidfile, - }).Fatal("Already running or pidfile exists") - } - fmt.Print(` - ███████╗██╗███████╗██╗ ██╗██████╗ ██╗ ██╗██╗ ██╗███████╗ - ██╔════╝██║██╔════╝╚██╗ ██╔╝██╔══██╗██║ ██║██║ ██║██╔════╝ - ███████╗██║███████╗ ╚████╔╝ ██████╔╝███████║██║ ██║███████╗ - ╚════██║██║╚════██║ ╚██╔╝ ██╔═══╝ ██╔══██║██║ ██║╚════██║ - ███████║██║███████║ ██║ ██║ ██║ ██║╚██████╔╝███████║ - ╚══════╝╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ + + ##### + # # # #### # # ##### # # # # #### + # # # # # # # # # # # # + ##### # #### # # # ###### # # #### + # # # # ##### # # # # # + # # # # # # # # # # # # # + ##### # #### # # # # #### #### - by Carlo Strub + by Carlo Strub `) - // Make arrangement to remove PID file upon receiving the SIGTERM from kill command - ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGTERM) - - go func() { - signalType := <-ch - signal.Stop(ch) - log.Info("Exit command received. Exiting sisyphus...") - - // this is a good place to flush everything to disk - // before terminating. - log.WithFields(log.Fields{ - "signal": signalType, - }).Info("Received signal") - - // remove PID file - os.Remove(*pidfile) - - os.Exit(0) - - }() if len(maildirPaths) < 1 { log.Fatal("No Maildir set. Please check the manual.") @@ -214,45 +186,9 @@ func main() { }, }, { - // See - // https://www.socketloop.com/tutorials/golang-daemonizing-a-simple-web-server-process-example - // for the process we are using to daemonize - Name: "start", - Aliases: []string{"s"}, - Usage: "start sisyphus daemon in the background", - Action: func(c *cli.Context) error { - - sisyphus.Pidfile(*pidfile).DaemonStart() - - return nil - }, - }, - { - Name: "stop", - Aliases: []string{"e"}, - Usage: "stop sisyphus daemon", - Action: func(c *cli.Context) error { - - sisyphus.Pidfile(*pidfile).DaemonStop() - - return nil - }, - }, - { - Name: "restart", - Aliases: []string{"r"}, - Usage: "restart sisyphus daemon", - Action: func(c *cli.Context) error { - - sisyphus.Pidfile(*pidfile).DaemonRestart() - - return nil - }, - }, - { - Name: "status", + Name: "stats", Aliases: []string{"i"}, - Usage: "status of sisyphus", + Usage: "Statistics from Sisyphus", Action: func(c *cli.Context) error { log.Info("here, we should get statistics from the db, TBD...") return nil