Skip to content

Commit

Permalink
Set $PORT with env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim committed Aug 11, 2017
1 parent 6c1062d commit 4f0f27c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hivemind.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newHivemind(conf hivemindConfig) (h *hivemind) {

for i, entry := range entries {
if len(procNames) == 0 || stringsContain(procNames, entry.Name) {
h.procs = append(h.procs, newProcess(entry.Name, entry.Command, baseColor+i, conf.Root, h.output))
h.procs = append(h.procs, newProcess(entry.Name, entry.Command, baseColor+i, conf.Root, entry.Port, h.output))
}
}

Expand Down
4 changes: 3 additions & 1 deletion process.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"os/exec"
"syscall"
Expand All @@ -15,7 +16,7 @@ type process struct {
output *multiOutput
}

func newProcess(name, command string, color int, root string, output *multiOutput) (proc *process) {
func newProcess(name, command string, color int, root string, port int, output *multiOutput) (proc *process) {
proc = &process{
exec.Command("/bin/sh", "-c", command),
name,
Expand All @@ -24,6 +25,7 @@ func newProcess(name, command string, color int, root string, output *multiOutpu
}

proc.Dir = root
proc.Env = append(os.Environ(), fmt.Sprintf("PORT=%d", port))

proc.output.Connect(proc)

Expand Down
8 changes: 2 additions & 6 deletions procfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"bufio"
"os"
"regexp"
"strconv"
"strings"
)

type procfileEntry struct {
Name string
Command string
Port int
}

func parseProcfile(path string, portBase, portStep int) (entries []procfileEntry) {
Expand Down Expand Up @@ -40,10 +39,7 @@ func parseProcfile(path string, portBase, portStep int) (entries []procfileEntry
}
names[name] = true

entries = append(entries, procfileEntry{
name,
strings.Replace(cmd, "$PORT", strconv.Itoa(port), -1),
})
entries = append(entries, procfileEntry{name, cmd, port})

port += portStep
}
Expand Down

0 comments on commit 4f0f27c

Please sign in to comment.