Browse Source

Quit upgrade_barak script upon error

pull/102/head
Jae Kwon 10 years ago
parent
commit
cc3a76f6c8
4 changed files with 57 additions and 12 deletions
  1. +2
    -2
      cmd/barak/main.go
  2. +40
    -0
      cmd/debora/main.go
  3. +4
    -2
      scripts/unsafe_debug_net.sh
  4. +11
    -8
      scripts/unsafe_upgrade_barak.sh

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

@ -86,7 +86,7 @@ func Run(authCommand AuthCommand) (interface{}, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Info(Fmt("Run() received command %v:\n%v", reflect.TypeOf(command), command))
log.Info(Fmt("Run() received command %v:%v", reflect.TypeOf(command), command))
// Issue command // Issue command
switch c := command.(type) { switch c := command.(type) {
case CommandStartProcess: case CommandStartProcess:
@ -162,7 +162,7 @@ func StartProcess(wait bool, label string, execPath string, args []string, input
if wait { if wait {
<-proc.WaitCh <-proc.WaitCh
output := pcm.ReadOutput(proc) output := pcm.ReadOutput(proc)
fmt.Println("Read output", output)
// fmt.Println("Read output", output)
if proc.ExitState == nil { if proc.ExitState == nil {
return &ResponseStartProcess{ return &ResponseStartProcess{
Success: true, Success: true,


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

@ -145,12 +145,14 @@ func cliGetStatus(c *cli.Context) {
fmt.Println("BTW, status takes no arguments.") fmt.Println("BTW, status takes no arguments.")
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := GetStatus(remote) response, err := GetStatus(remote)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success. %v\n", remote, response) fmt.Printf("%v success. %v\n", remote, response)
@ -158,6 +160,9 @@ func cliGetStatus(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliStartProcess(c *cli.Context) { func cliStartProcess(c *cli.Context) {
@ -175,12 +180,14 @@ func cliStartProcess(c *cli.Context) {
Input: c.String("input"), Input: c.String("input"),
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := StartProcess(Config.PrivKey, remote, command) response, err := StartProcess(Config.PrivKey, remote, command)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success.\n", remote) fmt.Printf("%v success.\n", remote)
@ -195,6 +202,9 @@ func cliStartProcess(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliStopProcess(c *cli.Context) { func cliStopProcess(c *cli.Context) {
@ -208,12 +218,14 @@ func cliStopProcess(c *cli.Context) {
Kill: true, Kill: true,
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := StopProcess(Config.PrivKey, remote, command) response, err := StopProcess(Config.PrivKey, remote, command)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success. %v\n", remote, response) fmt.Printf("%v success. %v\n", remote, response)
@ -221,6 +233,9 @@ func cliStopProcess(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliListProcesses(c *cli.Context) { func cliListProcesses(c *cli.Context) {
@ -233,12 +248,14 @@ func cliListProcesses(c *cli.Context) {
*/ */
command := btypes.CommandListProcesses{} command := btypes.CommandListProcesses{}
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := ListProcesses(Config.PrivKey, remote, command) response, err := ListProcesses(Config.PrivKey, remote, command)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", Blue(remote), Red(err)) fmt.Printf("%v failure. %v\n", Blue(remote), Red(err))
} else { } else {
fmt.Printf("%v processes:\n", Blue(remote)) fmt.Printf("%v processes:\n", Blue(remote))
@ -257,6 +274,9 @@ func cliListProcesses(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliOpenListener(c *cli.Context) { func cliOpenListener(c *cli.Context) {
@ -269,12 +289,14 @@ func cliOpenListener(c *cli.Context) {
Addr: listenAddr, Addr: listenAddr,
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := OpenListener(Config.PrivKey, remote, command) response, err := OpenListener(Config.PrivKey, remote, command)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v opened %v.\n", remote, response.Addr) fmt.Printf("%v opened %v.\n", remote, response.Addr)
@ -282,6 +304,9 @@ func cliOpenListener(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliCloseListener(c *cli.Context) { func cliCloseListener(c *cli.Context) {
@ -294,12 +319,14 @@ func cliCloseListener(c *cli.Context) {
Addr: listenAddr, Addr: listenAddr,
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := CloseListener(Config.PrivKey, remote, command) response, err := CloseListener(Config.PrivKey, remote, command)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success. %v\n", remote, response) fmt.Printf("%v success. %v\n", remote, response)
@ -307,6 +334,9 @@ func cliCloseListener(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliDownloadFile(c *cli.Context) { func cliDownloadFile(c *cli.Context) {
@ -321,12 +351,14 @@ func cliDownloadFile(c *cli.Context) {
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string, localPath string) { go func(remote string, localPath string) {
defer wg.Done() defer wg.Done()
n, err := DownloadFile(Config.PrivKey, remote, command, localPath) n, err := DownloadFile(Config.PrivKey, remote, command, localPath)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success. Wrote %v bytes to %v\n", remote, n, localPath) fmt.Printf("%v success. Wrote %v bytes to %v\n", remote, n, localPath)
@ -334,17 +366,22 @@ func cliDownloadFile(c *cli.Context) {
}(remote, Fmt("%v_%v", localPathPrefix, remoteNick(remote))) }(remote, Fmt("%v_%v", localPathPrefix, remoteNick(remote)))
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }
func cliQuit(c *cli.Context) { func cliQuit(c *cli.Context) {
command := btypes.CommandQuit{} command := btypes.CommandQuit{}
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
failed := 0
for _, remote := range Config.Remotes { for _, remote := range Config.Remotes {
wg.Add(1) wg.Add(1)
go func(remote string) { go func(remote string) {
defer wg.Done() defer wg.Done()
response, err := Quit(Config.PrivKey, remote, command) response, err := Quit(Config.PrivKey, remote, command)
if err != nil { if err != nil {
failed++
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success. %v\n", remote, response) fmt.Printf("%v success. %v\n", remote, response)
@ -352,4 +389,7 @@ func cliQuit(c *cli.Context) {
}(remote) }(remote)
} }
wg.Wait() wg.Wait()
if 0 < failed {
os.Exit(1)
}
} }

+ 4
- 2
scripts/unsafe_debug_net.sh View File

@ -1,10 +1,12 @@
#!/bin/sh
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; killall tendermint" debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; killall tendermint"
debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; tendermint unsafe_reset_priv_validator; rm -rf ~/.tendermint/data" debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; tendermint unsafe_reset_priv_validator; rm -rf ~/.tendermint/data"
debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; git pull origin develop; make" debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; git pull origin develop; make"
debora run --bg --label tendermint -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; tendermint node" debora run --bg --label tendermint -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; tendermint node"
echo "sleeping for a minute"
printf "\n\nSleeping for a minute"
sleep 60 sleep 60
debora download tendermint "logs/async$1" debora download tendermint "logs/async$1"
debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; killall tendermint" debora run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; killall tendermint"

+ 11
- 8
scripts/unsafe_upgrade_barak.sh View File

@ -1,15 +1,18 @@
#!/bin/sh
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
debora open "[::]:46661" debora open "[::]:46661"
debora --group default.upgrade list # TODO replace with command to test with
echo "Will shut down barak default port..."
sleep 10
debora --group default.upgrade status
printf "\n\nWill shut down barak default port..."
sleep 3
debora --group default.upgrade close "[::]:46660" debora --group default.upgrade close "[::]:46660"
debora --group default.upgrade run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; git pull origin develop; make" debora --group default.upgrade run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; git pull origin develop; make"
debora --group default.upgrade run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; mkdir -p ~/.barak/logs" debora --group default.upgrade run -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; mkdir -p ~/.barak/logs"
debora --group default.upgrade run --bg --label barak -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; barak --config=cmd/barak/seed | stdinwriter -outpath ~/.barak/logs/barak.log" debora --group default.upgrade run --bg --label barak -- bash -c "cd \$GOPATH/src/github.com/tendermint/tendermint; barak --config=cmd/barak/seed | stdinwriter -outpath ~/.barak/logs/barak.log"
echo "Testing new barak..."
debora list
sleep 10
echo "Will shut down old barak..."
printf "\n\nTesting new barak..."
debora status
sleep 3
printf "\n\nWill shut down old barak..."
debora --group default.upgrade quit debora --group default.upgrade quit
printf "Done!"

Loading…
Cancel
Save