/
restart.go
46 lines (37 loc) · 1017 Bytes
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"fmt"
"syscall"
"github.com/BitPonyLLC/huekeys/pkg/pidpath"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var restartCmd = &cobra.Command{
Use: "restart",
Short: "Tells remote process to restart",
RunE: func(cmd *cobra.Command, args []string) error {
if !waitPidPath.IsRunning() {
// don't fail here as this is invoked by post_install
return fail(0, "no remote process found")
}
if waitPidPath.IsOurs() {
log.Info().Msg("received request to restart")
cancelFunc()
return nil
}
menuPidPath = pidpath.NewPidPath(viper.GetString("menu.pidpath"), 0666)
if !menuPidPath.IsRunning() {
return sendMsgViaIPC(cmd, "quit")
}
log.Info().Str("menu", menuPidPath.String()).Msg("sending restart signal to menu")
err := syscall.Kill(menuPidPath.Getpid(), syscall.SIGHUP)
if err != nil {
return fmt.Errorf("unable to kill menu process: %w", err)
}
return nil
},
}
func init() {
rootCmd.AddCommand(restartCmd)
}