run_windows.go 881 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build windows
  2. package zdaemon
  3. import (
  4. "fmt"
  5. "os"
  6. "syscall"
  7. )
  8. func (zd *ZDaemon) makeIPCDir() {
  9. }
  10. func (zd *ZDaemon) cleanIPCUnixSock() {
  11. }
  12. func (zd *ZDaemon) start() {
  13. if zd.checkRunning() {
  14. fmt.Println("Already running. If you think it is dead, using 'restart' instead.")
  15. return
  16. }
  17. sa := &syscall.SysProcAttr{
  18. HideWindow: true,
  19. CmdLine: fmt.Sprintf("%s __run__", os.Args[0]),
  20. CreationFlags: 0,
  21. Token: 0,
  22. ProcessAttributes: nil,
  23. ThreadAttributes: nil,
  24. }
  25. p, err := os.StartProcess(os.Args[0], []string{"__run__"}, &os.ProcAttr{
  26. Dir: zd.programPath,
  27. Env: os.Environ(),
  28. Files: []*os.File{
  29. zd.programStdin,
  30. zd.programStdout,
  31. zd.programStderr,
  32. },
  33. Sys: sa,
  34. })
  35. if err != nil {
  36. fmt.Println("Failed start: ", err.Error())
  37. } else {
  38. fmt.Println("Daemon", zd.daemonName, "started. PID=", p.Pid)
  39. }
  40. }