Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto reload on config change #756

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/IBM/sarama v1.41.2
github.com/OneOfOne/xxhash v1.2.8
github.com/julienschmidt/httprouter v1.3.0
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/karrick/goswarm v1.10.0
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/karrick/goswarm v1.10.0 h1:hGUt7r6O3bR02whvkW/E4rU6Ei7MekGGlTD5zqAYSHo=
github.com/karrick/goswarm v1.10.0/go.mod h1:wqange6Y/RHXs23gBc4nRXPent8RaiFyfl2+otwXj8U=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import (
"github.com/spf13/viper"

"github.com/linkedin/Burrow/core"

"github.com/fsnotify/fsnotify"
"github.com/kardianos/osext"
)

// exitCode wraps a return value for the application
Expand Down Expand Up @@ -84,6 +87,24 @@ func main() {
panic(exitCode{1})
}

// auto reload on config change
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Fprintln(os.Stderr, "Config file changed: ", e.Name)
file, err := osext.Executable()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed retrieving executable name:", err.Error())
fmt.Fprintln(os.Stderr, "Manual restart is needed")
return
}
err = syscall.Exec(file, os.Args, os.Environ())
if err != nil {
fmt.Fprintln(os.Stderr, "Failed restarting:", err.Error())
fmt.Fprintln(os.Stderr, "Manual restart is needed")
return
}
})

// setup viper to be able to read env variables with a configured prefix
viper.SetDefault("general.env-var-prefix", "burrow")
envPrefix := viper.GetString("general.env-var-prefix")
Expand Down