selfupdate

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 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.

View Source
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.

View Source
const PreflightOK = "preflight ok"

PreflightOK is what a binary that honors PreflightEnvVar prints on stdout.

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 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.

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