install

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 30 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

Index

Constants

View Source
const ReleaseSigningKey = "ed25519:PcyApOO6AE0rjSIDLEUYJnO9lZLx/4XnzVwJDt5Pcz8="

ReleaseSigningKey is the public key, in the "ed25519:..." form printed by "selfupdate keygen", whose private half signs the manifest.json of every release. Updates are installed only from manifests it signed; a build without it cannot update itself.

Variables

View Source
var BuildTarget string

BuildTarget names the variant of a build for a CPU feature level or an old system, such as "v7" or "softfloat"; set by scripts/build_assets.sh.

View Source
var ErrRestartUnsupported = errors.New("a process not run as a Windows service cannot restart itself reliably")

ErrRestartUnsupported is returned by UpdateSelf and RestartSelf where the calling process cannot restart itself reliably (see CanRestartSelf).

Functions

func CanRestartSelf added in v0.34.9

func CanRestartSelf() bool

CanRestartSelf reports whether the calling process can restart itself as a new version without its parent noticing. On Unix it always can: the process image is replaced in place.

func ConfigureService added in v0.34.9

func ConfigureService(c *service.Config)

ConfigureService sets the platform specific settings of c.

func ControlService added in v0.34.8

func ControlService(s service.Service, name, action string) error

ControlService runs a service control action, the way the service manager of the platform needs it (see controlService).

func CopyDir

func CopyDir(srcPath string, destPath string) error

CopyDir copies the files under srcPath into destPath, creating directories as needed.

func GeoDataVersion added in v0.34.9

func GeoDataVersion(path string) string

GeoDataVersion returns the release the geodata file at path comes from, "" when unknown.

func LatestVersion added in v0.34.9

func LatestVersion() string

LatestVersion returns the version of the latest release as last queried, or "" before a query succeeded. A stale or missing version is queried again in the background, every 6 hours, or 10 minutes after a failure.

func LinkServiceStart added in v0.35.0

func LinkServiceStart(name string)

LinkServiceStart sets the start and stop links of the init script of name in /etc/rc.d, which BusyBox based systems such as OpenWrt read: the service library creates none for System V and fixed S50 and K02 ones for procd. The links it leaves are replaced by ones with the START and STOP of the script, so that the script's own enable and enabled see the same links and a later enable adds none.

func NPC added in v0.34.8

func NPC() (string, error)

NPC installs the npc executable and returns the path the service should run.

func NPS added in v0.34.8

func NPS() (string, error)

NPS installs the nps executable, web assets and, on a fresh install, the config directory. It returns the path the service should run.

func RecoverUpdate added in v0.35.0

func RecoverUpdate()

RecoverUpdate finishes or undoes an update of the running executable that a crash interrupted, and deletes what a finished one left behind. Call it on every start; StartUpdate does it as well.

func RestartAfterUpdate added in v0.34.8

func RestartAfterUpdate(s service.Service, name string, res *UpdateResult) error

RestartAfterUpdate restarts the services that ran the executables res replaced (see UpdateResult.Services), so they run the new version. s is the service name, the default service of the program, or nil when the service manager is unavailable; the other services are reached by their names. A service that is not running takes the new version on its next start.

func RestartSelf added in v0.34.9

func RestartSelf(exe string) error

RestartSelf makes the calling process continue as exe, the executable an update replaced, and returns only on failure. The process image is replaced in place, which keeps its process ID, so a service manager supervising it does not see the restart; this holds in containers as well.

func SetServiceScripts added in v0.35.0

func SetServiceScripts(c *service.Config)

SetServiceScripts sets the service file template of the init system of this host in c.Option, with c.Executable and c.Arguments written in as one quoted command line. Call it after both are final, right before the service is installed.

func StartUpdate added in v0.35.0

func StartUpdate()

StartUpdate is called when the program starts its real work. The first starts of a pending update confirm it once they have run for a while; a pending update that failed to do so too often is rolled back, and the process restarts as the previous version.

func UninstallService added in v0.34.9

func UninstallService(s service.Service, name string) error

UninstallService stops and uninstalls s, the system service name. systemd refuses to disable a unit whose file is empty, and procd runs the init script, which an empty or foreign script fails; the files of the service are then deleted directly so that a later install does not find them in place. The start and stop links of the init script, which installs of this and older versions named differently, are removed as well.

