123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
- package zdaemon
- import (
- "fmt"
- "git.swzry.com/zry/pathutils"
- "os"
- "path"
- "syscall"
- )
- func (zd *ZDaemon) makeIPCDir() {
- _ = pathutils.MkDirIfNotExist(path.Join(zd.zdaemonPath, "ipc"), 0777)
- }
- func (zd *ZDaemon) cleanIPCUnixSock() {
- _ = os.RemoveAll(path.Join(zd.zdaemonPath, "ipc"))
- }
- func (zd *ZDaemon) start() {
- if zd.checkRunning() {
- fmt.Println("Already running. If you think it is dead, using 'restart' instead.")
- return
- }
- sa := &syscall.SysProcAttr{
- Chroot: "",
- Credential: nil,
- Ptrace: false,
- Setsid: false,
- Setpgid: false,
- Setctty: false,
- Noctty: false,
- Ctty: 0,
- Foreground: false,
- Pgid: 0,
- Pdeathsig: 0,
- Cloneflags: 0,
- Unshareflags: 0,
- UidMappings: nil,
- GidMappings: nil,
- GidMappingsEnableSetgroups: false,
- AmbientCaps: nil,
- }
- p, err := os.StartProcess(os.Args[0], []string{os.Args[0], "__run__"}, &os.ProcAttr{
- Dir: zd.programPath,
- Env: os.Environ(),
- Files: []*os.File{
- zd.programStdin,
- zd.programStdout,
- zd.programStderr,
- },
- Sys: sa,
- })
- if err != nil {
- fmt.Println("Failed start: ", err.Error())
- } else {
- fmt.Println("Daemon", zd.daemonName, "started. PID=", p.Pid)
- }
- }
|