Skip to content

Commit 3f8eff9

Browse files
committed
packaging: CLI versionfix warn on outdated KBFS
1 parent 494b815 commit 3f8eff9

8 files changed

Lines changed: 125 additions & 23 deletions

File tree

‎go/client/cmd_status.go‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ type fstatus struct {
7474
Log string
7575
}
7676
KBFS struct {
77-
Version string
78-
Running bool
79-
Pid string
80-
Log string
81-
Mount string
77+
Version string
78+
InstalledVersion string
79+
Running bool
80+
Pid string
81+
Log string
82+
Mount string
8283
}
8384
Desktop struct {
8485
Version string
@@ -174,6 +175,10 @@ func (c *CmdStatus) load() (*fstatus, error) {
174175
status.StoredSecret = extStatus.StoredSecret
175176
status.SecretPromptSkip = extStatus.SecretPromptSkip
176177

178+
kbfsInstalledVersion, err := install.KBFSBundleVersion(c.G(), "")
179+
if err == nil {
180+
status.KBFS.InstalledVersion = kbfsInstalledVersion
181+
}
177182
if kbfs := getFirstClient(extStatus.Clients, keybase1.ClientType_KBFS); kbfs != nil {
178183
status.KBFS.Version = kbfs.Version
179184
status.KBFS.Running = true
@@ -187,10 +192,7 @@ func (c *CmdStatus) load() (*fstatus, error) {
187192
}
188193
status.KBFS.Mount = mountDir
189194
} else {
190-
kbfsVersion, err := install.KBFSBundleVersion(c.G(), "")
191-
if err == nil {
192-
status.KBFS.Version = kbfsVersion
193-
}
195+
status.KBFS.Version = kbfsInstalledVersion
194196
}
195197

196198
if desktop := getFirstClient(extStatus.Clients, keybase1.ClientType_GUI_MAIN); desktop != nil {
@@ -280,6 +282,7 @@ func (c *CmdStatus) outputTerminal(status *fstatus) error {
280282
dui.Printf("\nKBFS:\n")
281283
dui.Printf(" status: %s\n", BoolString(status.KBFS.Running, "running", "not running"))
282284
dui.Printf(" version: %s\n", status.KBFS.Version)
285+
dui.Printf(" installed: %s\n", status.KBFS.InstalledVersion)
283286
dui.Printf(" log: %s\n", status.KBFS.Log)
284287
dui.Printf(" mount: %s\n", status.KBFS.Mount)
285288
dui.Printf("\nService:\n")

‎go/client/versionfix.go‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"io/ioutil"
99
"net"
1010
"os"
11+
"runtime"
1112
"strconv"
1213
"strings"
1314
"time"
1415

1516
"github.com/blang/semver"
17+
"github.com/keybase/client/go/install"
1618
"github.com/keybase/client/go/libkb"
1719
keybase1 "github.com/keybase/client/go/protocol/keybase1"
1820
"github.com/keybase/go-framed-msgpack-rpc/rpc"
@@ -183,3 +185,71 @@ func FixVersionClash(g *libkb.GlobalContext, cl libkb.CommandLine) (err error) {
183185

184186
return err
185187
}
188+
189+
func WarnOutdatedKBFS(g *libkb.GlobalContext, cl libkb.CommandLine) (err error) {
190+
cli, err := GetConfigClient(g)
191+
if err != nil {
192+
return err
193+
}
194+
195+
extStatus, err := cli.GetExtendedStatus(context.TODO(), 0)
196+
if err != nil {
197+
return err
198+
}
199+
var kbfsClientVersion string
200+
201+
kbfs := getFirstClient(extStatus.Clients, keybase1.ClientType_KBFS)
202+
if kbfs == nil {
203+
g.Log.Debug("| KBFS not running; skip KBFS version check")
204+
return nil
205+
}
206+
207+
kbfsClientVersion = kbfs.Version
208+
kbfsInstalledVersion, err := install.KBFSBundleVersion(g, "")
209+
if err != nil {
210+
return err
211+
}
212+
213+
g.Log.Debug("| KBFS version check installed=%s v. client=%s", kbfsInstalledVersion, kbfsClientVersion)
214+
kbfsClientSemver, err := semver.Make(kbfsClientVersion)
215+
if err != nil {
216+
return err
217+
}
218+
219+
kbfsInstalledSemver, err := semver.Make(kbfsInstalledVersion)
220+
if err != nil {
221+
return err
222+
}
223+
224+
if kbfsClientSemver.GT(kbfsInstalledSemver) {
225+
g.Log.Debug("| KBFS client version greater than installed")
226+
} else if kbfsClientSemver.EQ(kbfsInstalledSemver) {
227+
g.Log.Debug("| KBFS versions check out")
228+
} else if kbfsClientSemver.Major < kbfsInstalledSemver.Major {
229+
return fmt.Errorf("Unexpected KBFS version clash; client is at v%s, which is significantly *less than* installed at v%s",
230+
kbfsClientSemver, kbfsInstalledSemver)
231+
} else {
232+
g.Log.Warning("KBFS needs to restart; running version %s, but %s installed.", kbfsClientSemver, kbfsInstalledSemver)
233+
if runtime.GOOS == "linux" {
234+
mountDir, err := g.Env.GetMountDir()
235+
g.Log.Debug("| KBFS mountdir %s", mountDir)
236+
if err != nil {
237+
return err
238+
}
239+
processes, err := install.LsofMount(mountDir, g.Log)
240+
g.Log.Debug("| KBFS lsof err=%s", err)
241+
g.Log.Debug("| KBFS lsof processes=%v", processes)
242+
if err != nil || len(processes) == 0 {
243+
g.Log.Warning("Run 'run_keybase' to restart Keybase services.")
244+
} else {
245+
g.Log.Warning("KBFS currently in use by the following processes:")
246+
for _, process := range processes {
247+
g.Log.Warning("- pid=%s, cmd=%s", process.PID, process.Command)
248+
}
249+
g.Log.Warning("Please terminate the above processes and then run 'run_keybase' to restart Keybase services safely.")
250+
}
251+
}
252+
}
253+
254+
return nil
255+
}

‎go/install/install.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,8 @@ func kbfsBinPathDefault(runMode libkb.RunMode, binPath string) (string, error) {
294294
}
295295
return filepath.Join(filepath.Dir(path), kbfsBinName()), nil
296296
}
297+
298+
type CommonLsofResult struct {
299+
PID string
300+
Command string
301+
}

‎go/install/install_nix.go‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ import (
1414
// IsInUse returns true if the mount is in use. This may be used by the updater
1515
// to determine if it's safe to apply an update and restart.
1616
func IsInUse(mountDir string, log Log) bool {
17-
log.Debug("Mount dir: %s", mountDir)
17+
// ignore error
18+
lsofResults, _ := LsofMount(mountDir, log)
19+
return len(lsofResults) > 0
20+
}
21+
22+
// LsofMount does not return an error if it was unable to lsof
23+
// the mountpoint or the mountpoint does not exist.
24+
func LsofMount(mountDir string, log Log) ([]CommonLsofResult, error) {
25+
log.Debug("Mount dir to lsof: %s", mountDir)
1826
if mountDir == "" {
19-
return false
27+
return nil, nil
2028
}
2129
if _, serr := os.Stat(mountDir); os.IsNotExist(serr) {
22-
log.Debug("%s doesn't exist", mountDir)
23-
return false
30+
log.Debug("%s, mount dir lsof target, doesn't exist", mountDir)
31+
return nil, nil
2432
}
2533

2634
log.Debug("Checking mount (lsof)")
@@ -29,11 +37,12 @@ func IsInUse(mountDir string, log Log) bool {
2937
// If there is an error in lsof it's ok to continue
3038
// An exit status of 1 means that the mount is not in use, and is
3139
// not really an error.
32-
// TODO: Remove this when we fix lsof
33-
log.Warning("Continuing despite error in lsof: %s", err)
40+
log.Debug("Continuing despite error in lsof: %s", err)
41+
return nil, nil
3442
}
35-
if len(processes) != 0 {
36-
return true
43+
var ret []CommonLsofResult
44+
for _, process := range processes {
45+
ret = append(ret, CommonLsofResult{process.PID, process.Command})
3746
}
38-
return false
47+
return ret, nil
3948
}

‎go/install/install_windows.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,8 @@ func StartUpdateIfNeeded(ctx context.Context, log logger.Logger) error {
356356
}
357357
return nil
358358
}
359+
360+
func LsofMount(mountDir string, log Log) ([]CommonLsofResult, error) {
361+
log.Warning("Cannot use lsof on Windows.")
362+
return nil, fmt.Errorf("Cannot use lsof on Windows.")
363+
}

‎go/keybase/main.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ func configOtherLibraries(g *libkb.GlobalContext) error {
204204
// AutoFork? Standalone? ClientServer? Brew service? This function deals with the
205205
// various run configurations that we can run in.
206206
func configureProcesses(g *libkb.GlobalContext, cl *libcmdline.CommandLine, cmd *libcmdline.Command) (err error) {
207-
208207
g.Log.Debug("+ configureProcesses")
209208
defer func() {
210209
g.Log.Debug("- configureProcesses -> %v", err)
@@ -296,6 +295,10 @@ func configureProcesses(g *libkb.GlobalContext, cl *libcmdline.CommandLine, cmd
296295
}
297296
}
298297

298+
if err = client.WarnOutdatedKBFS(g, cl); err != nil {
299+
return err
300+
}
301+
299302
g.Log.Debug("| After forks; newProc=%v", newProc)
300303
if err = configureLogging(g, cl); err != nil {
301304
return err

‎go/lsof/lsof.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ func parse(s string) ([]Process, error) {
178178
}
179179

180180
func run(args []string) ([]Process, error) {
181-
command := "/usr/sbin/lsof"
181+
// Some systems (Arch, Debian) install lsof in /usr/bin and others (centos)
182+
// install it in /usr/sbin, even though regular users can use it too. FreeBSD,
183+
// on the other hand, puts it in /usr/local/sbin. So do not specify absolute path.
184+
command := "lsof"
182185
args = append([]string{"-w"}, args...)
183186
output, err := exec.Command(command, args...).Output()
184187
if err != nil {

‎packaging/linux/post_install.sh‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ safe_restart_systemd_services() {
8989
# and the mountdir is configured (so, it is not a fresh install).
9090
user="$(ps -o user= -p "$pid")"
9191

92-
restart_instructions="Aborting Keybase autorestart for $user. Restart manually by running 'run_keybase' as $user."
92+
restart_instructions="Restart Keybase manually by running 'run_keybase' as $user."
93+
abort_instructions="Aborting Keybase autorestart for $user. $restart_instructions"
9394

9495
if ! systemd_unit_active_for "$user" "keybase.service"; then
9596
echo "Keybase not running via systemd for $user."
@@ -98,9 +99,12 @@ safe_restart_systemd_services() {
9899
fi
99100

100101
if systemd_unit_active_for "$user" "kbfs.service"; then
102+
# TODO: CORE-9789
103+
# We don't pass --direct to keybase config get because it doesn't work on non-root users
104+
# It should still work because the service should be running
101105
if ! mount="$(systemd_exec_as "$user" "/usr/bin/keybase config get --bare mountdir")" || [ -z "$mount" ]; then
102106
echo "Could not find mountdir for $user via systemd."
103-
echo "$restart_instructions"
107+
echo "$abort_instructions"
104108
continue
105109
fi
106110

@@ -111,7 +115,7 @@ safe_restart_systemd_services() {
111115
programs_accessing_mount="$(echo "$lsof_output" | tail -n +2 | awk '{print $1}' | tr '\n' ', ')"
112116
echo "KBFS mount $mount for user $user currently in use by ($programs_accessing_mount)."
113117
echo "Please stop these processes before restarting manually."
114-
echo "$restart_instructions"
118+
echo "$abort_instructions"
115119
continue
116120
fi
117121
fi

0 commit comments

Comments
 (0)