func UpdateAvailable added in v0.34.9

func UpdateAvailable() bool

UpdateAvailable reports whether the latest release known is newer than this build.

func WarnOldProcesses added in v0.34.9

func WarnOldProcesses(pids []int32)

WarnOldProcesses reports the processes among pids that still run, and so still run the version an update replaced.

Types

type GeoFile added in v0.34.9

type GeoFile struct {
	Name string
	Path string
}

GeoFile is one geodata file: its name in the release and its local path.

func GeoFiles added in v0.34.9

func GeoFiles(ipPath, sitePath string) []GeoFile

GeoFiles returns the geodata files kept at ipPath and sitePath.

func PickGeoFiles added in v0.35.0

func PickGeoFiles(files []GeoFile, name string) ([]GeoFile, error)

PickGeoFiles returns the file called name, geoip or geosite. With an empty name it returns geoip and the others that exist: having a file is what turns its rules on, and only geoip is fetched without being asked for.

type GeoUpdate added in v0.34.9

type GeoUpdate struct {
	// Updated lists the files that were replaced.
	Updated []string
}

GeoUpdate is the result of UpdateGeoData.

func UpdateGeoData added in v0.34.9

func UpdateGeoData(files []GeoFile) (*GeoUpdate, error)

UpdateGeoData downloads the latest release of each of files. A file whose content already matches the release is left alone. Each file is checked against its SHA-256 digest and replaced atomically, on its own: one that fails leaves the others updated.

type SelfUpdate added in v0.34.9

type SelfUpdate struct {
	// Version is the version updated to.
	Version string
	// contains filtered or unexported fields
}

SelfUpdate is an update of the running executable whose restart is still to come.

func UpdateSelf added in v0.35.0

func UpdateSelf(bin, name string) (*SelfUpdate, error)

UpdateSelf updates the running bin ("nps" or "npc"), installed as the system service name or not, to the latest release as a pending update, leaving the restart to the caller; the new version confirms itself in StartUpdate. A nil update with a nil error means the running version is the latest.

func (*SelfUpdate) Restart added in v0.34.9

func (u *SelfUpdate) Restart() error

Restart makes the calling process continue as the new version; see RestartSelf.

type UpdateOptions added in v0.35.0

type UpdateOptions struct {
	// Force installs the latest release whatever the running version is:
	// again when it is that release, back when it is newer, and also when
	// that release failed before. It lifts no gate of the manifest without
	// an unlock, so it stays within what the rules allow.
	Force bool
	// Pending keeps the replaced files until the new version confirms
	// itself (see StartUpdate); a start that does not is rolled back. Set
	// it when the new version is started right after the update.
	Pending bool
	// Quiet writes the progress as log lines instead of printing it, for
	// an update run by the running daemon rather than from the command
	// line.
	Quiet bool
}

UpdateOptions selects how Update installs a release.

type UpdateResult added in v0.34.9

type UpdateResult struct {
	// Version is the version updated to.
	Version string
	// Replaced are the executables replaced with the new version.
	Replaced []string
	// Running are the other processes that ran a replaced executable when it
	// was replaced; they keep running the old version until restarted.
	Running []int32
	// Services are the services other than the one of the calling process
	// that ran a replaced executable, to be restarted by RestartAfterUpdate.
	Services []string
}

UpdateResult describes a completed update.

func Update added in v0.35.0

func Update(ctx context.Context, bin, service string, o UpdateOptions) (_ *UpdateResult, err error)

Update replaces the executables of bin ("nps" or "npc") with the latest release: the running one and, when the calling process runs as a service whose executable is another file, that file (see updateTargets). Other copies and other instances are left alone: each one updates itself, so its update journal stays next to it. For nps the web assets and the reference config of the run directory are replaced along with them. All files are replaced as one set, so an interrupted update is undone on the next start. A nil result with a nil error means the running version is already the latest. service is the default service name of bin.

Update fetches the signed manifest, picks the release, verifies and replaces the files; selfupdate does each of these, Update only chooses the files and checks that the new executable runs. Restarting is left to the caller: RestartAfterUpdate for the services, or UpdateSelf for the running process.

Jump to

Keyboard shortcuts

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