Commit 9239a1d1 authored by Brian Tiger Chow's avatar Brian Tiger Chow

shut down cleanly

parent a6eb3961
...@@ -4,10 +4,12 @@ import ( ...@@ -4,10 +4,12 @@ import (
"flag" "flag"
"log" "log"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
process "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
homedir "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir" homedir "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
fsnotify "github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1" fsnotify "github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1"
commands "github.com/jbenet/go-ipfs/commands" commands "github.com/jbenet/go-ipfs/commands"
...@@ -40,6 +42,8 @@ func main() { ...@@ -40,6 +42,8 @@ func main() {
} }
func run(ipfsPath, watchPath string) error { func run(ipfsPath, watchPath string) error {
proc := process.WithParent(process.Background())
log.Printf("running IPFSWatch on %s using repo at %s...", watchPath, ipfsPath) log.Printf("running IPFSWatch on %s using repo at %s...", watchPath, ipfsPath)
ipfsPath, err := homedir.Expand(ipfsPath) ipfsPath, err := homedir.Expand(ipfsPath)
...@@ -78,13 +82,20 @@ func run(ipfsPath, watchPath string) error { ...@@ -78,13 +82,20 @@ func run(ipfsPath, watchPath string) error {
corehttp.WebUIOption, corehttp.WebUIOption,
corehttp.CommandsOption(cmdCtx(node, ipfsPath)), corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
} }
if err := corehttp.ListenAndServe(node, maddr, opts...); err != nil { proc.Go(func(p process.Process) {
return nil if err := corehttp.ListenAndServe(node, maddr, opts...); err != nil {
} return
}
})
} }
interrupts := make(chan os.Signal)
signal.Notify(interrupts, os.Interrupt, os.Kill)
for { for {
select { select {
case <-interrupts:
return nil
case e := <-watcher.Events: case e := <-watcher.Events:
log.Printf("received event: %s", e) log.Printf("received event: %s", e)
isDir, err := IsDirectory(e.Name) isDir, err := IsDirectory(e.Name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment