Skip to content

Commit ccbffba

Browse files
authored
Merge pull request #350 from arangodb-helper/feature/use-local-bin-flag
Add server.use-local-bin CLI option
2 parents a98c254 + c6132af commit ccbffba

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [master](https://github.com/arangodb-helper/arangodb/tree/master) (N/A)
44
- Improve deprecated notice for old passthrough flags
5-
- Improve detection of arangod binary when running local installation
5+
- Improve detection of arangod binary when running local installation (use --server.use-local-bin)
66
- Upgrade base Alpine image and Go dependencies to fix CVEs
77

88
## [0.15.6](https://github.com/arangodb-helper/arangodb/tree/0.15.6) (2023-01-20)

main.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func init() {
166166
f.BoolSliceVar(&opts.cluster.startCoordinator, "cluster.start-coordinator", nil, "should a coordinator instance be started")
167167
f.BoolSliceVar(&opts.cluster.startActiveFailover, "cluster.start-single", nil, "should an active-failover single server instance be started")
168168

169+
f.BoolVar(&opts.server.useLocalBin, "server.use-local-bin", false, "If true, starter will try searching for binaries in local directory first")
169170
f.StringVar(&opts.server.arangodPath, "server.arangod", defaultArangodPath, "Path of arangod")
170171
f.StringVar(&opts.server.arangoSyncPath, "server.arangosync", defaultArangoSyncPath, "Path of arangosync")
171172
f.StringVar(&opts.server.arangodJSPath, "server.js-dir", "/usr/share/arangodb3/js", "Path of arango JS folder")
@@ -334,18 +335,18 @@ func slasher(s string) string {
334335
// findExecutable uses a platform dependent approach to find an executable
335336
// with given process name.
336337
func findExecutable(processName, defaultPath string) (executablePath string, isBuild bool) {
337-
var pathList = make([]string, 0, 10)
338-
pathList = append(pathList, "build/bin/"+processName)
339-
// Add local folder to search path
338+
var localPaths []string
340339
if exePath, err := os.Executable(); err == nil {
341340
folder := filepath.Dir(exePath)
342-
pathList = append(pathList, filepath.Join(folder, processName+filepath.Ext(exePath)))
341+
localPaths = append(localPaths, filepath.Join(folder, processName+filepath.Ext(exePath)))
343342

344343
// Also try searching in ../sbin in case if we are running from local installation
345344
if runtime.GOOS != "windows" {
346-
pathList = append(pathList, filepath.Join(folder, "../sbin", processName+filepath.Ext(exePath)))
345+
localPaths = append(localPaths, filepath.Join(folder, "../sbin", processName+filepath.Ext(exePath)))
347346
}
348347
}
348+
349+
var pathList []string
349350
switch runtime.GOOS {
350351
case "windows":
351352
// Look in the default installation location:
@@ -385,11 +386,22 @@ func findExecutable(processName, defaultPath string) (executablePath string, isB
385386
"/usr/local/sbin/"+processName,
386387
)
387388
}
389+
390+
if opts.server.useLocalBin {
391+
pathList = append(localPaths, pathList...)
392+
} else {
393+
pathList = append(pathList, localPaths...)
394+
}
395+
396+
// buildPath should be always first on the list
397+
buildPath := "build/bin/" + processName
398+
pathList = append([]string{buildPath}, pathList...)
399+
388400
// Search for the first path that exists.
389401
for _, p := range pathList {
390402
if _, e := os.Stat(filepath.Clean(filepath.FromSlash(p))); e == nil || !os.IsNotExist(e) {
391403
executablePath, _ = filepath.Abs(filepath.FromSlash(p))
392-
isBuild = p == "build/bin/arangod"
404+
isBuild = p == buildPath
393405
return
394406
}
395407
}

options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type starterOptions struct {
3838
startActiveFailover []bool
3939
}
4040
server struct {
41+
useLocalBin bool
4142
arangodPath string
4243
arangodJSPath string
4344
arangoSyncPath string

0 commit comments

Comments
 (0)