This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
/
processes.go
106 lines (89 loc) · 1.85 KB
/
processes.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
101
102
103
104
105
106
package hsup
import (
"errors"
"io"
"log"
"net/url"
"os"
"runtime"
"strings"
"bitbucket.org/kardianos/osext"
)
var ErrNoReleases = errors.New("No releases found")
type Notifier interface {
Notify() <-chan *Processes
}
type Processes struct {
Rel *Release
Forms []Formation
Dd DynoDriver
OneShot bool
Executors []*Executor
LogplexURL *url.URL
}
type Formation interface {
Args() []string
Quantity() int
Type() string
}
func linuxAmd64Path() string {
exe, err := osext.Executable()
if err != nil {
log.Fatalln("could not locate own executable:", err)
}
if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
return exe
}
return exe + "-linux-amd64"
}
func copyFile(src, dst string, mode os.FileMode) (err error) {
r, err := os.Open(src)
if err != nil {
return err
}
defer func() {
err = combine(err, r.Close())
}()
w, err := os.Create(dst)
if err != nil {
return err
}
defer func() {
err = combine(err, w.Close())
}()
if _, err := io.Copy(w, r); err != nil {
return err
}
if err := os.Chmod(dst, mode); err != nil {
return err
}
return nil
}
type combinedError []error
// combine needs to return error, not a combinedError, otherwise nil errors
// aren't going to be treated as nil. More details:
// http://golang.org/doc/faq#nil_error
func combine(errors ...error) error {
errors = make(combinedError, 0, len(errors))
for _, err := range errors {
if err == nil {
continue
}
errors = append(errors, err)
}
if len(errors) == 0 {
return nil // important so that callers can do if err == nil
}
return combinedError(errors)
}
// Error implements the error interface
func (e combinedError) Error() string {
msgs := make([]string, len(e))
for i, entry := range e {
msgs[i] = entry.Error()
}
return strings.Join(msgs, " | ")
}
func (e combinedError) String() string {
return e.Error()
}