Skip to content

Commit

Permalink
Remove file change detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
csstaub committed Jun 23, 2018
1 parent 3d7b634 commit ae5cc8d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 195 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ control.
**Certificate hotswapping**: Ghostunnel can reload certificates at runtime
without dropping existing connections. To trigger a reload, simply send
`SIGUSR1` to the process (or set a time-based reloading interval). This will
cause ghostunnel to reload the keystore files. Once successful, the reloaded
cause ghostunnel to reload the certificate/key. Once successful, the reloaded
certificate will be used for new connections going forward.

**Monitoring and metrics**: Ghostunnel has a built-in status feature that
Expand Down
13 changes: 4 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ var exitFunc = os.Exit

// Context groups listening context data together
type Context struct {
watcher chan bool
status *statusHandler
statusHTTP *http.Server
shutdownTimeout time.Duration
Expand Down Expand Up @@ -305,12 +304,6 @@ func run(args []string) error {
}
metrics := sqmetrics.NewMetrics(*metricsURL, *metricsPrefix, client, *metricsInterval, metrics.DefaultRegistry, logger)

// Set up file watchers (if requested)
watcher := make(chan bool, 1)
if *timedReload > 0 {
go watchFiles([]string{*keystorePath}, *timedReload, watcher)
}

cert, err := buildCertificate(*keystorePath, *keystorePass)
if err != nil {
fmt.Fprintf(os.Stderr, "error: unable to load certificates: %s\n", err)
Expand All @@ -332,7 +325,8 @@ func run(args []string) error {
logger.Printf("using target address %s", *serverForwardAddress)

status := newStatusHandler(dial)
context := &Context{watcher, status, nil, *shutdownTimeout, dial, metrics, cert}
context := &Context{status, nil, *shutdownTimeout, dial, metrics, cert}
go context.reloadHandler(*timedReload)

// Start listening
err = serverListen(context)
Expand Down Expand Up @@ -361,7 +355,8 @@ func run(args []string) error {
}

status := newStatusHandler(dial)
context := &Context{watcher, status, nil, *shutdownTimeout, dial, metrics, cert}
context := &Context{status, nil, *shutdownTimeout, dial, metrics, cert}
go context.reloadHandler(*timedReload)

// Start listening
err = clientListen(context)
Expand Down
11 changes: 9 additions & 2 deletions signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ func (context *Context) signalHandler(p *proxy.Proxy) {

logger.Printf("received %s, reloading certificates", sig.String())
context.reload()
case <-context.watcher:
context.reload()
}
}
}

func (context *Context) reloadHandler(interval time.Duration) {
if interval == 0 {
return
}
for range time.Tick(interval) {
context.reload()
}
}

func (context *Context) reload() {
context.status.Reloading()
err := context.cert.Reload()
Expand Down
100 changes: 0 additions & 100 deletions watcher.go

This file was deleted.

83 changes: 0 additions & 83 deletions watcher_test.go

This file was deleted.

0 comments on commit ae5cc8d

Please sign in to comment.