當前位置: 首頁>>代碼示例>>Golang>>正文


Golang osext.Executable函數代碼示例

本文整理匯總了Golang中bitbucket/org/kardianos/osext.Executable函數的典型用法代碼示例。如果您正苦於以下問題:Golang Executable函數的具體用法?Golang Executable怎麽用?Golang Executable使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Executable函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Install

func (s *darwinLaunchdService) Install() error {
	var confPath = s.getServiceFilePath()
	_, err := os.Stat(confPath)
	if err == nil {
		return fmt.Errorf("Init already exists: %s", confPath)
	}

	f, err := os.Create(confPath)
	if err != nil {
		return err
	}
	defer f.Close()

	path, err := osext.Executable()
	if err != nil {
		return err
	}

	var to = &struct {
		Name        string
		Display     string
		Description string
		Path        string
	}{
		s.name,
		s.displayName,
		s.description,
		path,
	}

	t := template.Must(template.New("launchdConfig").Parse(launchdConfig))
	return t.Execute(f, to)
}
開發者ID:supr,項目名稱:service,代碼行數:33,代碼來源:service_darwin.go

示例2: Install

func (ws *windowsService) Install() error {
	exepath, err := osext.Executable()
	if err != nil {
		return err
	}
	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:supr,項目名稱:service,代碼行數:31,代碼來源:service_windows.go

示例3: exePath

func exePath() string {
	exePath, err := osext.Executable()
	if err != nil {
		panic(err)
	}
	return exePath
}
開發者ID:Joffcom,項目名稱:silver,代碼行數:7,代碼來源:util.go

示例4: updateSelf

func updateSelf() {
	fmt.Println("Downloading latest version...")
	resp, err := http.Get("https://s3.amazonaws.com/progrium-flynn/flynn-grid/dev/grid-cli_" + runtime.GOOS + "_" + runtime.GOARCH + ".tgz")
	assert(err)
	defer resp.Body.Close()
	z, err := gzip.NewReader(resp.Body)
	assert(err)
	defer z.Close()
	t := tar.NewReader(z)
	hdr, err := t.Next()
	assert(err)
	if hdr.Name != "grid" {
		log.Fatal("grid binary not found in tarball")
	}
	defer t.Next()
	selfpath, err := osext.Executable()
	assert(err)
	info, err := os.Stat(selfpath)
	assert(err)
	assert(os.Rename(selfpath, selfpath+".old"))
	f, err := os.OpenFile(selfpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, info.Mode().Perm())
	if err != nil {
		assert(os.Rename(selfpath+".old", selfpath))
		assert(err)
	}
	defer f.Close()
	_, err = io.Copy(f, t)
	if err != nil {
		assert(os.Rename(selfpath+".old", selfpath))
		assert(err)
	}
	assert(os.Remove(selfpath + ".old"))
	fmt.Println("Updated.")
}
開發者ID:pombredanne,項目名稱:grid-cli,代碼行數:34,代碼來源:selfupdate.go

示例5: upgrade

func upgrade() error {
	path, err := osext.Executable()
	if err != nil {
		return err
	}

	resp, err := http.Get("https://api.github.com/repos/calmh/syncthing/releases?per_page=1")
	if err != nil {
		return err
	}

	var rels []githubRelease
	json.NewDecoder(resp.Body).Decode(&rels)
	resp.Body.Close()

	if len(rels) != 1 {
		return fmt.Errorf("Unexpected number of releases: %d", len(rels))
	}
	rel := rels[0]

	if rel.Tag > Version {
		infof("Attempting upgrade to %s...", rel.Tag)
	} else if rel.Tag == Version {
		okf("Already running the latest version, %s. Not upgrading.", Version)
		return nil
	} else {
		okf("Current version %s is newer than latest release %s. Not upgrading.", Version, rel.Tag)
		return nil
	}

	expectedRelease := fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, rel.Tag)
	for _, asset := range rel.Assets {
		if strings.HasPrefix(asset.Name, expectedRelease) {
			if strings.HasSuffix(asset.Name, ".tar.gz") {
				infof("Downloading %s...", asset.Name)
				fname, err := readTarGZ(asset.URL, filepath.Dir(path))
				if err != nil {
					return err
				}

				old := path + "." + Version
				err = os.Rename(path, old)
				if err != nil {
					return err
				}
				err = os.Rename(fname, path)
				if err != nil {
					return err
				}

				okf("Upgraded %q to %s.", path, rel.Tag)
				okf("Previous version saved in %q.", old)

				return nil
			}
		}
	}

	return nil
}
開發者ID:JIVS,項目名稱:syncthing,代碼行數:60,代碼來源:upgrade_unix.go

示例6: copyToBin

func copyToBin() (err error) {
	src, err := osext.Executable()
	if err != nil {
		return
	}

	dst := "/usr/bin/fiddler"

	log.Println("Copying", src, "to", dst, "...")

	sf, err := os.OpenFile(src, os.O_RDONLY, 0666)
	if err != nil {
		return
	}
	defer sf.Close()

	df, err := os.OpenFile(dst, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0744)
	if err != nil {
		return
	}
	defer df.Close()

	_, err = io.Copy(df, sf)
	if err != nil {
		return
	}

	log.Println("Done.")

	return
}
開發者ID:hayesgm,項目名稱:fiddler,代碼行數:31,代碼來源:installer.go

示例7: InstallFiddler

