Skip to content

Commit

Permalink
Fixed windows builds
Browse files Browse the repository at this point in the history
Removed SIGUSR1 for now, log reopenig is not possible on windows for now
  • Loading branch information
phires committed Jun 6, 2024
1 parent 5a3eea0 commit 13718a2
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 46 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ guerrillad:
# Build for different architectures
$(GO_VARS) GOOS=linux GOARCH=amd64 $(GO) build -o="dist/linux/amd64/guerrillad" -ldflags="$(LD_FLAGS)" $(ROOT)/cmd/guerrillad
$(GO_VARS) GOOS=linux GOARCH=arm64 $(GO) build -o="dist/linux/arm64/guerrillad" -ldflags="$(LD_FLAGS)" $(ROOT)/cmd/guerrillad
# Windows is currently failing
# $(GO_VARS) GOOS=windows GOARCH=amd64 $(GO) build -o="dist/windows/amd64/guerrillad" -ldflags="$(LD_FLAGS)" $(ROOT)/cmd/guerrillad
$(GO_VARS) GOOS=windows GOARCH=amd64 $(GO) build -o="dist/windows/amd64/guerrillad" -ldflags="$(LD_FLAGS)" $(ROOT)/cmd/guerrillad

# Build the binary for current platform (as before) to not break any existing build processes
$(GO_VARS) $(GO) build -o="dist/windows/amd64/guerrillad" -ldflags="$(LD_FLAGS)" $(ROOT)/cmd/guerrillad
Expand Down
44 changes: 0 additions & 44 deletions cmd/guerrillad/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/phires/go-guerrilla"
"github.com/phires/go-guerrilla/log"
Expand Down Expand Up @@ -61,47 +58,6 @@ func init() {
rootCmd.AddCommand(serveCmd)
}

func sigHandler() {
signal.Notify(signalChannel,
syscall.SIGHUP,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGINT,
syscall.SIGKILL,
syscall.SIGUSR1,
os.Kill,
)
for sig := range signalChannel {
if sig == syscall.SIGHUP {
if ac, err := readConfig(configPath, pidFile); err == nil {
_ = d.ReloadConfig(*ac)
} else {
mainlog.WithError(err).Error("Could not reload config")
}
} else if sig == syscall.SIGUSR1 {
if err := d.ReopenLogs(); err != nil {
mainlog.WithError(err).Error("reopening logs failed")
}
} else if sig == syscall.SIGTERM || sig == syscall.SIGQUIT || sig == syscall.SIGINT || sig == os.Kill {
mainlog.Infof("Shutdown signal caught")
go func() {
select {
// exit if graceful shutdown not finished in 60 sec.
case <-time.After(time.Second * 60):
mainlog.Error("graceful shutdown timed out")
os.Exit(1)
}
}()
d.Shutdown()
mainlog.Infof("Shutdown completed, exiting.")
return
} else {
mainlog.Infof("Shutdown, unknown signal caught")
return
}
}
}

func serve(cmd *cobra.Command, args []string) {
logVersion()
d = guerrilla.Daemon{Logger: mainlog}
Expand Down
61 changes: 61 additions & 0 deletions cmd/guerrillad/sighandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
// +build darwin dragonfly freebsd linux netbsd openbsd

package main

import (
"os"
"os/signal"
"syscall"
"time"

// enable the Redis redigo driver
_ "github.com/phires/go-guerrilla/backends/storage/redigo"

// Choose iconv or mail/encoding package which uses golang.org/x/net/html/charset
//_ "github.com/phires/go-guerrilla/mail/iconv"
_ "github.com/phires/go-guerrilla/mail/encoding"

_ "github.com/go-sql-driver/mysql"
)

func sigHandler() {
signal.Notify(signalChannel,
syscall.SIGHUP,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGINT,
syscall.SIGKILL,
syscall.SIGUSR1,
os.Kill,
)
for sig := range signalChannel {
if sig == syscall.SIGHUP {
if ac, err := readConfig(configPath, pidFile); err == nil {
_ = d.ReloadConfig(*ac)
} else {
mainlog.WithError(err).Error("Could not reload config")
}
} else if sig == syscall.SIGUSR1 {
if err := d.ReopenLogs(); err != nil {
mainlog.WithError(err).Error("reopening logs failed")
}
} else if sig == syscall.SIGTERM || sig == syscall.SIGQUIT || sig == syscall.SIGINT || sig == os.Kill {
mainlog.Infof("Shutdown signal caught")
go func() {
select {
// exit if graceful shutdown not finished in 60 sec.
case <-time.After(time.Second * 60):
mainlog.Error("graceful shutdown timed out")
os.Exit(1)
}
}()
d.Shutdown()
mainlog.Infof("Shutdown completed, exiting.")
return
} else {
mainlog.Infof("Shutdown, unknown signal caught")
return
}
}
}
56 changes: 56 additions & 0 deletions cmd/guerrillad/sighandler_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//go:build !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd

package main

import (
"os"
"os/signal"
"syscall"
"time"

// enable the Redis redigo driver
_ "github.com/phires/go-guerrilla/backends/storage/redigo"

// Choose iconv or mail/encoding package which uses golang.org/x/net/html/charset
//_ "github.com/phires/go-guerrilla/mail/iconv"
_ "github.com/phires/go-guerrilla/mail/encoding"

_ "github.com/go-sql-driver/mysql"
)

func sigHandler() {
signal.Notify(signalChannel,
syscall.SIGHUP,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGINT,
syscall.SIGKILL,
os.Kill,
)
for sig := range signalChannel {
if sig == syscall.SIGHUP {
if ac, err := readConfig(configPath, pidFile); err == nil {
_ = d.ReloadConfig(*ac)
} else {
mainlog.WithError(err).Error("Could not reload config")
}
} else if sig == syscall.SIGTERM || sig == syscall.SIGQUIT || sig == syscall.SIGINT || sig == os.Kill {
mainlog.Infof("Shutdown signal caught")
go func() {
select {
// exit if graceful shutdown not finished in 60 sec.
case <-time.After(time.Second * 60):
mainlog.Error("graceful shutdown timed out")
os.Exit(1)
}
}()
d.Shutdown()
mainlog.Infof("Shutdown completed, exiting.")
return
} else {
mainlog.Infof("Shutdown, unknown signal caught")
return
}
}
}

0 comments on commit 13718a2

Please sign in to comment.