Skip to content

Commit

Permalink
fix: replace binary before copying to store
Browse files Browse the repository at this point in the history
Change-Id: I2810f1900b4bef3caa97f07494d23cc340333545
  • Loading branch information
profclems committed Oct 27, 2024
1 parent f5d66cc commit 525c637
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 0 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ services:
STORJ_CONSOLE_ADDRESS: 0.0.0.0:10000
STORJ_CONSOLE_AUTH_TOKEN_SECRET: my-suppa-secret-key
STORJ_CONSOLE_EXTERNAL_ADDRESS: http://localhost:10000/
STORJ_CONSOLE_GATEWAY_CREDENTIALS_REQUEST_URL: http://localhost:8888
STORJ_CONSOLE_LINKSHARING_URL: http://localhost:9090
STORJ_CONSOLE_OPEN_REGISTRATION_ENABLED: "true"
STORJ_CONSOLE_PUBLIC_LINKSHARING_URL: http://localhost:9090
STORJ_CONSOLE_RATE_LIMIT_BURST: "10000"
STORJ_CONSOLE_SIGNUP_ACTIVATION_CODE_ENABLED: "false"
STORJ_CONTACT_EXTERNAL_ADDRESS: satellite-api:7777
STORJ_DATABASE: cockroach://root@cockroach:26257/master?sslmode=disable
Expand Down
6 changes: 5 additions & 1 deletion supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (s *Supervisor) Run(ctx context.Context) error {
slog.Info("Starting process", slog.String("binary", s.process.binPath))
err := s.runProcess(ctx)
if err != nil {
slog.Error("Failed to run process", "error", err)
slog.Error("Process exited with error", "error", err)
} else {
slog.Info("Process exited")
}

if s.disableAutoRestart {
Expand Down Expand Up @@ -87,7 +89,9 @@ func (s *Supervisor) Run(ctx context.Context) error {
}

if updated {
// reset the current version to force a new check.
curVersion = version.SemVer{}
// exit the process to restart it with the new binary.
return errSupervisor.Wrap(s.process.exit())
}

Expand Down
17 changes: 10 additions & 7 deletions supervisor/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"io"
"io/fs"
"log"
"log/slog"
"net/http"
"os"
Expand All @@ -19,12 +18,15 @@ import (
)

type Updater struct {
log *slog.Logger

checker *checker.Client
}

// NewUpdater creates a new updater.
func NewUpdater(checker *checker.Client) *Updater {
func NewUpdater(log *slog.Logger, checker *checker.Client) *Updater {
return &Updater{
log: log,
checker: checker,
}
}
Expand All @@ -42,7 +44,7 @@ func (u *Updater) Update(ctx context.Context, process *Process, currentVersion v
}

if newVersion.IsZero() {
log.Println(reason)
u.log.Info(reason)
return false, nil
}

Expand All @@ -68,12 +70,13 @@ func (u *Updater) Update(ctx context.Context, process *Process, currentVersion v
return false, errs.Combine(err, os.Remove(newVersionPath))
}

if err = copyToStore(ctx, process.storeDir, newVersionPath); err != nil {
if err = replaceBinary(ctx, currentVersion, newVersionPath, process.binPath); err != nil {
return false, errs.Wrap(err)
}

if err = replaceBinary(ctx, currentVersion, newVersionPath, process.binPath); err != nil {
return false, errs.Wrap(err)
if err = copyToStore(ctx, process.storeDir, process.binPath); err != nil {
// log the error but don't return it as it's not critical;
slog.Warn("Error copying binary to store.", "error", err)
}

return true, nil
Expand Down Expand Up @@ -104,7 +107,7 @@ func replaceBinary(ctx context.Context, currentVersion version.SemVer, newVersio

// remove the backup binary
if err := os.Remove(backupPath); err != nil && !errs.Is(err, fs.ErrNotExist) {
slog.Warn("Error removing backup binary", err)
slog.Warn("Error removing backup binary. Consider removing manually", "error", err)
}

return nil
Expand Down

0 comments on commit 525c637

Please sign in to comment.