github.com/Cloud-Foundations/Dominator@v0.3.4/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 trg := triggers.Trigger{ 27 MatchLines: []string{tmpPathname}, 28 Service: serviceName, 29 } 30 if serviceName == "reboot" { 31 trg.DoReboot = true 32 } 33 return client.CallUpdate(srpcClient, sub.UpdateRequest{ 34 Wait: true, 35 InodesToMake: []sub.Inode{ 36 { 37 Name: tmpPathname, 38 GenericInode: &filesystem.RegularInode{}, 39 }, 40 }, 41 PathsToDelete: []string{tmpPathname}, 42 Triggers: &triggers.Triggers{ 43 Triggers: []*triggers.Trigger{&trg}, 44 }, 45 }, 46 &sub.UpdateResponse{}) 47 }