fix(windows): make installer upgrades version aware
This commit is contained in:
1 parent
6906ed52f2
commit
ee7844cb40
14 files changed
+824
-51
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -62,7 +63,21 @@ func queryNative() (Status, error) {
|
||||
} else if configuration.StartType == mgr.StartManual {
|
||||
startup = StartupManual
|
||||
}
|
||||
return Status{Installed: true, State: state, Startup: startup}, nil
|
||||
result := Status{Installed: true, State: state, Startup: startup}
|
||||
if args, err := windows.DecomposeCommandLine(configuration.BinaryPathName); err == nil && len(args) > 0 {
|
||||
result.ExecutablePath = args[0]
|
||||
for i := 1; i < len(args); i++ {
|
||||
if args[i] == "--config" && i+1 < len(args) {
|
||||
result.ConfigPath = args[i+1]
|
||||
break
|
||||
}
|
||||
if strings.HasPrefix(args[i], "--config=") {
|
||||
result.ConfigPath = strings.TrimPrefix(args[i], "--config=")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func installNative(spec InstallSpec) error {
|
||||
@@ -111,7 +126,7 @@ func installNative(spec InstallSpec) error {
|
||||
}
|
||||
}
|
||||
defer service.Close()
|
||||
if err := service.Start(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_ALREADY_RUNNING) {
|
||||
if err := ensureServiceRunning(service, 30*time.Second); err != nil {
|
||||
return fmt.Errorf("start %s service: %w", Name, err)
|
||||
}
|
||||
if err := registerTray(spec); err != nil {
|
||||
@@ -224,10 +239,44 @@ func startNative() error {
|
||||
return err
|
||||
}
|
||||
defer service.Close()
|
||||
if err := service.Start(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_ALREADY_RUNNING) {
|
||||
return err
|
||||
return ensureServiceRunning(service, 30*time.Second)
|
||||
}
|
||||
|
||||
func ensureServiceRunning(service *mgr.Service, timeout time.Duration) error {
|
||||
deadline := time.Now().Add(timeout)
|
||||
issued := false
|
||||
for {
|
||||
status, err := service.Query()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch status.State {
|
||||
case svc.Running:
|
||||
return nil
|
||||
case svc.Stopped:
|
||||
if issued {
|
||||
return errors.New("RVBox service stopped while starting; inspect service-startup.log")
|
||||
}
|
||||
if err := service.Start(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_ALREADY_RUNNING) {
|
||||
return err
|
||||
}
|
||||
issued = true
|
||||
case svc.Paused:
|
||||
if !issued {
|
||||
if _, err := service.Control(svc.Continue); err != nil {
|
||||
return err
|
||||
}
|
||||
issued = true
|
||||
}
|
||||
case svc.StartPending, svc.StopPending, svc.ContinuePending, svc.PausePending:
|
||||
default:
|
||||
return errors.New("RVBox service is in an unsupported startup state")
|
||||
}
|
||||
if !time.Now().Before(deadline) {
|
||||
return errors.New("timed out waiting for RVBox service to run")
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stopNative(timeoutSeconds uint32) error {
|
||||
|
||||
Reference in new issue
Block a user