Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
d0380b73
Commit
d0380b73
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
const for lock file, + fix unreachable Close
parent
508a5b7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
daemon/daemon.go
daemon/daemon.go
+10
-2
daemon/daemon_client.go
daemon/daemon_client.go
+6
-7
No files found.
daemon/daemon.go
View file @
d0380b73
...
...
@@ -6,11 +6,12 @@ import (
"io"
"net"
"os"
"path"
core
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/commands"
u
"github.com/jbenet/go-ipfs/util"
"github.com/op/go-logging"
logging
"github.com/op/go-logging"
"github.com/camlistore/lock"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
...
...
@@ -18,6 +19,9 @@ import (
var
log
=
logging
.
MustGetLogger
(
"daemon"
)
// LockFile is the filename of the daemon lock, relative to config dir
const
LockFile
=
"daemon.lock"
// DaemonListener listens to an initialized IPFS node and can send it commands instead of
// starting up a new set of connections
type
DaemonListener
struct
{
...
...
@@ -41,7 +45,7 @@ func NewDaemonListener(ipfsnode *core.IpfsNode, addr *ma.Multiaddr, confdir stri
return
nil
,
err
}
lk
,
err
:=
lock
.
Lock
(
confdir
+
"/daemon.lock"
)
lk
,
err
:=
daemon
Lock
(
confdir
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -133,3 +137,7 @@ func (dl *DaemonListener) Close() error {
dl
.
closed
=
true
return
dl
.
list
.
Close
()
}
func
daemonLock
(
confdir
string
)
(
io
.
Closer
,
error
)
{
return
lock
.
Lock
(
path
.
Join
(
confdir
,
LockFile
))
}
This diff is collapsed.
Click to expand it.
daemon/daemon_client.go
View file @
d0380b73
...
...
@@ -8,7 +8,6 @@ import (
"net"
"os"
lock
"github.com/camlistore/lock"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -43,10 +42,10 @@ func getDaemonAddr(confdir string) (string, error) {
return
string
(
line
),
nil
}
// SendCommand
issues a command (of type daemon.Command) to the daemon, if it
//
is running (if not, errors out). This is done over network RPC API. Th
e
// address of the daemon is retrieved from the config
uration directory, where
// live daemons write their addresses to special files.
// SendCommand
attempts to run the command over a currently-running daemon.
//
If there is no running daemon, returns ErrDaemonNotRunning. This is don
e
//
over network RPC API. The
address of the daemon is retrieved from the config
//
directory, where
live daemons write their addresses to special files.
func
SendCommand
(
command
*
Command
,
confdir
string
)
error
{
//check if daemon is running
log
.
Info
(
"Checking if daemon is running..."
)
...
...
@@ -55,10 +54,10 @@ func SendCommand(command *Command, confdir string) error {
if
err
!=
nil
{
return
err
}
lk
,
err
:=
lock
.
Lock
(
confdir
+
"/daemon.lock"
)
lk
,
err
:=
daemon
Lock
(
confdir
)
if
err
==
nil
{
return
ErrDaemonNotRunning
lk
.
Close
()
return
ErrDaemonNotRunning
}
log
.
Info
(
"Daemon is running! %s"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment