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 626B

12345678910111213141516171819202122232425262728293031
  1. // The Isomorphic Go Project
  2. // Copyright (c) Wirecog, LLC. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license, which can be found in the LICENSE file.
  5. // +build !windows
  6. package main
  7. import (
  8. "os"
  9. "os/exec"
  10. "syscall"
  11. )
  12. func start() *exec.Cmd {
  13. buildGopherJSProject()
  14. cmd := exec.Command("go", "run", appPath+"/"+mainSourceFile)
  15. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  16. cmd.Stdout = os.Stdout
  17. cmd.Stderr = os.Stderr
  18. cmd.Start()
  19. return cmd
  20. }
  21. func stop(cmd *exec.Cmd) {
  22. pgid, err := syscall.Getpgid(cmd.Process.Pid)
  23. if err == nil {
  24. syscall.Kill(-pgid, 15)
  25. }
  26. }