feat: support to suspend

This commit is contained in:
mzz2017
2023-03-14 00:34:38 +08:00
parent ea568ebce5
commit 2b25e789db
9 changed files with 144 additions and 27 deletions

View File

@ -6,26 +6,42 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/v2rayA/dae/cmd/internal"
"os"
"strconv"
"strings"
"syscall"
)
var (
reloadCmd = &cobra.Command{
Use: "reload pid",
Use: "reload [pid]",
Run: func(cmd *cobra.Command, args []string) {
internal.AutoSu()
if len(args) == 0 {
cmd.Help()
os.Exit(1)
_pid, err := os.ReadFile(PidFilePath)
if err != nil {
fmt.Println("Failed to read pid file:", err)
os.Exit(1)
}
args = []string{strings.TrimSpace(string(_pid))}
}
pid, err := strconv.Atoi(args[0])
if err != nil {
cmd.Help()
os.Exit(1)
}
syscall.Kill(pid, syscall.SIGUSR1)
if err = syscall.Kill(pid, syscall.SIGUSR1); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("OK")
},
}
)
func init() {
rootCmd.AddCommand(reloadCmd)
}