Automatically restart after unexpected errors

This commit is contained in:
Frank Denis 2018-07-01 23:06:28 +02:00
parent f9b6994fd2
commit 73a43b31b9
1 changed files with 12 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import (
"path/filepath"
"strconv"
"syscall"
"time"
"github.com/jedisct1/dlog"
)
@ -40,15 +41,18 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
args = args[1:]
args = append(args, "-child")
cmd := exec.Command(path, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.ExtraFiles = fds
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
dlog.Notice("Dropping privileges")
if err := cmd.Run(); err != nil {
dlog.Fatal(err)
for {
cmd := exec.Command(path, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.ExtraFiles = fds
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
if cmd.Run() == nil {
break
}
time.Sleep(1 * time.Second)
}
os.Exit(0)
}