@@ -3,6 +3,7 @@ package commands
33import (
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