-
Notifications
You must be signed in to change notification settings - Fork 82
/
procfile.go
100 lines (78 loc) · 1.68 KB
/
procfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package start
import (
"fmt"
"os"
"regexp"
"syscall"
"github.com/DarthSim/overmind/v2/utils"
)
var procfileRe = regexp.MustCompile(`^([\w-]+):\s+(.+)$`)
type procfileEntry struct {
Name string
OrigName string
Command string
Port int
StopSignal syscall.Signal
}
type procfile []procfileEntry
func parseProcfile(procfile string, portBase, portStep int, formation map[string]int, formationPortStep int, stopSignals map[string]syscall.Signal) (pf procfile) {
f, err := os.Open(procfile)
utils.FatalOnErr(err)
port := portBase
names := make(map[string]bool)
err = utils.ScanLines(f, func(b []byte) bool {
if len(b) == 0 {
return true
}
params := procfileRe.FindStringSubmatch(string(b))
if len(params) != 3 {
return true
}
name, cmd := params[1], params[2]
num := 1
if fnum, ok := formation[name]; ok {
num = fnum
} else if fnum, ok := formation["all"]; ok {
num = fnum
}
signal := syscall.SIGINT
if s, ok := stopSignals[name]; ok {
signal = s
}
for i := 0; i < num; i++ {
iname := name
if num > 1 {
iname = fmt.Sprintf("%s#%d", name, i+1)
}
if names[iname] {
utils.Fatal("Process names must be unique")
}
names[iname] = true
pf = append(
pf,
procfileEntry{
Name: iname,
OrigName: name,
Command: cmd,
Port: port + (i * formationPortStep),
StopSignal: signal,
},
)
}
port += portStep
return true
})
utils.FatalOnErr(err)
if len(pf) == 0 {
utils.Fatal("No entries were found in Procfile")
}
return
}
func (p procfile) MaxNameLength() (nl int) {
for _, e := range p {
if l := len(e.Name); nl < l {
nl = l
}
}
return
}