@cryptotaxi247 / kubo / commits / 9239a1d11

shut down cleanly

Brian Tiger Chow committed Jan 22, 2015 at 01:43 UTC 9239a1d11d57d4d91e75b357cf70af5dde775fa2
1 file changed +14 -3
cmd/ipfswatch/main.go
+14 -3
@@ -4,10 +4,12 @@ import (
4 "flag"
5 "log"
6 "os"
7 + "os/signal"
8 "path/filepath"
9
10 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
11 ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
12 + process "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
13 homedir "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
14 fsnotify "github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1"
15 commands "github.com/jbenet/go-ipfs/commands"
@@ -40,6 +42,8 @@ func main() {
42 }
43
44 func run(ipfsPath, watchPath string) error {
45 +
46 + proc := process.WithParent(process.Background())
47 log.Printf("running IPFSWatch on %s using repo at %s...", watchPath, ipfsPath)
48
49 ipfsPath, err := homedir.Expand(ipfsPath)
@@ -78,13 +82,20 @@ func run(ipfsPath, watchPath string) error {
82 corehttp.WebUIOption,
83 corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
84 }
81 - if err := corehttp.ListenAndServe(node, maddr, opts...); err != nil {
82 - return nil
83 - }
85 + proc.Go(func(p process.Process) {
86 + if err := corehttp.ListenAndServe(node, maddr, opts...); err != nil {
87 + return
88 + }
89 + })
90 }
91
92 + interrupts := make(chan os.Signal)
93 + signal.Notify(interrupts, os.Interrupt, os.Kill)
94 +
95 for {
96 select {
97 + case <-interrupts:
98 + return nil
99 case e := <-watcher.Events:
100 log.Printf("received event: %s", e)
101 isDir, err := IsDirectory(e.Name)