本文整理汇总了Golang中github.com/kardianos/osext.Executable函数的典型用法代码示例。如果您正苦于以下问题:Golang Executable函数的具体用法?Golang Executable怎么用?Golang Executable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Executable函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: updateBinary
func updateBinary(v semver.Version, downloadBinary, updateLinkPrefix, downloadLinkFormat string) {
checksum, err := downloadChecksum(v, downloadBinary, downloadLinkFormat)
if err != nil {
glog.Errorf("Cannot download checksum: %s", err)
os.Exit(1)
}
binary, err := http.Get(fmt.Sprintf(downloadLinkFormat, v, downloadBinary))
if err != nil {
glog.Errorf("Cannot download binary: %s", err)
os.Exit(1)
}
defer binary.Body.Close()
err = update.Apply(binary.Body, update.Options{
Hash: crypto.SHA256,
Checksum: checksum,
})
if err != nil {
glog.Errorf("Cannot apply binary update: %s", err)
os.Exit(1)
}
env := os.Environ()
args := os.Args
currentBinary, err := osext.Executable()
if err != nil {
glog.Errorf("Cannot find current binary to exec: %s", err)
os.Exit(1)
}
err = syscall.Exec(currentBinary, args, env)
if err != nil {
glog.Errorf("Failed to exec updated binary: %s", err)
os.Exit(1)
}
}
开发者ID:gashcrumb,项目名称:gofabric8,代码行数:34,代码来源:update.go
示例2: updateCLI
func (u *updateCmd) updateCLI(e *env) (bool, error) {
downloadURL, err := u.getDownloadURL(e)
if err != nil {
return false, err
}
if downloadURL == "" {
return false, nil
}
exec, err := osext.Executable()
if err != nil {
return false, stackerr.Wrap(err)
}
fmt.Fprintf(e.Out, "Downloading binary from %s.\n", downloadURL)
resp, err := http.Get(downloadURL)
if err != nil {
return false, stackerr.Newf("Update failed with error: %v", err)
}
defer resp.Body.Close()
err = update.Apply(resp.Body, update.Options{TargetPath: exec})
if err != nil {
return false, stackerr.Newf("Update failed with error: %v", err)
}
fmt.Fprintf(e.Out, "Successfully updated binary at: %s\n", exec)
return true, nil
}
开发者ID:Georotzen,项目名称:parse-cli,代码行数:26,代码来源:update_cmd.go
示例3: Start
// Start starts the e2e services in another process, it returns when all e2e
// services are ready.
// We want to statically link e2e services into the test binary, but we don't
// want their glog to pollute the test result. So we run the binary in run-
// services-mode to start e2e services in another process.
func (e *E2EServices) Start() error {
var err error
// Create the manifest path for kubelet.
// TODO(random-liu): Remove related logic when we move kubelet starting logic out of the test.
framework.TestContext.ManifestPath, err = ioutil.TempDir("", "node-e2e-pod")
if err != nil {
return fmt.Errorf("failed to create static pod manifest directory: %v", err)
}
testBin, err := osext.Executable()
if err != nil {
return fmt.Errorf("can't get current binary: %v", err)
}
// TODO(random-liu): Add sudo after we statically link apiserver and etcd, because apiserver needs
// sudo. We can't add sudo now, because etcd may not be in PATH of root.
startCmd := exec.Command(testBin,
"--run-services-mode",
"--server-start-timeout", serverStartTimeout.String(),
"--report-dir", framework.TestContext.ReportDir,
// TODO(random-liu): Remove the following flags after we move kubelet starting logic
// out of the test.
"--node-name", framework.TestContext.NodeName,
"--disable-kubenet="+strconv.FormatBool(framework.TestContext.DisableKubenet),
// TODO: enable when flag is introduced in 1.5
// "--cgroups-per-qos="+strconv.FormatBool(framework.TestContext.CgroupsPerQOS),
"--manifest-path", framework.TestContext.ManifestPath,
"--eviction-hard", framework.TestContext.EvictionHard,
"--logtostderr",
"--vmodule=*=4",
)
e.services = newServer("services", startCmd, nil, nil, getHealthCheckURLs(), servicesLogFile, false)
return e.services.start()
}
开发者ID:titilambert,项目名称:kubernetes,代码行数:37,代码来源:services.go
示例4: CreateAgent
func CreateAgent() error {
path, err := osext.Executable()
if err != nil {
return err
}
fileDir := os.ExpandEnv("$HOME/Library/LaunchAgents")
err = os.MkdirAll(fileDir, 0755)
if err != nil {
return err
}
err = changePermissions(fileDir)
if err != nil {
return err
}
filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
file, err := os.Create(filePath)
if err != nil {
return err
}
plist := fmt.Sprintf(template, path)
_, err = file.WriteString(plist)
if err != nil {
return err
}
return changePermissions(filePath)
}
开发者ID:djui,项目名称:dlite,代码行数:31,代码来源:agent.go
示例5: getPath
func (u *Update) getPath() (string, error) {
if u.TargetPath == "" {
return osext.Executable()
} else {
return u.TargetPath, nil
}
}
开发者ID:kcompher,项目名称:z-manager,代码行数:7,代码来源:update.go
示例6: GetThisPathParts
func GetThisPathParts() (dirPath, fileName, absPath string) {
exeFile, err := osext.Executable()
if err != nil {
panic(err)
}
return GetPathParts(exeFile)
}
开发者ID:Oskoss,项目名称:rexray,代码行数:7,代码来源:util.go
示例7: Discover
// Discover plugins located on disk, and fall back on plugins baked into the
// Terraform binary.
//
// We look in the following places for plugins:
//
// 1. Terraform configuration path
// 2. Path where Terraform is installed
// 3. Path where Terraform is invoked
//
// Whichever file is discoverd LAST wins.
//
// Finally, we look at the list of plugins compiled into Terraform. If any of
// them has not been found on disk we use the internal version. This allows
// users to add / replace plugins without recompiling the main binary.
func (c *Config) Discover(ui cli.Ui) error {
// Look in ~/.terraform.d/plugins/
dir, err := ConfigDir()
if err != nil {
log.Printf("[ERR] Error loading config directory: %s", err)
} else {
if err := c.discover(filepath.Join(dir, "plugins")); err != nil {
return err
}
}
// Next, look in the same directory as the Terraform executable, usually
// /usr/local/bin. If found, this replaces what we found in the config path.
exePath, err := osext.Executable()
if err != nil {
log.Printf("[ERR] Error loading exe directory: %s", err)
} else {
if err := c.discover(filepath.Dir(exePath)); err != nil {
return err
}
}
// Finally look in the cwd (where we are invoke Terraform). If found, this
// replaces anything we found in the config / install paths.
if err := c.discover("."); err != nil {
return err
}
// Finally, if we have a plugin compiled into Terraform and we didn't find
// a replacement on disk, we'll just use the internal version.
for name, _ := range command.InternalProviders {
if path, found := c.Providers[name]; found {
ui.Warn(fmt.Sprintf("[WARN] %s overrides an internal plugin for %s-provider.\n"+
" If you did not expect to see this message you will need to remove the old plugin.\n"+
" See https://www.terraform.io/docs/internals/internal-plugins.html", path, name))
} else {
cmd, err := command.BuildPluginCommandString("provider", name)
if err != nil {
return err
}
c.Providers[name] = cmd
}
}
for name, _ := range command.InternalProvisioners {
if path, found := c.Provisioners[name]; found {
ui.Warn(fmt.Sprintf("[WARN] %s overrides an internal plugin for %s-provisioner.\n"+
" If you did not expect to see this message you will need to remove the old plugin.\n"+
" See https://www.terraform.io/docs/internals/internal-plugins.html", path, name))
} else {
cmd, err := command.BuildPluginCommandString("provisioner", name)
if err != nil {
return err
}
c.Provisioners[name] = cmd
}
}
return nil
}
开发者ID:ack,项目名称:terraform,代码行数:74,代码来源:config.go
示例8: onStart
func onStart() {
var err error
if self, err = osext.Executable(); err != nil {
logger.Warn("msg", "error getting the path for self", "error", err)
} else {
var self2 string
if self2, err = filepath.Abs(self); err != nil {
logger.Warn("msg", "error getting the absolute path for "+self, "error", err)
} else {
self = self2
}
}
if version != "" {
self = self + " (" + version + ")"
}
var uname string
if u, e := user.Current(); e != nil {
logger.Warn("msg", "cannot get current user", "error", e)
uname = os.Getenv("USER")
} else {
uname = u.Username
}
i := len(topCmd) - 1
topCmd[i] = topCmd[i] + uname
stats.startedat = time.Now().Format(time.RFC3339)
}
开发者ID:thanzen,项目名称:agostle,代码行数:29,代码来源:status.go
示例9: Discover
// Discover discovers plugins.
//
// Search the directory of the executable, then the plugins directory, and
// finally the CWD, in that order. Any conflicts will overwrite previously
// found plugins, in that order.
// Hence, the priority order is the reverse of the search order - i.e., the
// CWD has the highest priority.
func (c *config) Discover() error {
// First, look in the same directory as the executable.
exePath, err := osext.Executable()
if err != nil {
log.Printf("[ERR] Error loading exe directory: %s", err)
} else {
if err := c.discover(filepath.Dir(exePath)); err != nil {
return err
}
}
// Next, look in the plugins directory.
dir, err := packer.ConfigDir()
if err != nil {
log.Printf("[ERR] Error loading config directory: %s", err)
} else {
if err := c.discover(filepath.Join(dir, "plugins")); err != nil {
return err
}
}
// Next, look in the CWD.
if err := c.discover("."); err != nil {
return err
}
// Finally, try to use an internal plugin. Note that this will not override
// any previously-loaded plugins.
if err := c.discoverInternal(); err != nil {
return err
}
return nil
}
开发者ID:c12simple,项目名称:packer,代码行数:41,代码来源:config.go
示例10: runSelfUpdate
func runSelfUpdate(ctx *cli.Context) {
version := "latest"
if len(ctx.Args()) > 0 {
version = ctx.Args()[0]
}
release, err := getRelease(version)
if err != nil {
util.Fatal("Unable to fetch release data")
}
filename := "vagabond_" + runtime.GOOS + "_" + runtime.GOARCH
asset, found := assetSearch(release.Assets, filename)
if !found {
util.Fatal("Unable to find a release asset for this OS and architecture. Expected to find " + filename)
}
srcfile, err := fetchAsset(asset)
if err != nil {
util.Fatalf("Failed fetching file: %s", err)
}
dstFile, err := osext.Executable()
if err != nil {
util.Fatalf("Failed determining current binary: %s", err)
}
err = copyFileOver(srcfile, dstFile)
if err != nil {
util.Fatalf("Failed replacing current binary.")
}
util.Successf("Updated to %s (%s)", *release.TagName, dstFile)
}
开发者ID:LastCallMedia,项目名称:vagabond,代码行数:28,代码来源:selfupdate.go
示例11: CreateLaunchFile
func CreateLaunchFile(autoLaunch bool) {
var err error
var content bytes.Buffer
fname := appdir.InHomeDir(LaunchdPlistFile)
lanternPath, err := osext.Executable()
if err != nil {
log.Errorf("Could not get Lantern directory path: %q", err)
return
}
log.Debugf("Using lantern path: %v", lanternPath)
// Create plist template and set RunAtLoad property
t := template.Must(template.New("LaunchdPlist").Parse(LaunchdPlist))
err = t.Execute(&content, &Plist{RunAtLoad: autoLaunch, Path: lanternPath})
if err != nil {
log.Errorf("Error writing plist template: %q", err)
return
}
if err = ioutil.WriteFile(fname, content.Bytes(), 0755); err != nil {
log.Errorf("Error writing to launchd plist file: %q", err)
}
}
开发者ID:2722,项目名称:lantern,代码行数:25,代码来源:launcher_darwin.go
示例12: exeDir
func exeDir() (string, error) {
exe, err := osext.Executable()
if err != nil {
return "", err
}
return path.Dir(exe), nil
}
开发者ID:vincentcr,项目名称:huecontrol,代码行数:7,代码来源:config.go
示例13: Path
// Path returns the path to the currently running executable.
func Path() string {
path, err := osext.Executable()
if err != nil {
panic(err)
}
return path
}
开发者ID:bastiaanb,项目名称:nomad,代码行数:8,代码来源:testtask.go
示例14: loadFullExePath
func loadFullExePath() {
if exe, err := osext.Executable(); err != nil {
panic("Cannot find EXE path, error: " + err.Error())
} else {
FULL_EXE_PATH = exe
}
}
开发者ID:zero-boilerplate,项目名称:scroxy,代码行数:7,代码来源:config.go
示例15: update
func (u *Updater) update() error {
path, err := osext.Executable()
if err != nil {
return err
}
old, err := os.Open(path)
if err != nil {
return err
}
defer old.Close()
err = u.fetchInfo()
if err != nil {
return err
}
if u.Info.Version == u.CurrentVersion {
return nil
}
bin, err := u.fetchAndVerifyPatch(old)
if err != nil {
if err == ErrHashMismatch {
log.Println("update: hash mismatch from patched binary")
} else {
if u.DiffURL != "" {
log.Println("update: patching binary,", err)
}
}
bin, err = u.fetchAndVerifyFullBin()
if err != nil {
if err == ErrHashMismatch {
log.Println("update: hash mismatch from full binary")
} else {
log.Println("update: fetching full binary,", err)
}
return err
}
}
// close the old binary before installing because on windows
// it can't be renamed if a handle to the file is still open
old.Close()
err, errRecover := up.FromStream(bytes.NewBuffer(bin))
if errRecover != nil {
return fmt.Errorf("update and recovery errors: %q %q", err, errRecover)
}
if err != nil {
return err
}
// remove config.ini so at restart the package will extract again
shutil.CopyFile(*configIni, *configIni+".bak", false)
os.Remove(*configIni)
// update done, we should decide if we need to restart ASAP (maybe a field in update json?)
// BIG issue: the file has been renamed in the meantime
return nil
}
开发者ID:AntoineNlt,项目名称:arduino-create-agent,代码行数:60,代码来源:update.go
示例16: getMoonLauncher
func getMoonLauncher() *MoonLauncher {
if moonLauncher != nil {
return moonLauncher
}
moonLauncher = &MoonLauncher{
name: "MoonDeploy",
}
moonLauncher.title = fmt.Sprintf("%v %v", moonLauncher.name, moondeploy.Version)
var err error
moonLauncher.executable, err = osext.Executable()
if err != nil {
panic(err)
}
moonLauncher.directory, err = osext.ExecutableFolder()
if err != nil {
panic(err)
}
moonLauncher.iconPathAsIco = filepath.Join(moonLauncher.directory, "moondeploy.ico")
moonLauncher.iconPathAsPng = filepath.Join(moonLauncher.directory, "moondeploy.png")
moonLauncher.settings = getMoonSettings()
return moonLauncher
}
开发者ID:giancosta86,项目名称:moondeploy,代码行数:29,代码来源:launcher.go
示例17: Install
func (ws *windowsService) Install() error {
exepath, err := osext.Executable()
if err != nil {
return err
}
// Used if path contains a space.
exepath = `"` + exepath + `"`
m, err := mgr.Connect()
if err != nil {
return err
}
defer m.Disconnect()
s, err := m.OpenService(ws.name)
if err == nil {
s.Close()
return fmt.Errorf("service %s already exists", ws.name)
}
s, err = m.CreateService(ws.name, exepath, mgr.Config{
DisplayName: ws.displayName,
Description: ws.description,
StartType: mgr.StartAutomatic,
})
if err != nil {
return err
}
defer s.Close()
err = eventlog.InstallAsEventCreate(ws.name, eventlog.Error|eventlog.Warning|eventlog.Info)
if err != nil {
s.Delete()
return fmt.Errorf("InstallAsEventCreate() failed: %s", err)
}
return nil
}
开发者ID:sneha29shukla,项目名称:mig,代码行数:33,代码来源:service_windows.go
示例18: UpgradeTo
// UpgradeTo upgrades the currently exeuting binary to the specified Build and
// returns an error or nil. The file is downloaded to <destination>.part and
// atomically renamed to the destination after the hash check. The destination
// is taken as the path of the currently executing binary, while following any
// symbolic links to it's destination.
func UpgradeTo(build Build) error {
path, err := osext.Executable()
if err != nil {
return err
}
path, err = filepath.EvalSymlinks(path)
if err != nil {
return err
}
tmp := path + ".part"
gzUrl := build.URL + ".gz"
resp, err := http.Get(gzUrl)
if err != nil {
return err
}
defer resp.Body.Close()
gunzip, err := gzip.NewReader(resp.Body)
if err != nil {
return err
}
out, err := os.Create(tmp)
if err != nil {
return err
}
defer os.Remove(tmp)
err = os.Chmod(tmp, 0755)
if err != nil {
return err
}
_, err = io.Copy(out, gunzip)
if err != nil {
return err
}
err = out.Close()
if err != nil {
return err
}
hash, err := sha1file(tmp)
if err != nil {
return err
}
if hash != build.Hash {
return ErrHashMismatch
}
ftime := time.Unix(int64(build.BuildStamp), 0)
_ = os.Chtimes(tmp, ftime, ftime)
return os.Rename(tmp, path)
}
开发者ID:calmh,项目名称:mole,代码行数:65,代码来源:upgrade.go
示例19: massageArg0
func massageArg0() {
var err error
os.Args[0], err = osext.Executable()
if err != nil {
panic(fmt.Sprintf("Unable to discover current executable: %v", err))
}
}
开发者ID:x5u,项目名称:goofys,代码行数:7,代码来源:main.go
示例20: runInfo
func runInfo(cmd *types.Command, args []string) {
if infoHelp {
cmd.PrintUsage()
}
if len(args) != 0 {
cmd.PrintShortUsage()
}
// FIXME: fmt.Printf("Servers: %s\n", "quantity")
// FIXME: fmt.Printf("Images: %s\n", "quantity")
fmt.Printf("Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
fmt.Printf("Organization: %s\n", cmd.API.Organization)
// FIXME: add partially-masked token
fmt.Printf("API Endpoint: %s\n", os.Getenv("scaleway_api_endpoint"))
configPath, _ := utils.GetConfigFilePath()
fmt.Printf("RC file: %s\n", configPath)
fmt.Printf("User: %s\n", os.Getenv("USER"))
fmt.Printf("CPUs: %d\n", runtime.NumCPU())
hostname, _ := os.Hostname()
fmt.Printf("Hostname: %s\n", hostname)
cliPath, _ := osext.Executable()
fmt.Printf("CLI Path: %s\n", cliPath)
fmt.Printf("Cache: %s\n", cmd.API.Cache.Path)
fmt.Printf(" Servers: %d\n", cmd.API.Cache.GetNbServers())
fmt.Printf(" Images: %d\n", cmd.API.Cache.GetNbImages())
fmt.Printf(" Snapshots: %d\n", cmd.API.Cache.GetNbSnapshots())
fmt.Printf(" Volumes: %d\n", cmd.API.Cache.GetNbVolumes())
fmt.Printf(" Bootscripts: %d\n", cmd.API.Cache.GetNbBootscripts())
}
开发者ID:pkgr,项目名称:scaleway-cli,代码行数:31,代码来源:info.go
注:本文中的github.com/kardianos/osext.Executable函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论