Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
fix(units): use default GOPATH for unit lookup, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy committed Aug 25, 2014
1 parent da443aa commit cba85ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 17 additions & 6 deletions client/unit.go
Expand Up @@ -13,7 +13,7 @@ import (
)

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

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

// readTemplate returns the contents of a systemd template for the given component
func readTemplate(component string) (out []byte, err error) {
templateName := "deis-" + component + ".service"
var templateFile string
for _, rootPath := range rootPaths {
filename := path.Join(rootPath, templateName)

// first look for unit files in GOPATH
if os.Getenv("GOPATH") != "" {
filename := path.Join(os.Getenv("GOPATH"),
path.Join("src", "github.com", "deis", "deisctl", "units", templateName))
if _, err := os.Stat(filename); err == nil {
templateFile = filename
break
}
} else {
// otherwise look in rootPaths hierarchy
for _, rootPath := range rootPaths {
filename := path.Join(rootPath, templateName)
if _, err := os.Stat(filename); err == nil {
templateFile = filename
break
}
}
}

if templateFile == "" {
return nil, fmt.Errorf("Could not find unit template for %v", component)
}
Expand Down
3 changes: 1 addition & 2 deletions deisctl.go
Expand Up @@ -77,8 +77,7 @@ Example Commands:
deisctl install
deisctl uninstall
deisctl list-units
deisctl list-unit-files
deisctl list
deisctl scale router=2
deisctl start router@2
deisctl stop router builder
Expand Down

0 comments on commit cba85ee

Please sign in to comment.