Skip to content

Commit 10afc0f

Browse files
committed
Add server restart to restart a sidecar
1 parent 9e40300 commit 10afc0f

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ The changelog for Bonvoy
22

33
## Pending Release
44

5-
* Add `statistics dump` command
5+
* Add `server restart` to restart a sidecar
6+
* Add `statistics dump` command to dump statistics
67
* Better resiliency around restarting sidecars
78
* Add `certificates list` to show all registered certificates on a sidecar
89
* Add `config dump` to dump the entire Envoy config

commands/server.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commands
33
import (
44
"bonvoy/envoy"
55
"fmt"
6+
"github.com/fatih/color"
67
"github.com/olekukonko/tablewriter"
78
"github.com/spf13/cobra"
89
"os"
@@ -19,6 +20,7 @@ func (r *Registry) Server() *Server {
1920
}
2021
cmd.AddCommand(r.BuildServerInfoCommand())
2122
cmd.AddCommand(r.BuildServerMemoryCommand())
23+
cmd.AddCommand(r.BuildServerRestartCommand())
2224
return &Server{
2325
Command: cmd,
2426
}
@@ -159,4 +161,36 @@ func (s *ServerMemoryController) Run() error {
159161
table.SetAlignment(tablewriter.ALIGN_LEFT)
160162
table.Render()
161163
return nil
162-
}
164+
}
165+
166+
// server restart
167+
168+
type ServerRestartController struct {
169+
ServiceName string
170+
}
171+
func (r *Registry) BuildServerRestartCommand() *cobra.Command {
172+
return &cobra.Command{
173+
Use: "restart",
174+
Short: "Restart an Envoy sidecar",
175+
Long: `Restarts an Envoy sidecar process`,
176+
Args: cobra.MinimumNArgs(1),
177+
RunE: func(cmd *cobra.Command, args []string) error {
178+
controller := ServerRestartController{
179+
ServiceName: args[0],
180+
}
181+
return controller.Run()
182+
},
183+
}
184+
}
185+
186+
func (s *ServerRestartController) Run() error {
187+
e, err := envoy.NewFromServiceName(s.ServiceName)
188+
if err != nil { return err }
189+
190+
err = e.Restart()
191+
if err != nil { return err }
192+
193+
color.Green(s.ServiceName + " Envoy restarted.")
194+
// TODO: Would be nice to monitor and let the user know when the service comes back alive.
195+
return nil
196+
}

0 commit comments

Comments
 (0)