File
Blob: tun/client/reload.go
| 1 | package client |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "time" |
| 6 | |
| 7 | "go.uber.org/zap" |
| 8 | ) |
| 9 | |
| 10 | func (c *Client) reloadOnSignal(ctx context.Context) { |
| 11 | defer c.closeWg.Done() |
| 12 | |
| 13 | for { |
| 14 | select { |
| 15 | case <-c.closeCh: |
| 16 | return |
| 17 | case <-ctx.Done(): |
| 18 | return |
| 19 | case <-c.ReloadSignal: |
| 20 | c.Logger.Info("Received SIGHUP, reloading config") |
| 21 | if result := c.doReload(ctx); result.Error != "" { |
| 22 | c.Logger.Warn("Configuration reload did not fully succeed", zap.String("error", result.Error)) |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func (c *Client) doReload(ctx context.Context) SyncResult { |
| 29 | c.syncMu.Lock() |
| 30 | defer c.syncMu.Unlock() |
| 31 | c.configMu.Lock() |
| 32 | if err := c.Configuration.reloadFile(); err != nil { |
| 33 | c.Logger.Error("Error reloading config file", zap.Error(err)) |
| 34 | c.configMu.Unlock() |
| 35 | now := time.Now() |
| 36 | return SyncResult{Error: err.Error(), AttemptedAt: &now, Tunnels: []TunnelSyncResult{}} |
| 37 | } |
| 38 | c.setRoutes(c.Configuration.Tunnels) |
| 39 | c.configMu.Unlock() |
| 40 | return c.syncConfigTunnels(ctx, true) |
| 41 | } |
| 42 | |
| 43 | func (c *Client) UpdateApex(apex string) { |
| 44 | c.configMu.Lock() |
| 45 | c.Configuration.Apex = apex |
| 46 | if err := c.Configuration.writeFile(); err != nil { |
| 47 | c.Logger.Error("Error saving to config file", zap.Error(err)) |
| 48 | } |
| 49 | c.configMu.Unlock() |
| 50 | } |
| 51 | |
| 52 | func (c *Client) GetCurrentConfig() *Config { |
| 53 | c.configMu.RLock() |
| 54 | defer c.configMu.RUnlock() |
| 55 | return c.Configuration.clone() |
| 56 | } |