Documentation
¶
Overview ¶
Package selfupdate downloads a new pd-agent binary from GitHub releases and replaces the running binary via rename + syscall.Exec.
Index ¶
- Constants
- func Apply(newBinaryPath, currentVersion, agentID string) error
- func CleanupOldBinary()
- func DownloadAndVerify(ctx context.Context, currentVersion, requestedVersion string) (string, error)
- func IsContainer() bool
- func Prevalidate(newBinaryPath, agentID string) error
- type UpdateRequest
- type UpdateResult
Constants ¶
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 ¶
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 ¶
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.