A lightweight mechanism to provide an *instant kickstart* to a Go web server instance upon changing any Go source files under the project directory (and its subdirectories).

startstop_unixlike.go 438B

1234567891011121314151617181920212223242526
  1. // +build !windows
  2. package main
  3. import (
  4. "os"
  5. "os/exec"
  6. "syscall"
  7. )
  8. func start() *exec.Cmd {
  9. buildGopherJSProject()
  10. cmd := exec.Command("go", "run", appPath+"/"+mainSourceFile)
  11. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  12. cmd.Stdout = os.Stdout
  13. cmd.Stderr = os.Stderr
  14. cmd.Start()
  15. return cmd
  16. }
  17. func stop(cmd *exec.Cmd) {
  18. pgid, err := syscall.Getpgid(cmd.Process.Pid)
  19. if err == nil {
  20. syscall.Kill(-pgid, 15)
  21. }
  22. }