Add support /api/restart #652

This commit is contained in:
Alex X
2023-10-09 17:11:57 +03:00
parent b252fcaaa1
commit 9a2e9dd6d1
3 changed files with 27 additions and 1 deletions
+15
View File
@@ -2,7 +2,9 @@ package shell
import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"regexp"
"strings"
"syscall"
@@ -75,3 +77,16 @@ func RunUntilSignal() {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
println("exit with signal:", (<-sigs).String())
}
func Restart() {
path, err := exec.LookPath(os.Args[0])
if err != nil {
return
}
path, err = filepath.Abs(path)
if err != nil {
return
}
path = filepath.Clean(path)
_ = syscall.Exec(path, os.Args, os.Environ())
}