本文整理汇总了Golang中github.com/keybase/client/go/launchd.NewService函数的典型用法代码示例。如果您正苦于以下问题:Golang NewService函数的具体用法?Golang NewService怎么用?Golang NewService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewService函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: KBFSServiceStatus
// KBFSServiceStatus returns service status for KBFS
func KBFSServiceStatus(context Context, label string, wait time.Duration, log Log) (status keybase1.ServiceStatus) {
if label == "" {
status = keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")}
return
}
kbfsService := launchd.NewService(label)
status, err := serviceStatusFromLaunchd(kbfsService, context.GetKBFSInfoPath(), wait, log)
if err != nil {
return
}
bundleVersion, err := KBFSBundleVersion(context, "")
if err != nil {
status.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error())
return
}
status.BundleVersion = bundleVersion
if status.InstallStatus == keybase1.InstallStatus_NOT_INSTALLED {
return
}
installStatus, installAction, kbStatus := ResolveInstallStatus(status.Version, status.BundleVersion, status.LastExitStatus, log)
status.InstallStatus = installStatus
status.InstallAction = installAction
status.Status = kbStatus
return
}
示例2: keybaseServiceStatus
func keybaseServiceStatus(g *libkb.GlobalContext, label string, bundleVersion string) keybase1.ServiceStatus {
if label == "" {
label = defaultServiceLabel(g.Env.GetRunMode())
}
kbService := launchd.NewService(label)
st, done := serviceStatusFromLaunchd(kbService, path.Join(g.Env.GetRuntimeDir(), "keybased.info"))
st.BundleVersion = bundleVersion
if done {
return st
}
// Something must be wrong if this build doesn't match the package version.
buildVersion := libkb.VersionString()
if bundleVersion != "" && bundleVersion != buildVersion {
st.InstallAction = keybase1.InstallAction_NONE
st.InstallStatus = keybase1.InstallStatus_ERROR
st.Status = errorStatus("INSTALL_ERROR", fmt.Sprintf("Version mismatch: %s != %s", bundleVersion, buildVersion))
return st
}
installStatus, installAction, status := installStatus(st.Version, st.BundleVersion, st.LastExitStatus)
st.InstallStatus = installStatus
st.InstallAction = installAction
st.Status = status
return st
}
示例3: autoInstall
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
}
resolvedBinPath, err := chooseBinPath(binPath)
if err != nil {
return
}
g.Log.Debug("Using binPath: %s", resolvedBinPath)
service := launchd.NewService(label)
plist := keybasePlist(g, resolvedBinPath, label)
// Check if plist is valid. If so we're already installed and return.
plistValid, err := service.CheckPlist(plist)
if err != nil || plistValid {
return
}
err = installService(g, binPath, true)
componentResults = append(componentResults, componentResult(string(ComponentNameService), err))
if err != nil {
return
}
newProc = true
return
}
示例4: KBFSServiceStatus
func KBFSServiceStatus(g *libkb.GlobalContext, label string) (status keybase1.ServiceStatus) {
if label == "" {
label = DefaultKBFSLabel(g.Env.GetRunMode())
}
kbfsService := launchd.NewService(label)
status, err := serviceStatusFromLaunchd(g, kbfsService, path.Join(g.Env.GetRuntimeDir(), "kbfs.info"))
if err != nil {
return
}
bundleVersion, err := KBFSBundleVersion(g, "")
if err != nil {
status.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error())
return
}
status.BundleVersion = bundleVersion
if status.InstallStatus == keybase1.InstallStatus_NOT_INSTALLED {
return
}
installStatus, installAction, kbStatus := ResolveInstallStatus(status.Version, status.BundleVersion, status.LastExitStatus)
status.InstallStatus = installStatus
status.InstallAction = installAction
status.Status = kbStatus
return
}
示例5: UpdaterServiceStatus
// UpdaterServiceStatus returns service status for the Updater service
func UpdaterServiceStatus(context Context, label string) keybase1.ServiceStatus {
if label == "" {
return keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")}
}
serviceStatus := keybase1.ServiceStatus{Label: label}
updaterService := launchd.NewService(label)
status, err := updaterService.WaitForStatus(defaultLaunchdWait, 500*time.Millisecond)
if err != nil {
serviceStatus.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error())
return serviceStatus
}
if status != nil {
serviceStatus.Pid = status.Pid()
serviceStatus.LastExitStatus = status.LastExitStatus()
}
if serviceStatus.Pid != "" {
serviceStatus.InstallStatus = keybase1.InstallStatus_INSTALLED
serviceStatus.InstallAction = keybase1.InstallAction_NONE
} else {
serviceStatus.InstallStatus = keybase1.InstallStatus_NOT_INSTALLED
serviceStatus.InstallAction = keybase1.InstallAction_INSTALL
}
serviceStatus.Status = keybase1.StatusOK("")
return serviceStatus
}
示例6: installKBFSService
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
}
示例7: installKBFSService
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
}
示例8: restartLaunchdService
func restartLaunchdService(g *libkb.GlobalContext, label string, serviceInfoPath string) error {
launchService := launchd.NewService(label)
launchService.SetLogger(g.Log)
err := launchService.Restart(defaultLaunchdWait)
if err != nil {
return err
}
return WaitForService(g, launchService, serviceInfoPath)
}
示例9: installUpdater
func installUpdater(context Context, keybaseBinPath string, force bool, log Log) error {
if context.GetRunMode() != libkb.ProductionRunMode {
return fmt.Errorf("Updater not supported in this run mode")
}
keybaseBinPath, err := chooseBinPath(keybaseBinPath)
if err != nil {
return err
}
updaterBinPath := filepath.Join(filepath.Dir(keybaseBinPath), "updater")
if err != nil {
return err
}
log.Debug("Using updater path: %s", updaterBinPath)
label := DefaultUpdaterLabel(context.GetRunMode())
service := launchd.NewService(label)
plist, err := updaterPlist(context, label, updaterBinPath, keybaseBinPath)
if err != nil {
return err
}
launchdStatus, err := service.LoadStatus()
if err != nil {
return err
}
needsInstall := false
if launchdStatus == nil {
log.Debug("No status, needs install")
needsInstall = true
}
if !needsInstall {
plistValid, err := service.CheckPlist(plist)
if err != nil {
return err
}
if !plistValid {
log.Debug("Plist needs update: %s", service.PlistDestination())
needsInstall = true
}
}
if needsInstall || force {
uninstallUpdater(context.GetRunMode(), log)
log.Debug("Installing updater service")
_, err := installUpdaterService(service, plist, defaultLaunchdWait, log)
if err != nil {
log.Errorf("Error installing updater service: %s", err)
return err
}
}
return nil
}
示例10: stopLaunchd
func (c *CtlHandler) stopLaunchd() {
status := install.KeybaseServiceStatus(c.G(), c.G().Env.GetLabel())
if status.Pid == "" {
c.G().Log.Debug("Service does not appear to be running via launchd (label = %q)", c.G().Env.GetLabel())
return
}
c.G().Log.Debug("Removing %s from launchd", status.Label)
svc := launchd.NewService(status.Label)
if err := svc.Stop(false); err != nil {
c.G().Log.Warning("error stopping launchd service:", err)
}
}
示例11: installKeybaseService
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
}
示例12: installKeybaseService
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
}
示例13: kbfsServiceStatus
func kbfsServiceStatus(g *libkb.GlobalContext, label string, bundleVersion string) keybase1.ServiceStatus {
if label == "" {
label = defaultKBFSLabel(g.Env.GetRunMode())
}
kbfsService := launchd.NewService(label)
st, done := serviceStatusFromLaunchd(kbfsService, path.Join(g.Env.GetRuntimeDir(), "kbfs.info"))
st.BundleVersion = bundleVersion
if done {
return st
}
installStatus, installAction, status := installStatus(st.Version, st.BundleVersion, st.LastExitStatus)
st.InstallStatus = installStatus
st.InstallAction = installAction
st.Status = status
return st
}
示例14: KBFSServiceStatus
func KBFSServiceStatus(g *libkb.GlobalContext, bundleVersion string) keybase1.ServiceStatus {
serviceLabel := libkb.DefaultServiceLabel(libkb.KBFSServiceID, libkb.DefaultRunMode)
kbfsService := launchd.NewService(serviceLabel)
kbfsLaunchdStatus, err := kbfsService.Status()
if err != nil {
return errorStatus(err)
}
if kbfsLaunchdStatus == nil {
return keybase1.ServiceStatus{InstallStatus: keybase1.InstallStatus_NOT_INSTALLED}
}
var kbfsInfo *libkb.ServiceInfo
if kbfsLaunchdStatus.Pid() != "" {
runtimeDir := g.Env.GetRuntimeDir()
kbfsInfo, err = libkb.WaitForServiceInfoFile(path.Join(runtimeDir, "kbfs.info"), kbfsLaunchdStatus.Pid(), 5, 500*time.Millisecond, "launchd status for kbfs")
if err != nil {
return errorStatus(err)
}
}
// nil means not running or file wasn't found
if kbfsInfo == nil {
kbfsInfo = &libkb.ServiceInfo{}
}
version := kbfsInfo.Version
st := keybase1.ServiceStatus{
Version: version,
Label: kbfsLaunchdStatus.Label(),
Pid: kbfsLaunchdStatus.Pid(),
LastExitStatus: kbfsLaunchdStatus.LastExitStatus(),
BundleVersion: bundleVersion,
}
installStatus, installAction, se := installStatus(version, bundleVersion, st.LastExitStatus)
st.InstallStatus = installStatus
st.InstallAction = installAction
st.Error = se
return st
}
示例15: installService
func installService(context Context, binPath string, force bool, log Log) error {
resolvedBinPath, err := chooseBinPath(binPath)
if err != nil {
return err
}
log.Debug("Using binPath: %s", resolvedBinPath)
label := DefaultServiceLabel(context.GetRunMode())
service := launchd.NewService(label)
plist, err := keybasePlist(context, resolvedBinPath, label, log)
if err != nil {
return err
}
log.Debug("Checking service: %s", label)
keybaseStatus := KeybaseServiceStatus(context, label, time.Second, log)
log.Debug("Service: %s (Action: %s); %#v", keybaseStatus.InstallStatus.String(), keybaseStatus.InstallAction.String(), keybaseStatus)
needsInstall := keybaseStatus.NeedsInstall()
if !needsInstall {
plistValid, err := service.CheckPlist(plist)
if err != nil {
return err
}
if !plistValid {
log.Debug("Needs plist upgrade: %s", service.PlistDestination())
needsInstall = true
}
}
if needsInstall || force {
uninstallKeybaseServices(context.GetRunMode(), log)
log.Debug("Installing Keybase service")
_, err := installKeybaseService(context, service, plist, defaultLaunchdWait, log)
if err != nil {
log.Errorf("Error installing Keybase service: %s", err)
return err
}
}
return nil
}