Skip to content

Commit e66cd60

Browse files
authored
Installer timeout variable on if app opened from user or boot (keybase#4397)
1 parent 68dfae8 commit e66cd60

30 files changed

Lines changed: 167 additions & 182 deletions

‎desktop/app/installer.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @flow
2+
import {app} from 'electron'
23
import exec from './exec'
34
import {appInstallerPath, appBundlePath} from './paths'
45
import {quit} from './ctl'
@@ -15,7 +16,13 @@ export default (callback: (err: any) => void): void => {
1516
callback(new Error('No bundle path for installer'))
1617
return
1718
}
18-
const args = ['--app-path=' + bundlePath, '--run-mode=' + runMode]
19+
let timeout = 10
20+
// If the app was opened at login, there might be contention for lots
21+
// of resources, so let's bump the install timeout to something large.
22+
if (app.getLoginItemSettings().wasOpenedAtLogin) {
23+
timeout = 30
24+
}
25+
const args = ['--app-path=' + bundlePath, '--run-mode=' + runMode, '--timeout=' + timeout]
1926

2027
exec(installerPath, args, 'darwin', 'prod', true, function (err) {
2128
if (err && err.code === 1) {

‎go/client/cmd_ctl_start_osx.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ func ctlStart(g *libkb.GlobalContext, components map[string]bool) error {
6565
g.Log.Debug("Components: %v", components)
6666
errs := []error{}
6767
if ok := components[install.ComponentNameService.String()]; ok {
68-
if err := install.InstallService(g, "", false, g.Log); err != nil {
68+
if err := install.InstallService(g, "", false, defaultLaunchdWait, g.Log); err != nil {
6969
errs = append(errs, err)
7070
g.Log.Errorf("%s", err)
7171
}
7272
}
7373
if ok := components[install.ComponentNameKBFS.String()]; ok {
74-
if err := install.InstallKBFS(g, "", false, g.Log); err != nil {
74+
if err := install.InstallKBFS(g, "", false, defaultLaunchdWait, g.Log); err != nil {
7575
errs = append(errs, err)
7676
g.Log.Errorf("%s", err)
7777
}
7878
}
7979
if ok := components[install.ComponentNameUpdater.String()]; ok {
80-
if err := install.InstallUpdater(g, "", false, g.Log); err != nil {
80+
if err := install.InstallUpdater(g, "", false, defaultLaunchdWait, g.Log); err != nil {
8181
errs = append(errs, err)
8282
g.Log.Errorf("%s", err)
8383
}

‎go/client/cmd_install_osx.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"strings"
13+
"time"
1314

1415
"github.com/keybase/cli"
1516
"github.com/keybase/client/go/install"
@@ -43,6 +44,10 @@ func NewCmdInstall(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comma
4344
Name: "c, components",
4445
Usage: "Components to install, comma separated. Specify 'cli' for command line, 'service' for service, kbfs for 'kbfs', or blank for all.",
4546
},
47+
cli.DurationFlag{
48+
Name: "t, timeout",
49+
Usage: "Timeout as duration, such as '10s' or '1m'.",
50+
},
4651
},
4752
ArgumentHelp: "",
4853
Usage: "Installs Keybase components",
@@ -60,6 +65,7 @@ type CmdInstall struct {
6065
format string
6166
binPath string
6267
installer string
68+
timeout time.Duration
6369
components []string
6470
}
6571

@@ -78,6 +84,10 @@ func (v *CmdInstall) ParseArgv(ctx *cli.Context) error {
7884
v.format = ctx.String("format")
7985
v.binPath = ctx.String("bin-path")
8086
v.installer = ctx.String("installer")
87+
v.timeout = ctx.Duration("timeout")
88+
if v.timeout == 0 {
89+
v.timeout = 11 * time.Second
90+
}
8191
if ctx.String("components") == "" {
8292
v.components = []string{"updater", "service", "kbfs"}
8393
} else {
@@ -100,9 +110,9 @@ func (v *CmdInstall) runInstall() keybase1.InstallResult {
100110
}
101111

102112
if v.installer == "auto" {
103-
return install.AutoInstallWithStatus(v.G(), v.binPath, v.force, v.G().Log)
113+
return install.AutoInstallWithStatus(v.G(), v.binPath, v.force, v.timeout, v.G().Log)
104114
} else if v.installer == "" {
105-
return install.Install(v.G(), v.binPath, v.components, v.force, v.G().Log)
115+
return install.Install(v.G(), v.binPath, v.components, v.force, v.timeout, v.G().Log)
106116
}
107117

108118
return keybase1.InstallResult{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCInstallError, fmt.Sprintf("Invalid installer: %s", v.installer))}

‎go/client/cmd_launchd_osx.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewCmdLaunchd(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comma
3636
}
3737

3838
// defaultLaunchdWait is how long we should wait after install, start, for launchd services
39-
const defaultLaunchdWait = 5 * time.Second
39+
const defaultLaunchdWait = 10 * time.Second
4040

4141
func NewCmdLaunchdInstall(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
4242
return cli.Command{

‎go/install/install_osx.go‎

Lines changed: 31 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func keybasePlist(context Context, binPath string, label string, log Log) (launc
277277
}
278278

279279
func installKeybaseService(context Context, service launchd.Service, plist launchd.Plist, wait time.Duration, log Log) (*keybase1.ServiceStatus, error) {
280-
err := launchd.Install(plist, defaultLaunchdWait, log)
280+
err := launchd.Install(plist, wait, log)
281281
if err != nil {
282282
return nil, err
283283
}
@@ -330,7 +330,7 @@ func kbfsPlist(context Context, kbfsBinPath string, label string) (plist launchd
330330
}
331331

332332
func installKBFSService(context Context, service launchd.Service, plist launchd.Plist, wait time.Duration, log Log) (*keybase1.ServiceStatus, error) {
333-
err := launchd.Install(plist, defaultLaunchdWait, log)
333+
err := launchd.Install(plist, wait, log)
334334
if err != nil {
335335
return nil, err
336336
}
@@ -339,7 +339,7 @@ func installKBFSService(context Context, service launchd.Service, plist launchd.
339339
return &st, err
340340
}
341341

342-
// UninstallUninstallKBFSServicesBFS removes KBFS service (including homebrew)
342+
// UninstallKBFSServices removes KBFS service (including homebrew)
343343
func UninstallKBFSServices(runMode libkb.RunMode, log Log) error {
344344
err1 := launchd.Uninstall(defaultKBFSLabel(runMode, false), defaultLaunchdWait, log)
345345
err2 := launchd.Uninstall(defaultKBFSLabel(runMode, true), defaultLaunchdWait, log)
@@ -398,14 +398,14 @@ func ServiceStatus(context Context, label ServiceLabel, wait time.Duration, log
398398
}
399399

400400
// Install installs all keybase components
401-
func Install(context Context, binPath string, components []string, force bool, log Log) keybase1.InstallResult {
401+
func Install(context Context, binPath string, components []string, force bool, timeout time.Duration, log Log) keybase1.InstallResult {
402402
var err error
403403
componentResults := []keybase1.ComponentResult{}
404404

405405
log.Debug("Installing components: %s", components)
406406

407407
if libkb.IsIn(string(ComponentNameUpdater), components, false) {
408-
err = InstallUpdater(context, binPath, force, log)
408+
err = InstallUpdater(context, binPath, force, timeout, log)
409409
componentResults = append(componentResults, componentResult(string(ComponentNameUpdater), err))
410410
}
411411

@@ -415,12 +415,12 @@ func Install(context Context, binPath string, components []string, force bool, l
415415
}
416416

417417
if libkb.IsIn(string(ComponentNameService), components, false) {
418-
err = InstallService(context, binPath, force, log)
418+
err = InstallService(context, binPath, force, timeout, log)
419419
componentResults = append(componentResults, componentResult(string(ComponentNameService), err))
420420
}
421421

422422
if libkb.IsIn(string(ComponentNameKBFS), components, false) {
423-
err = InstallKBFS(context, binPath, force, log)
423+
err = InstallKBFS(context, binPath, force, timeout, log)
424424
componentResults = append(componentResults, componentResult(string(ComponentNameKBFS), err))
425425
}
426426

@@ -476,7 +476,7 @@ func installCommandLineForBinPath(binPath string, linkPath string, force bool) e
476476
}
477477

478478
// InstallService installs the launchd service
479-
func InstallService(context Context, binPath string, force bool, log Log) error {
479+
func InstallService(context Context, binPath string, force bool, timeout time.Duration, log Log) error {
480480
resolvedBinPath, err := chooseBinPath(binPath)
481481
if err != nil {
482482
return err
@@ -489,37 +489,17 @@ func InstallService(context Context, binPath string, force bool, log Log) error
489489
if err != nil {
490490
return err
491491
}
492-
log.Debug("Checking service: %s", label)
493-
keybaseStatus := KeybaseServiceStatus(context, label, time.Second, log)
494-
log.Debug("Service: %s (Action: %s); %#v", keybaseStatus.InstallStatus.String(), keybaseStatus.InstallAction.String(), keybaseStatus)
495-
needsInstall := keybaseStatus.NeedsInstall()
496-
497-
if !needsInstall {
498-
plistValid, err := service.CheckPlist(plist)
499-
if err != nil {
500-
return err
501-
}
502-
if !plistValid {
503-
log.Debug("Needs plist upgrade: %s", service.PlistDestination())
504-
needsInstall = true
505-
}
506-
}
507-
508-
if needsInstall || force {
509-
UninstallKeybaseServices(context.GetRunMode(), log)
510-
log.Debug("Installing Keybase service")
511-
_, err := installKeybaseService(context, service, plist, defaultLaunchdWait, log)
512-
if err != nil {
513-
log.Errorf("Error installing Keybase service: %s", err)
514-
return err
515-
}
492+
UninstallKeybaseServices(context.GetRunMode(), log)
493+
log.Debug("Installing Keybase service (%s, timeout=%s)", label, timeout)
494+
if _, err := installKeybaseService(context, service, plist, timeout, log); err != nil {
495+
log.Errorf("Error installing Keybase service: %s", err)
496+
return err
516497
}
517-
518498
return nil
519499
}
520500

521501
// InstallKBFS installs the KBFS launchd service
522-
func InstallKBFS(context Context, binPath string, force bool, log Log) error {
502+
func InstallKBFS(context Context, binPath string, force bool, timeout time.Duration, log Log) error {
523503
runMode := context.GetRunMode()
524504
label := DefaultKBFSLabel(runMode)
525505
kbfsService := launchd.NewService(label)
@@ -532,31 +512,12 @@ func InstallKBFS(context Context, binPath string, force bool, log Log) error {
532512
return err
533513
}
534514

535-
log.Debug("Checking KBFS")
536-
kbfsStatus := KBFSServiceStatus(context, label, time.Second, log)
537-
log.Debug("KBFS: %s (Action: %s); %#v", kbfsStatus.InstallStatus.String(), kbfsStatus.InstallAction.String(), kbfsStatus)
538-
needsInstall := kbfsStatus.NeedsInstall()
539-
540-
if !needsInstall {
541-
plistValid, err := kbfsService.CheckPlist(plist)
542-
if err != nil {
543-
return err
544-
}
545-
if !plistValid {
546-
log.Debug("Needs plist upgrade: %s", kbfsService.PlistDestination())
547-
needsInstall = true
548-
}
549-
}
550-
if needsInstall || force {
551-
UninstallKBFSServices(context.GetRunMode(), log)
552-
log.Debug("Installing KBFS")
553-
_, err := installKBFSService(context, kbfsService, plist, defaultLaunchdWait, log)
554-
if err != nil {
555-
log.Errorf("Error installing KBFS: %s", err)
556-
return err
557-
}
515+
UninstallKBFSServices(context.GetRunMode(), log)
516+
log.Debug("Installing KBFS (%s, timeout=%s)", label, timeout)
517+
if _, err := installKBFSService(context, kbfsService, plist, timeout, log); err != nil {
518+
log.Errorf("Error installing KBFS: %s", err)
519+
return err
558520
}
559-
560521
return nil
561522
}
562523

@@ -677,25 +638,25 @@ func execNativeInstallerWithArg(arg string, runMode libkb.RunMode, log Log) erro
677638
}
678639

679640
// AutoInstallWithStatus runs the auto install and returns a result
680-
func AutoInstallWithStatus(context Context, binPath string, force bool, log Log) keybase1.InstallResult {
681-
_, res, err := autoInstall(context, binPath, force, log)
641+
func AutoInstallWithStatus(context Context, binPath string, force bool, timeout time.Duration, log Log) keybase1.InstallResult {
642+
_, res, err := autoInstall(context, binPath, force, timeout, log)
682643
if err != nil {
683644
return keybase1.InstallResult{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCInstallError, err.Error())}
684645
}
685646
return newInstallResult(res)
686647
}
687648

688649
// AutoInstall runs the auto install
689-
func AutoInstall(context Context, binPath string, force bool, log Log) (newProc bool, err error) {
650+
func AutoInstall(context Context, binPath string, force bool, timeout time.Duration, log Log) (newProc bool, err error) {
690651
if context.GetRunMode() != libkb.ProductionRunMode {
691652
return false, fmt.Errorf("Auto install is only supported in production")
692653
}
693654

694-
newProc, _, err = autoInstall(context, binPath, force, log)
655+
newProc, _, err = autoInstall(context, binPath, force, timeout, log)
695656
return
696657
}
697658

698-
func autoInstall(context Context, binPath string, force bool, log Log) (newProc bool, componentResults []keybase1.ComponentResult, err error) {
659+
func autoInstall(context Context, binPath string, force bool, timeout time.Duration, log Log) (newProc bool, componentResults []keybase1.ComponentResult, err error) {
699660
log.Debug("+ AutoInstall for launchd")
700661
defer func() {
701662
log.Debug("- AutoInstall -> %v, %v", newProc, err)
@@ -723,7 +684,7 @@ func autoInstall(context Context, binPath string, force bool, log Log) (newProc
723684
return
724685
}
725686

726-
err = InstallService(context, binPath, true, log)
687+
err = InstallService(context, binPath, true, timeout, log)
727688
componentResults = append(componentResults, componentResult(string(ComponentNameService), err))
728689
if err != nil {
729690
return
@@ -880,7 +841,7 @@ func OSVersion() (semver.Version, error) {
880841
}
881842

882843
// InstallUpdater installs the updater launchd service
883-
func InstallUpdater(context Context, keybaseBinPath string, force bool, log Log) error {
844+
func InstallUpdater(context Context, keybaseBinPath string, force bool, timeout time.Duration, log Log) error {
884845
if context.GetRunMode() != libkb.ProductionRunMode {
885846
return fmt.Errorf("Updater not supported in this run mode")
886847
}
@@ -901,38 +862,12 @@ func InstallUpdater(context Context, keybaseBinPath string, force bool, log Log)
901862
return err
902863
}
903864

904-
launchdStatus, err := service.LoadStatus()
905-
if err != nil {
865+
UninstallUpdaterService(context.GetRunMode(), log)
866+
log.Debug("Installing updater service (%s, timeout=%s)", label, timeout)
867+
if _, err := installUpdaterService(service, plist, timeout, log); err != nil {
868+
log.Errorf("Error installing updater service: %s", err)
906869
return err
907870
}
908-
909-
needsInstall := false
910-
if launchdStatus == nil {
911-
log.Debug("No status, needs install")
912-
needsInstall = true
913-
}
914-
915-
if !needsInstall {
916-
plistValid, err := service.CheckPlist(plist)
917-
if err != nil {
918-
return err
919-
}
920-
if !plistValid {
921-
log.Debug("Plist needs update: %s", service.PlistDestination())
922-
needsInstall = true
923-
}
924-
}
925-
926-
if needsInstall || force {
927-
UninstallUpdaterService(context.GetRunMode(), log)
928-
log.Debug("Installing updater service")
929-
_, err := installUpdaterService(service, plist, defaultLaunchdWait, log)
930-
if err != nil {
931-
log.Errorf("Error installing updater service: %s", err)
932-
return err
933-
}
934-
}
935-
936871
return nil
937872
}
938873

@@ -949,7 +884,7 @@ func updaterPlist(context Context, label string, serviceBinPath string, keybaseB
949884
}
950885

951886
func installUpdaterService(service launchd.Service, plist launchd.Plist, wait time.Duration, log Log) (*keybase1.ServiceStatus, error) {
952-
err := launchd.Install(plist, defaultLaunchdWait, log)
887+
err := launchd.Install(plist, wait, log)
953888
if err != nil {
954889
return nil, err
955890
}

‎go/install/install_unix.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"path"
1414
"regexp"
15+
"time"
1516

1617
"github.com/keybase/client/go/libkb"
1718
)
@@ -50,7 +51,7 @@ func autostartFilePath(context Context) string {
5051
}
5152

5253
// AutoInstall installs auto start on unix
53-
func AutoInstall(context Context, _ string, _ bool, log Log) ( /* newProc */ bool, error) {
54+
func AutoInstall(context Context, _ string, _ bool, timeout time.Duration, log Log) ( /* newProc */ bool, error) {
5455
// If the desktop file already exists and has been disabled by the user, short circuit.
5556
if file, err := os.Open(autostartFilePath(context)); err == nil {
5657
defer file.Close()

‎go/install/install_windows.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path/filepath"
1414
"sort"
1515
"strings"
16+
"time"
1617

1718
"golang.org/x/text/encoding/unicode"
1819
"golang.org/x/text/transform"
@@ -22,7 +23,7 @@ import (
2223
)
2324

2425
// AutoInstall is not supported on Windows
25-
func AutoInstall(context Context, binPath string, force bool, log Log) (newProc bool, err error) {
26+
func AutoInstall(context Context, binPath string, force bool, timeout time.Duration, log Log) (newProc bool, err error) {
2627
return false, fmt.Errorf("Auto install not supported for this build or platform")
2728
}
2829

‎go/install/update_osx.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func AfterUpdateApply(context Context, willRestart bool, force bool, log Log) er
1616
}
1717
if reinstallKBFS {
1818
log.Info("Re-installing KBFS")
19-
err := InstallKBFS(context, "", false, log)
19+
err := InstallKBFS(context, "", false, defaultLaunchdWait, log)
2020
if err != nil {
2121
log.Errorf("Error re-installing KBFS (after Fuse upgrade): %s", err)
2222
}

0 commit comments

Comments
 (0)