Exemple #1
0
func NewCmdLaunchdInstall(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
	return cli.Command{
		Name:         "install",
		ArgumentHelp: "<label> <path/to/keybase> <args>",
		Usage:        "Install a launchd service",
		Action: func(c *cli.Context) {
			// TODO: Use ChooseCommand
			args := c.Args()
			if len(args) < 1 {
				g.Log.Fatalf("No label specified.")
			}
			if len(args) < 2 {
				g.Log.Fatalf("No path to keybase executable specified.")
			}

			label := args[0]
			binPath := args[1]
			plistArgs := args[2:]
			envVars := defaultLaunchdEnvVars(g, label)

			plist := launchd.NewPlist(label, binPath, plistArgs, envVars)
			err := launchd.Install(plist, os.Stdout)
			if err != nil {
				g.Log.Fatalf("%v", err)
			}
			os.Exit(0)
		},
	}
}
Exemple #2
0
func keybasePlist(g *libkb.GlobalContext, binPath string, label string) launchd.Plist {
	// TODO: Remove -d when doing real release
	plistArgs := []string{"-d", "service"}
	envVars := DefaultLaunchdEnvVars(g, label)
	comment := "It's not advisable to edit this plist, it may be overwritten"
	return launchd.NewPlist(label, binPath, plistArgs, envVars, libkb.ServiceLogFileName, comment)
}
Exemple #3
0
func installKBFSService(g *libkb.GlobalContext, binPath string) (*keybase1.ServiceStatus, error) {
	runMode := g.Env.GetRunMode()
	label := defaultKBFSLabel(runMode)
	kbfsBinPath, err := kbfsBinPath(runMode, binPath)
	if err != nil {
		return nil, err
	}
	mountPath := kbfsMountPath(g.Env.GetHome(), runMode)

	// Create mount dir if it doesn't exist
	if _, err := os.Stat(mountPath); os.IsNotExist(err) {
		// TODO Make dir hidden so it only shows when mounted?
		err := os.MkdirAll(mountPath, libkb.PermDir)
		if err != nil {
			return nil, err
		}
	}

	plistArgs := []string{mountPath}
	envVars := defaultLaunchdEnvVars(g, label)

	plist := launchd.NewPlist(label, kbfsBinPath, plistArgs, envVars)
	err = launchd.Install(plist, os.Stdout)
	if err != nil {
		return nil, err
	}

	kbfsService := launchd.NewService(label)
	st, _ := serviceStatusFromLaunchd(kbfsService, "")

	return &st, nil
}
Exemple #4
0
func NewCmdLaunchdInstall(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
	return cli.Command{
		Name:         "install",
		Usage:        "Install a launchd service",
		ArgumentHelp: "<label> <executable> <logfilename> <args>",
		Action: func(c *cli.Context) {
			// TODO: Use ChooseCommand
			args := c.Args()
			if len(args) < 1 {
				g.Log.Fatalf("No label specified.")
			}
			if len(args) < 2 {
				g.Log.Fatalf("No executable specified.")
			}
			if len(args) < 3 {
				g.Log.Fatalf("No log file name specified.")
			}

			label := args[0]
			binPath := args[1]
			logFileName := args[2]
			plistArgs := args[3:]
			envVars := install.DefaultLaunchdEnvVars(label)

			plist := launchd.NewPlist(label, binPath, plistArgs, envVars, logFileName, "")
			err := launchd.Install(plist, defaultLaunchdWait, g.Log)
			if err != nil {
				g.Log.Fatalf("%v", err)
			}
			os.Exit(0)
		},
	}
}
Exemple #5
0
func installKBFSService(g *libkb.GlobalContext, binPath string) (*keybase1.ServiceStatus, error) {
	runMode := g.Env.GetRunMode()
	label := defaultKBFSLabel(runMode)
	kbfsBinPath, err := kbfsBinPath(runMode, binPath)
	if err != nil {
		return nil, err
	}

	mountPath := kbfsMountPath(runMode)
	_, err = os.Stat(mountPath)
	if err != nil {
		return nil, err
	}

	// TODO: Remove when doing real release
	plistArgs := []string{"-debug", mountPath}
	envVars := DefaultLaunchdEnvVars(g, label)

	plist := launchd.NewPlist(label, kbfsBinPath, plistArgs, envVars)
	err = launchd.Install(plist, g.Log)
	if err != nil {
		return nil, err
	}

	kbfsService := launchd.NewService(label)
	st, err := serviceStatusFromLaunchd(kbfsService, "")
	return &st, err
}
Exemple #6
0
func NewCmdLaunchdInstall(cl *libcmdline.CommandLine) cli.Command {
	return cli.Command{
		Name:         "install",
		ArgumentHelp: "<label> <path/to/keybase> <args>",
		Usage:        "Install a launchd service",
		Action: func(c *cli.Context) {
			args := c.Args()
			if len(args) < 1 {
				G.Log.Fatalf("No label specified.")
			}
			if len(args) < 2 {
				G.Log.Fatalf("No path to keybase executable specified.")
			}

			label := args[0]
			binPath := args[1]
			plistArgs := args[2:]

			envVars := make(map[string]string)
			envVars["PATH"] = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin"
			envVars["KEYBASE_LABEL"] = label
			envVars["KEYBASE_LOG_FORMAT"] = "file"

			plist := launchd.NewPlist(label, binPath, plistArgs, envVars)
			err := launchd.Install(plist)
			if err != nil {
				G.Log.Fatalf("%v", err)
			}
			os.Exit(0)
		},
	}
}
Exemple #7
0
func kbfsPlist(context Context, kbfsBinPath string, label string) (plist launchd.Plist, err error) {
	mountDir, err := context.GetMountDir()
	if err != nil {
		return
	}
	logFile := filepath.Join(context.GetLogDir(), libkb.KBFSLogFileName)
	startLogFile := filepath.Join(context.GetLogDir(), libkb.StartLogFileName)
	err = libkb.MakeParentDirs(startLogFile)
	if err != nil {
		return
	}
	// TODO: Remove debug flag when doing real release
	plistArgs := []string{
		"-debug",
		fmt.Sprintf("-log-file=%s", logFile),
		fmt.Sprintf("-runtime-dir=%s", context.GetRuntimeDir()),
	}

	if context.GetRunMode() == libkb.DevelRunMode {
		plistArgs = append(plistArgs, fmt.Sprintf("-server-root=%s", context.GetRuntimeDir()))
	}

	plistArgs = append(plistArgs, mountDir)

	envVars := DefaultLaunchdEnvVars(label)
	envVars = append(envVars, launchd.NewEnvVar("KEYBASE_RUN_MODE", string(context.GetRunMode())))
	plist = launchd.NewPlist(label, kbfsBinPath, plistArgs, envVars, startLogFile, defaultPlistComment)

	_, err = os.Stat(mountDir)
	if err != nil {
		return
	}

	return
}
Exemple #8
0
func updaterPlist(context Context, label string, serviceBinPath string, keybaseBinPath string) (launchd.Plist, error) {
	plistArgs := []string{fmt.Sprintf("-path-to-keybase=%s", keybaseBinPath)}
	envVars := DefaultLaunchdEnvVars(label)
	comment := "It's not advisable to edit this plist, it may be overwritten"
	logFile := filepath.Join(context.GetLogDir(), libkb.UpdaterLogFileName)
	err := libkb.MakeParentDirs(logFile)
	if err != nil {
		return launchd.Plist{}, err
	}
	return launchd.NewPlist(label, serviceBinPath, plistArgs, envVars, logFile, comment), nil
}
Exemple #9
0
func keybasePlist(context Context, binPath string, label string, log Log) (launchd.Plist, error) {
	// TODO: Remove -d when doing real release
	logFile := filepath.Join(context.GetLogDir(), libkb.ServiceLogFileName)
	startLogFile := filepath.Join(context.GetLogDir(), libkb.StartLogFileName)
	err := libkb.MakeParentDirs(startLogFile)
	if err != nil {
		return launchd.Plist{}, err
	}
	plistArgs := []string{"-d", fmt.Sprintf("--log-file=%s", logFile), "service"}
	envVars := DefaultLaunchdEnvVars(label)
	envVars = append(envVars, launchd.NewEnvVar("KEYBASE_RUN_MODE", string(context.GetRunMode())))
	return launchd.NewPlist(label, binPath, plistArgs, envVars, startLogFile, defaultPlistComment), nil
}
Exemple #10
0
func installKeybaseService(g *libkb.GlobalContext, binPath string) (*keybase1.ServiceStatus, error) {
	label := defaultServiceLabel(g.Env.GetRunMode())
	plistArgs := []string{"service"}
	envVars := DefaultLaunchdEnvVars(g, label)

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

	kbService := launchd.NewService(label)
	st, err := serviceStatusFromLaunchd(kbService, serviceInfoPath(g))
	return &st, err
}
Exemple #11
0
func kbfsPlist(g *libkb.GlobalContext, kbfsBinPath string, label string) (plist launchd.Plist, err error) {
	runMode := g.Env.GetRunMode()
	mountPath := kbfsMountPath(runMode)
	// TODO: Remove when doing real release
	plistArgs := []string{"-debug", mountPath}
	envVars := DefaultLaunchdEnvVars(g, label)
	comment := "It's not advisable to edit this plist, it may be overwritten"
	plist = launchd.NewPlist(label, kbfsBinPath, plistArgs, envVars, libkb.KBFSLogFileName, comment)

	_, err = os.Stat(mountPath)
	if err != nil {
		return
	}

	return
}
Exemple #12
0
func installKeybaseService(g *libkb.GlobalContext, binPath string) (*keybase1.ServiceStatus, error) {
	label := DefaultServiceLabel(g.Env.GetRunMode())
	// TODO: Remove -d when doing real release
	plistArgs := []string{"-d", "service"}
	envVars := DefaultLaunchdEnvVars(g, label)

	plist := launchd.NewPlist(label, binPath, plistArgs, envVars, libkb.ServiceLogFileName)
	err := launchd.Install(plist, g.Log)
	if err != nil {
		return nil, err
	}

	kbService := launchd.NewService(label)
	st, err := serviceStatusFromLaunchd(g, kbService, serviceInfoPath(g))
	return &st, err
}
func NewCmdLaunchdInstall(cl *libcmdline.CommandLine) cli.Command {
	return cli.Command{
		Name:         "install",
		ArgumentHelp: "<label> <path/to/keybase> <args>",
		Usage:        "Install a launchd service",
		Action: func(c *cli.Context) {
			args := c.Args()
			if len(args) < 1 {
				G.Log.Fatalf("No label specified.")
			}
			if len(args) < 2 {
				G.Log.Fatalf("No path to keybase executable specified.")
			}

			label := args[0]
			binPath := args[1]
			plistArgs := args[2:]

			homeDir := os.Getenv("HOME")
			home := libkb.NewHomeFinder("keybase",
				func() string { return homeDir },
				runtime.GOOS,
				func() libkb.RunMode { return libkb.DefaultRunMode })

			envVars := make(map[string]string)
			envVars["PATH"] = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin"
			envVars["KEYBASE_LABEL"] = label
			envVars["KEYBASE_LOG_FORMAT"] = "file"
			envVars["KEYBASE_RUNTIME_DIR"] = home.RuntimeDir()

			plist := launchd.NewPlist(label, binPath, plistArgs, envVars)
			err := launchd.Install(plist)
			if err != nil {
				G.Log.Fatalf("%v", err)
			}
			os.Exit(0)
		},
	}
}
Exemple #14
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
}