@@ -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
1919func (c * FleetClient ) getUnits (target string ) (units []string , err error ) {
@@ -99,22 +99,33 @@ func NewDataUnit(component string, machineID string) (uf *unit.UnitFile, err err
9999func 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
108107func 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 }
0 commit comments