respect the lock file, also cpu profile
Jeromy committed
Sep 23, 2014 at 01:22 UTC
e311ccbf4311f6e123804cf089a517017273948b
2 files changed
+27
-1
cmd/ipfs/ipfs.go
+10
-1
@@ -4,6 +4,7 @@ import (
4
"errors"
5
"fmt"
6
"os"
7
+ "runtime/pprof"
8
9
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
10
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
@@ -67,7 +68,15 @@ func ipfsCmd(c *commander.Command, args []string) error {
68
69
func main() {
70
u.Debug = true
70
- err := CmdIpfs.Dispatch(os.Args[1:])
71
+ ofi, err := os.Create("cpu.prof")
72
+ if err != nil {
73
+ fmt.Println(err)
74
+ return
75
+ }
76
+ pprof.StartCPUProfile(ofi)
77
+ defer ofi.Close()
78
+ defer pprof.StopCPUProfile()
79
+ err = CmdIpfs.Dispatch(os.Args[1:])
80
if err != nil {
81
if len(err.Error()) > 0 {
82
fmt.Fprintf(os.Stderr, "ipfs %s: %v\n", os.Args[1], err)
daemon/daemon_client.go
+17
@@ -8,7 +8,9 @@ import (
8
"net"
9
"os"
10
11
+ lock "github.com/camlistore/lock"
12
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
13
+
14
u "github.com/jbenet/go-ipfs/util"
15
)
16
@@ -46,6 +48,21 @@ func getDaemonAddr(confdir string) (string, error) {
48
// address of the daemon is retrieved from the configuration directory, where
49
// live daemons write their addresses to special files.
50
func SendCommand(command *Command, confdir string) error {
51
+ //check if daemon is running
52
+ log.Info("Checking if daemon is running...")
53
+ var err error
54
+ confdir, err = u.TildeExpansion(confdir)
55
+ if err != nil {
56
+ return err
57
+ }
58
+ lk, err := lock.Lock(confdir + "/daemon.lock")
59
+ if err == nil {
60
+ return ErrDaemonNotRunning
61
+ lk.Close()
62
+ }
63
+
64
+ log.Info("Daemon is running! %s", err)
65
+
66
server, err := getDaemonAddr(confdir)
67
if err != nil {
68
return err