Merge pull request #372 from mrd0ll4r/build-win

cmd/chihaya: make things work on windows
This commit is contained in:
mrd0ll4r 2017-12-24 13:28:29 +01:00 committed by GitHub
commit 8f472ad52c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import (
"errors" "errors"
"os" "os"
"os/signal" "os/signal"
"runtime"
"runtime/pprof" "runtime/pprof"
"strings" "strings"
"syscall" "syscall"
@ -141,8 +142,7 @@ func RunCmdFunc(cmd *cobra.Command, args []string) error {
quit := make(chan os.Signal) quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
reload := make(chan os.Signal) reload := makeReloadChan()
signal.Notify(reload, syscall.SIGUSR1)
for { for {
select { select {
@ -173,6 +173,14 @@ func main() {
Short: "BitTorrent Tracker", Short: "BitTorrent Tracker",
Long: "A customizable, multi-protocol BitTorrent Tracker", Long: "A customizable, multi-protocol BitTorrent Tracker",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
noColors, err := cmd.Flags().GetBool("nocolors")
if err != nil {
return err
}
if noColors {
log.SetFormatter(&logrus.TextFormatter{DisableColors: true})
}
jsonLog, err := cmd.Flags().GetBool("json") jsonLog, err := cmd.Flags().GetBool("json")
if err != nil { if err != nil {
return err return err
@ -216,6 +224,11 @@ func main() {
rootCmd.Flags().String("cpuprofile", "", "location to save a CPU profile") rootCmd.Flags().String("cpuprofile", "", "location to save a CPU profile")
rootCmd.Flags().Bool("debug", false, "enable debug logging") rootCmd.Flags().Bool("debug", false, "enable debug logging")
rootCmd.Flags().Bool("json", false, "enable json logging") rootCmd.Flags().Bool("json", false, "enable json logging")
if runtime.GOOS == "windows" {
rootCmd.Flags().Bool("nocolors", true, "disable log coloring")
} else {
rootCmd.Flags().Bool("nocolors", false, "disable log coloring")
}
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
log.Fatal("failed when executing root cobra command: " + err.Error()) log.Fatal("failed when executing root cobra command: " + err.Error())

View file

@ -0,0 +1,15 @@
// +build darwin freebsd linux netbsd openbsd dragonfly solaris
package main
import (
"os"
"os/signal"
"syscall"
)
func makeReloadChan() <-chan os.Signal {
reload := make(chan os.Signal)
signal.Notify(reload, syscall.SIGUSR1)
return reload
}

View file

@ -0,0 +1,15 @@
// +build windows
package main
import (
"os"
"os/signal"
"syscall"
)
func makeReloadChan() <-chan os.Signal {
reload := make(chan os.Signal)
signal.Notify(reload, syscall.SIGHUP)
return reload
}