// Installs Fiddler to run on systemd
// 1) This is going to copy our executable to a more suitable location (/usr/bin/fiddler)
// 2) Then, we'll install a service for ourselves
// 3) And we'll kick off that service
func InstallFiddler(c string, conf config.FiddlerConf) (err error) {
	// err = copyToBin()
	// if err != nil {
	//  return
	// }
	src, err := osext.Executable()
	if err != nil {
		return
	}

	settings := ServiceSettings{Exec: src, Conf: c}

	err = installServiceFromTemplate("fiddler.service", FiddlerTemplate, &settings)
	if err != nil {
		return
	}

	err = installServiceFromTemplate("container.service", DockerTemplate, conf.Docker)
	if err != nil {
		return
	}

	err = restartServices()
	if err != nil {
		return
	}

	return
}
開發者ID:hayesgm,項目名稱:fiddler,代碼行數:33,代碼來源:installer.go

示例8: getPath

func (u *Update) getPath() (string, error) {
	if u.TargetPath == "" {
		return osext.Executable()
	} else {
		return u.TargetPath, nil
	}
}
開發者ID:ZhangBanger,項目名稱:go-update,代碼行數:7,代碼來源:update.go

示例9: backgroundRun

func backgroundRun() {
	b, err := needUpdate()
	if err != nil {
		return
	}
	if b {
		if err := update.SanityCheck(); err != nil {
			if debugMode {
				fmt.Println("Will not be able to replace the executable")
			}
			// fail
			return
		}
		self, err := osext.Executable()
		if err != nil {
			// fail update, couldn't figure out path to self
			return
		}
		l := exec.Command("logger", "-tcx")
		c := exec.Command(self, "update")
		if w, err := l.StdinPipe(); err == nil && l.Start() == nil {
			c.Stdout = w
			c.Stderr = w
		}
		c.Start()
	}
}
開發者ID:noma4i,項目名稱:cx,代碼行數:27,代碼來源:update.go

示例10: ImportConf

func ImportConf() error {
	var conffile string
	current, _ := osext.Executable()
	current = path.Dir(current)

	flag.StringVar(&conffile, "config", current+"/"+defaultConfigFile, "Configuration File")
	flag.Parse()

	c, err := ioutil.ReadFile(conffile)
	if err != nil {
		return err
	}

	json.Unmarshal(c, &Config)

	// Sanitize
	if Config.Port == 0 {
		Config.Port = 8042
	}
	if Config.StaticDir == "" {
		Config.StaticDir = current + "/static"
	}
	if Config.TmplDir == "" {
		Config.TmplDir = current + "/templates"
	}
	if Config.XMPP_Server == "" {
		Config.XMPP_Server = "localhost"
	}
	if Config.XMPP_Port == 0 {
		Config.XMPP_Port = 5222
	}

	return nil
}
開發者ID:hasantayyar,項目名稱:kiwi,代碼行數:34,代碼來源:config.go

示例11: 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:reth-,項目名稱:mole,代碼行數:65,代碼來源:upgrade.go

示例12: main

func main() {
	syscall.Setuid(0)
	usr, e := user.Current()
	if e != nil {
		log.Fatal(e)
	}

CHECK:
	if usr.Name != "System Administrator" {
		fmt.Println("Not running as root, relaunching")

		appdir, _ := osext.Executable()
		appdir_len := len(appdir)
		sudo_path := appdir[0:(appdir_len-7)] + "qtox_sudo" //qtox_sudo is a fork of cocoasudo with all of its flags and other features stripped out

		if _, err := os.Stat(sudo_path); os.IsNotExist(err) {
			fmt.Println("Error: No qtox_sudo binary installed, falling back")
			custom_user = usr.Name
			usr.Name = "System Administrator"
			goto CHECK
		}

		relaunch := exec.Command(sudo_path, appdir, usr.Name)
		relaunch.Stdout = os.Stdout
		relaunch.Stderr = os.Stderr
		relaunch.Run()
		return

	} else {

		if len(os.Args) > 1 || custom_user != "" {

			if custom_user == "" {
				custom_user = os.Args[1]
			}

			update_dir := "/Users/" + custom_user + "/Library/Preferences/tox/update/"
			if _, err := os.Stat(update_dir); os.IsNotExist(err) {
				fmt.Println("Error: No update folder, is check for updates enabled?")
				return
			}
			fmt.Println("qTox Updater")

			killqtox := exec.Command("/usr/bin/killall", "qtox")
			_ = killqtox.Run()

			install(update_dir, len(update_dir))

			os.RemoveAll(update_dir)
			fmt.Println("Update metadata wiped, launching qTox")
			launchqtox := exec.Command("/usr/bin/open", "-b", "chat.tox.qtox")
			launchqtox.Run()

		} else {
			fmt.Println("Error: no user passed")
		}

	}
}
開發者ID:C3La-NS,項目名稱:qTox-UI,代碼行數:59,代碼來源:updater.go

示例13: main

func main() {
	var debug = flag.Bool("d", false, "debug mode: do not fork and print all logs to stdout")
	flag.Parse()
	log.Println(osext.Executable())
	if *debug {
		log.Println("debug is set")
	}
}
開發者ID:jvehent,項目名稱:go-toybox,代碼行數:8,代碼來源:arguments.go

示例14: scriptDir

func scriptDir() string {
	executable, err := osext.Executable()
	if err != nil {
		log.Fatal(err)
	}
	dir := filepath.Dir(executable)
	return dir
}
開發者ID:WIZARD-CXY,項目名稱:golang-devops-stuff,代碼行數:8,代碼來源:defaults.go

示例15: getExecutableName

func getExecutableName() string {
	executablePath, err := osext.Executable()
	if err != nil {
		return "(UNKNOWN)"
	} else {
		return path.Base(executablePath)
	}
}
開發者ID:kisom,項目名稱:etcd,代碼行數:8,代碼來源:logger.go


注:本文中的bitbucket/org/kardianos/osext.Executable函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。