selfupdate

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package selfupdate downloads a new pd-agent binary from GitHub releases and replaces the running binary via rename + syscall.Exec.

Index

Constants

View Source
const PreflightEnvVar = "PDCP_PREFLIGHT"

PreflightEnvVar signals the new binary to exit 0 after flag parsing so the caller can detect a broken update before swapping the live binary.

Variables

This section is empty.

Functions

func Apply

func Apply(newBinaryPath, currentVersion, agentID string) error

Apply replaces the running binary and restarts via syscall.Exec. Call only after draining work. Returns only on failure; on success the process is replaced. agentID is injected into restart args so the new process keeps the same identity. The old binary is left at execPath+".old" for rollback; CleanupOldBinary removes it once the new process reaches a healthy state.

func CleanupOldBinary

func CleanupOldBinary()

CleanupOldBinary removes execPath+".old". Call after the new process reaches a healthy startup milestone (NATS up, registered).

func DownloadAndVerify

func DownloadAndVerify(ctx context.Context, currentVersion, requestedVersion string) (string, error)

DownloadAndVerify resolves the requested version, downloads the binary, and verifies it with -version. Returns the path to the verified temp binary; caller must call Apply or clean it up. Safe to run while the agent is live. PDCP_UPDATE_URL overrides the download URL.

func IsContainer

func IsContainer() bool

IsContainer reports whether the process runs inside a Docker/k8s container.

func Prevalidate

func Prevalidate(newBinaryPath, agentID string) error

Prevalidate runs the new binary with the Apply-time args and PDCP_PREFLIGHT=1, aborting if it exits inside preflightWindow. A binary that honors PreflightEnvVar exits 0 quickly; an older binary either runs normally (and clashes with the live NATS session) or dies on flag mismatches, so any early exit fails the preflight.

Types

type UpdateRequest

type UpdateRequest struct {
	Version string `json:"version"` // "v1.2.3" or "latest"
}

UpdateRequest is the NATS RPC payload for the update command.

type UpdateResult

type UpdateResult struct {
	AgentID        string `json:"agent_id"`
	Status         string `json:"status"`
	CurrentVersion string `json:"current_version"`
	TargetVersion  string `json:"target_version"`
	Message        string `json:"message,omitempty"`
}

UpdateResult is returned before the process restarts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL