Browse Source

"status" command, we track pids on processes

pull/55/head
Jae Kwon 10 years ago
parent
commit
40dc09701a
5 changed files with 50 additions and 6 deletions
  1. +12
    -2
      cmd/barak/main.go
  2. +1
    -0
      cmd/barak/types/responses.go
  3. +10
    -0
      cmd/debora/README.md
  4. +7
    -4
      cmd/debora/commands.go
  5. +20
    -0
      cmd/debora/main.go

+ 12
- 2
cmd/barak/main.go View File

@ -36,12 +36,20 @@ type Options struct {
// Global instance
var barak = struct {
mtx sync.Mutex
pid int
nonce uint64
processes map[string]*pcm.Process
validators []Validator
nonce uint64
}{sync.Mutex{}, make(map[string]*pcm.Process), nil, 0}
}{
mtx: sync.Mutex{},
pid: os.Getpid(),
nonce: 0,
processes: make(map[string]*pcm.Process),
validators: nil,
}
func main() {
fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())
// read options from stdin.
var err error
@ -77,11 +85,13 @@ func main() {
func Status() (*ResponseStatus, error) {
barak.mtx.Lock()
pid := barak.pid
nonce := barak.nonce
validators := barak.validators
barak.mtx.Unlock()
return &ResponseStatus{
Pid: pid,
Nonce: nonce,
Validators: validators,
}, nil


+ 1
- 0
cmd/barak/types/responses.go View File

@ -5,6 +5,7 @@ import (
)
type ResponseStatus struct {
Pid int
Nonce uint64
Validators []Validator
}


+ 10
- 0
cmd/debora/README.md View File

@ -0,0 +1,10 @@
### Example
```bash
# Upgrade barak.
# We need to give it a new seed to prevent port conflicts.
./build/debora --privkey-file build/privkey run --input "`cat cmd/barak/seed2`" -- barak2 ./build/barak
# Build tendermint from source
./build/debora --privkey-file build/privkey run -- build_tendermint bash -c "cd $GOPATH/src/github.com/tendermint/tendermint; make"
```

+ 7
- 4
cmd/debora/commands.go View File

@ -49,13 +49,16 @@ func ListProcesses(privKey acm.PrivKey, remote string, command btypes.CommandLis
// Utility method to get nonce from the remote.
// The next command should include the returned nonce+1 as nonce.
func GetNonce(remote string) (uint64, error) {
var err error
response := btypes.ResponseStatus{}
response, err := GetStatus(remote)
return response.Nonce, err
}
func GetStatus(remote string) (response btypes.ResponseStatus, err error) {
_, err = rpc.Call(remote, "status", Arr(), &response)
if err != nil {
return 0, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err)
return response, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err)
}
return response.Nonce, nil
return response, nil
}
// Each developer runs this


+ 20
- 0
cmd/debora/main.go View File

@ -53,6 +53,11 @@ func main() {
return nil
}
app.Commands = []cli.Command{
cli.Command{
Name: "status",
Usage: "shows remote status",
Action: cliGetStatus,
},
cli.Command{
Name: "run",
Usage: "run process",
@ -100,6 +105,21 @@ func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
return remotes, privKey
}
func cliGetStatus(c *cli.Context) {
args := c.Args()
if len(args) != 0 {
fmt.Println("BTW, status takes no arguments.")
}
for _, remote := range remotes {
response, err := GetStatus(remote)
if err != nil {
fmt.Printf("%v failure. %v\n", remote, err)
} else {
fmt.Printf("%v success. %v\n", remote, response)
}
}
}
func cliRunProcess(c *cli.Context) {
args := c.Args()
if len(args) < 2 {


Loading…
Cancel
Save