Exemple #1
0
func AutoInstall(g *libkb.GlobalContext, binPath string, force bool) (newProc bool, err error) {
	g.Log.Debug("+ AutoInstall for launchd")
	defer func() {
		g.Log.Debug("- AutoInstall -> %v, %v", newProc, err)
	}()
	label := defaultServiceLabel(g.Env.GetRunMode())
	if label == "" {
		err = fmt.Errorf("No service label to install")
		return newProc, err
	}

	// Check if plist is installed. If so we're already installed and return.
	plistPath := launchd.PlistDestination(label)
	if _, err := os.Stat(plistPath); err == nil {
		g.Log.Debug("| already installed at %s", plistPath)
		if !force {
			return newProc, nil
		}
	}

	err = installService(g, binPath, true)
	if err != nil {
		return newProc, err
	}

	newProc = true
	return newProc, nil
}
Exemple #2
0
func autoInstall(g *libkb.GlobalContext, binPath string, force bool) (newProc bool, componentResults []keybase1.ComponentResult, err error) {
	g.Log.Debug("+ AutoInstall for launchd")
	defer func() {
		g.Log.Debug("- AutoInstall -> %v, %v", newProc, err)
	}()
	label := DefaultServiceLabel(g.Env.GetRunMode())
	if label == "" {
		err = fmt.Errorf("No service label to install")
		return
	}

	// Check if plist is installed. If so we're already installed and return.
	plistPath := launchd.PlistDestination(label)
	if _, ferr := os.Stat(plistPath); ferr == nil {
		g.Log.Debug("| already installed at %s", plistPath)
		if !force {
			return
		}
	}

	err = installService(g, binPath, true)
	componentResults = append(componentResults, componentResult(string(ComponentNameService), err))
	if err != nil {
		return
	}

	newProc = true
	return
}
Exemple #3
0
func BrewAutoInstall(g *libkb.GlobalContext) (newProc bool, err error) {
	g.Log.Debug("+ BrewAutoInstall for launchd")
	defer func() {
		g.Log.Debug("- BrewAutoInstall -> %v, %v", newProc, err)
	}()
	label := defaultBrewServiceLabel(g.Env.GetRunMode())
	if label == "" {
		err = fmt.Errorf("No service label to install")
		return newProc, err
	}

	// Check if plist is installed. If so we're already installed and return.
	plistPath := launchd.PlistDestination(label)
	if _, err := os.Stat(plistPath); err == nil {
		g.Log.Debug("| already installed at %s", plistPath)
		return newProc, nil
	}

	// Get the full path to this executable using the brew opt bin directory.
	binName := filepath.Base(os.Args[0])
	binPath := filepath.Join("/usr/local/opt", binName, "bin", binName)
	g.Log.Debug("| assembled binPath = %s", binPath)
	plistArgs := []string{"service"}
	envVars := defaultEnvVars(g, label)

	plist := launchd.NewPlist(label, binPath, plistArgs, envVars)
	err = launchd.Install(plist, ioutil.Discard)
	if err != nil {
		return newProc, err
	}

	// Get service install status. This causes us to pause (with timeout) until
	// the service is up.
	kbService := launchd.NewService(label)
	ServiceStatusFromLaunchd(kbService, path.Join(g.Env.GetRuntimeDir(), "keybased.info"))

	newProc = true
	return newProc, nil
}