open-nomad/helper/subproc/self.go
2023-04-10 15:36:59 +00:00

38 lines
722 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package subproc
import (
"fmt"
"os"
"os/exec"
"strings"
)
var (
// executable is the executable of this process
executable string
)
func init() {
s, err := os.Executable()
if err != nil {
panic(fmt.Sprintf("failed to detect executable: %v", err))
}
// when running tests, we need to use the real nomad binary,
// and make sure you recompile between changes!
if strings.HasSuffix(s, ".test") {
if s, err = exec.LookPath("nomad"); err != nil {
panic(fmt.Sprintf("failed to find nomad binary: %v", err))
}
}
executable = s
}
// Self returns the path to the executable of this process.
func Self() string {
return executable
}