mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-31 21:27:04 +00:00
Run process
This commit is contained in:
+8
-2
@@ -155,9 +155,14 @@ func RunProcess(wait bool, label string, execPath string, args []string, input s
|
||||
}
|
||||
|
||||
// Otherwise, create one.
|
||||
proc := pcm.Create(pcm.ProcessModeDaemon, label, execPath, args, input)
|
||||
barak.processes[label] = proc
|
||||
proc, err := pcm.Create(pcm.ProcessModeDaemon, label, execPath, args, input)
|
||||
if err == nil {
|
||||
barak.processes[label] = proc
|
||||
}
|
||||
barak.mtx.Unlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if wait {
|
||||
exitErr := pcm.Wait(proc)
|
||||
@@ -183,6 +188,7 @@ func StopProcess(label string, kill bool) (*ResponseStopProcess, error) {
|
||||
func ListProcesses() (*ResponseListProcesses, error) {
|
||||
var procs = []*pcm.Process{}
|
||||
barak.mtx.Lock()
|
||||
fmt.Println("Processes: %v", barak.processes)
|
||||
for _, proc := range barak.processes {
|
||||
procs = append(procs, proc)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@ import (
|
||||
"github.com/tendermint/tendermint/rpc"
|
||||
)
|
||||
|
||||
// These are convenience functions for a single developer.
|
||||
// When multiple are involved, the workflow is different.
|
||||
// (First the command(s) are signed by all validators,
|
||||
// and then it is broadcast).
|
||||
|
||||
func RunProcess(privKey acm.PrivKey, remote string, command btypes.CommandRunProcess) (response btypes.ResponseRunProcess, err error) {
|
||||
nonce, err := GetNonce(remote)
|
||||
if err != nil {
|
||||
|
||||
+42
-21
@@ -26,6 +26,15 @@ var (
|
||||
Value: "privkey",
|
||||
Usage: "file containing private key json",
|
||||
}
|
||||
waitFlag = cli.BoolFlag{
|
||||
Name: "wait",
|
||||
Usage: "whether to wait for termination",
|
||||
}
|
||||
inputFlag = cli.StringFlag{
|
||||
Name: "input",
|
||||
Value: "",
|
||||
Usage: "input to the program (e.g. stdin)",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -48,9 +57,9 @@ func main() {
|
||||
Name: "run",
|
||||
Usage: "run process",
|
||||
Action: cliRunProcess,
|
||||
Flags: []cli.Flag{
|
||||
//remotesFlag,
|
||||
//privKeyFlag,
|
||||
Flags: []cli.Flag{
|
||||
waitFlag,
|
||||
inputFlag,
|
||||
},
|
||||
},
|
||||
cli.Command{
|
||||
@@ -81,7 +90,8 @@ func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
|
||||
privkeyFile := c.String("privkey-file")
|
||||
privkeyJSONBytes, err := ioutil.ReadFile(privkeyFile)
|
||||
if err != nil {
|
||||
Exit(Fmt("Failed to read privkey from file %v. %v", privkeyFile, err))
|
||||
fmt.Printf("Failed to read privkey from file %v. %v", privkeyFile, err)
|
||||
return remotes, nil
|
||||
}
|
||||
binary.ReadJSON(&privKey, privkeyJSONBytes, &err)
|
||||
if err != nil {
|
||||
@@ -91,14 +101,20 @@ func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
|
||||
}
|
||||
|
||||
func cliRunProcess(c *cli.Context) {
|
||||
/*
|
||||
args := c.Args()
|
||||
if len(args) == 0 {
|
||||
log.Fatal("Must specify application name")
|
||||
}
|
||||
app := args[0]
|
||||
*/
|
||||
command := btypes.CommandRunProcess{}
|
||||
args := c.Args()
|
||||
if len(args) < 2 {
|
||||
Exit("Must specify <label> <execPath> <args...>")
|
||||
}
|
||||
label := args[0]
|
||||
execPath := args[1]
|
||||
args = args[2:]
|
||||
command := btypes.CommandRunProcess{
|
||||
Wait: c.Bool("wait"),
|
||||
Label: label,
|
||||
ExecPath: execPath,
|
||||
Args: args,
|
||||
Input: c.String("input"),
|
||||
}
|
||||
for _, remote := range remotes {
|
||||
response, err := RunProcess(privKey, remote, command)
|
||||
if err != nil {
|
||||
@@ -110,14 +126,14 @@ func cliRunProcess(c *cli.Context) {
|
||||
}
|
||||
|
||||
func cliStopProcess(c *cli.Context) {
|
||||
/*
|
||||
args := c.Args()
|
||||
if len(args) == 0 {
|
||||
log.Fatal("Must specify application name")
|
||||
}
|
||||
app := args[0]
|
||||
*/
|
||||
command := btypes.CommandStopProcess{}
|
||||
args := c.Args()
|
||||
if len(args) == 0 {
|
||||
Exit("Must specify label to stop")
|
||||
}
|
||||
label := args[0]
|
||||
command := btypes.CommandStopProcess{
|
||||
Label: label,
|
||||
}
|
||||
for _, remote := range remotes {
|
||||
response, err := StopProcess(privKey, remote, command)
|
||||
if err != nil {
|
||||
@@ -142,7 +158,12 @@ func cliListProcesses(c *cli.Context) {
|
||||
if err != nil {
|
||||
fmt.Printf("%v failure. %v\n", remote, err)
|
||||
} else {
|
||||
fmt.Printf("%v success: %v\n", remote, response)
|
||||
fmt.Printf("%v processes:\n", remote)
|
||||
for _, proc := range response.Processes {
|
||||
fmt.Printf(" \"%v\" => `%v` (%v) start:%v end:%v output:%v\n",
|
||||
proc.Label, proc.ExecPath, proc.Pid,
|
||||
proc.StartTime, proc.EndTime, proc.OutputPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user