Skip to content

Commit cba85ee

Browse files
author
Gabriel Monroy
committed
fix(units): use default GOPATH for unit lookup, if available
1 parent da443aa commit cba85ee

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

client/unit.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// path hierarchy for finding systemd service templates
16-
var rootPaths = []string{"/var/lib/deis/units", "units", "../units"}
16+
var rootPaths = []string{"/var/lib/deis/units", "units"}
1717

1818
// getUnits returns a list of units filtered by target
1919
func (c *FleetClient) getUnits(target string) (units []string, err error) {
@@ -99,22 +99,33 @@ func NewDataUnit(component string, machineID string) (uf *unit.UnitFile, err err
9999
func formatUnitName(component string, num int) (unitName string, err error) {
100100
if num == 0 {
101101
return "deis-" + component + ".service", nil
102-
} else {
103-
return "deis-" + component + "@" + strconv.Itoa(num) + ".service", nil
104102
}
103+
return "deis-" + component + "@" + strconv.Itoa(num) + ".service", nil
105104
}
106105

107106
// readTemplate returns the contents of a systemd template for the given component
108107
func readTemplate(component string) (out []byte, err error) {
109108
templateName := "deis-" + component + ".service"
110109
var templateFile string
111-
for _, rootPath := range rootPaths {
112-
filename := path.Join(rootPath, templateName)
110+
111+
// first look for unit files in GOPATH
112+
if os.Getenv("GOPATH") != "" {
113+
filename := path.Join(os.Getenv("GOPATH"),
114+
path.Join("src", "github.com", "deis", "deisctl", "units", templateName))
113115
if _, err := os.Stat(filename); err == nil {
114116
templateFile = filename
115-
break
117+
}
118+
} else {
119+
// otherwise look in rootPaths hierarchy
120+
for _, rootPath := range rootPaths {
121+
filename := path.Join(rootPath, templateName)
122+
if _, err := os.Stat(filename); err == nil {
123+
templateFile = filename
124+
break
125+
}
116126
}
117127
}
128+
118129
if templateFile == "" {
119130
return nil, fmt.Errorf("Could not find unit template for %v", component)
120131
}

deisctl.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ Example Commands:
7777
7878
deisctl install
7979
deisctl uninstall
80-
deisctl list-units
81-
deisctl list-unit-files
80+
deisctl list
8281
deisctl scale router=2
8382
deisctl start router@2
8483
deisctl stop router builder

0 commit comments

Comments
 (0)