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 asks the new binary to parse its flags, print PreflightOK and stop before touching shared state, so the caller can detect a broken update before swapping the live binary.
const PreflightHold = 20 * time.Second
PreflightHold is how long the binary stays up after printing PreflightOK. Updaters up to v0.2.3 passed the preflight only when the new binary was still running after 15s, so it must outlast that window for them to accept it.
const PreflightOK = "preflight ok"
PreflightOK is what a binary that honors PreflightEnvVar prints on stdout.
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 and passes once it prints PreflightOK. A binary that exits or keeps running without printing it fails: it is broken, or too old to honor the preflight and would start a second agent on the live NATS session.
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.