src/amp/amp/run.go |
| ... | ... | @@ -12,7 +12,7 @@ import ( |
| 12 | 12 | "time" |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | | -func runProcess(amp, cmd, path, config string, console bool) { |
| 15 | +func runProcess(amp, cmd, path, config string, console bool, quit chan bool) { |
| 16 | 16 | |
| 17 | 17 | var files []*os.File |
| 18 | 18 | |
| ... | ... | @@ -39,9 +39,25 @@ func runProcess(amp, cmd, path, config string, console bool) { |
| 39 | 39 | if err != nil { |
| 40 | 40 | runtime.StandardError(err) |
| 41 | 41 | } |
| 42 | + |
| 43 | + quit <- true |
| 44 | + |
| 42 | 45 | } |
| 43 | 46 | |
| 44 | | -func run(argv []string, usage string) { |
| 47 | +func ensureDirectory(root, path string) (directory string) { |
| 48 | + if path == "" { |
| 49 | + directory = root |
| 50 | + } else { |
| 51 | + directory = runtime.JoinPath(root, path) |
| 52 | + } |
| 53 | + _, err := os.Open(directory) |
| 54 | + if err != nil { |
| 55 | + runtime.StandardError(err) |
| 56 | + } |
| 57 | + return |
| 58 | +} |
| 59 | + |
| 60 | +func ampRun(argv []string, usage string) { |
| 45 | 61 | |
| 46 | 62 | opts := optparse.Parser( |
| 47 | 63 | "Usage: amp run <instance-path> [options]\n\n " + usage + "\n") |
| ... | ... | @@ -49,11 +65,17 @@ func run(argv []string, usage string) { |
| 49 | 65 | profile := opts.String([]string{"--profile"}, "development", |
| 50 | 66 | "the config profile to use [development]", "NAME") |
| 51 | 67 | |
| 52 | | - frontendPath := opts.String([]string{"--frontend"}, "frontend", |
| 53 | | - "the path to the frontend directory [frontend]", "PATH") |
| 68 | + repoPath := opts.String([]string{"--repo"}, "repo", |
| 69 | + "the path to the amp repo directory [repo]", "PATH") |
| 70 | + |
| 71 | + storePath := opts.String([]string{"--store"}, "store", |
| 72 | + "the path to the amp store directory [store]", "PATH") |
| 54 | 73 | |
| 55 | 74 | nodePath := opts.String([]string{"--node"}, "node", |
| 56 | | - "the path to the node directory [node]", "PATH") |
| 75 | + "the path to the amp node directory [node]", "PATH") |
| 76 | + |
| 77 | + frontendPath := opts.String([]string{"--frontend"}, "frontend", |
| 78 | + "the path to the amp frontend directory [frontend]", "PATH") |
| 57 | 79 | |
| 58 | 80 | noConsoleLog := opts.Bool([]string{"--no-console-log"}, false, |
| 59 | 81 | "disable output to stdout/stderr") |
| ... | ... | @@ -70,44 +92,29 @@ func run(argv []string, usage string) { |
| 70 | 92 | runtime.StandardError(err) |
| 71 | 93 | } |
| 72 | 94 | |
| 73 | | - _, err = os.Open(root) |
| 74 | | - if err != nil { |
| 75 | | - runtime.StandardError(err) |
| 76 | | - } |
| 77 | | - |
| 78 | | - frontendDirectory := runtime.JoinPath(root, *frontendPath) |
| 79 | | - _, err = os.Open(frontendDirectory) |
| 80 | | - if err != nil { |
| 81 | | - runtime.StandardError(err) |
| 82 | | - } |
| 83 | | - |
| 84 | | - nodeDirectory := runtime.JoinPath(root, *nodePath) |
| 85 | | - _, err = os.Open(nodeDirectory) |
| 86 | | - if err != nil { |
| 87 | | - runtime.StandardError(err) |
| 88 | | - } |
| 89 | | - |
| 90 | 95 | amp, err := exec.LookPath("amp") |
| 91 | 96 | if err != nil { |
| 92 | 97 | runtime.StandardError(err) |
| 93 | 98 | } |
| 94 | 99 | |
| 95 | | - runtime.Init() |
| 96 | 100 | config := *profile + ".yaml" |
| 101 | + console := !*noConsoleLog |
| 102 | + quit := make(chan bool, 1) |
| 97 | 103 | |
| 98 | | - console := true |
| 99 | | - if *noConsoleLog { |
| 100 | | - console = false |
| 104 | + runtime.Init() |
| 105 | + ensureDirectory(root, "") |
| 106 | + |
| 107 | + for _, spec := range [][]string{ |
| 108 | + {"repo", ensureDirectory(root, *repoPath)}, |
| 109 | + {"store", ensureDirectory(root, *storePath)}, |
| 110 | + {"node", ensureDirectory(root, *nodePath)}, |
| 111 | + {"frontend", ensureDirectory(root, *frontendPath)}, |
| 112 | + } { |
| 113 | + go runProcess(amp, spec[0], spec[1], config, console, quit) |
| 114 | + <-time.After(2000000000) |
| 101 | 115 | } |
| 102 | 116 | |
| 103 | | - go runProcess(amp, "frontend", frontendDirectory, config, console) |
| 104 | | - |
| 105 | | - <-time.After(2000000000) |
| 106 | | - |
| 107 | | - go runProcess(amp, "node", nodeDirectory, config, console) |
| 108 | | - |
| 109 | 117 | // Enter the wait loop for the process to be killed. |
| 110 | | - loopForever := make(chan bool, 1) |
| 111 | | - <-loopForever |
| 118 | + <-quit |
| 112 | 119 | |
| 113 | 120 | } |