github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/cmd/subtool/restartService.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/Cloud-Foundations/Dominator/lib/filesystem" 8 "github.com/Cloud-Foundations/Dominator/lib/log" 9 "github.com/Cloud-Foundations/Dominator/lib/srpc" 10 "github.com/Cloud-Foundations/Dominator/lib/triggers" 11 "github.com/Cloud-Foundations/Dominator/proto/sub" 12 "github.com/Cloud-Foundations/Dominator/sub/client" 13 ) 14 15 func restartServiceSubcommand(args []string, logger log.DebugLogger) error { 16 srpcClient := getSubClient(logger) 17 defer srpcClient.Close() 18 if err := restartService(srpcClient, args[0]); err != nil { 19 return fmt.Errorf("Error deleting: %s", err) 20 } 21 return nil 22 } 23 24 func restartService(srpcClient *srpc.Client, serviceName string) error { 25 tmpPathname := fmt.Sprintf("/subtool-restart-%d", os.Getpid()) 26 return client.CallUpdate(srpcClient, sub.UpdateRequest{ 27 Wait: true, 28 InodesToMake: []sub.Inode{ 29 { 30 Name: tmpPathname, 31 GenericInode: &filesystem.RegularInode{}, 32 }, 33 }, 34 PathsToDelete: []string{tmpPathname}, 35 Triggers: &triggers.Triggers{ 36 Triggers: []*triggers.Trigger{ 37 { 38 MatchLines: []string{tmpPathname}, 39 Service: serviceName, 40 }, 41 }, 42 }, 43 }, 44 &sub.UpdateResponse{}) 45 }