Skip to content

Add server.use-local-bin CLI option #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## [0.15.6](https://github.com/arangodb-helper/arangodb/tree/0.15.6) (2023-01-20)
Expand Down
24 changes: 18 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func init() {
f.BoolSliceVar(&opts.cluster.startCoordinator, "cluster.start-coordinator", nil, "should a coordinator instance be started")
f.BoolSliceVar(&opts.cluster.startActiveFailover, "cluster.start-single", nil, "should an active-failover single server instance be started")

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

// Also try searching in ../sbin in case if we are running from local installation
if runtime.GOOS != "windows" {
pathList = append(pathList, filepath.Join(folder, "../sbin", processName+filepath.Ext(exePath)))
localPaths = append(localPaths, filepath.Join(folder, "../sbin", processName+filepath.Ext(exePath)))
}
}

var pathList []string
switch runtime.GOOS {
case "windows":
// Look in the default installation location:
Expand Down Expand Up @@ -385,11 +386,22 @@ func findExecutable(processName, defaultPath string) (executablePath string, isB
"/usr/local/sbin/"+processName,
)
}

if opts.server.useLocalBin {
pathList = append(localPaths, pathList...)
} else {
pathList = append(pathList, localPaths...)
}

// buildPath should be always first on the list
buildPath := "build/bin/" + processName
pathList = append([]string{buildPath}, pathList...)

// Search for the first path that exists.
for _, p := range pathList {
if _, e := os.Stat(filepath.Clean(filepath.FromSlash(p))); e == nil || !os.IsNotExist(e) {
executablePath, _ = filepath.Abs(filepath.FromSlash(p))
isBuild = p == "build/bin/arangod"
isBuild = p == buildPath
return
}
}
Expand Down
1 change: 1 addition & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type starterOptions struct {
startActiveFailover []bool
}
server struct {
useLocalBin bool
arangodPath string
arangodJSPath string
arangoSyncPath string
Expand Down