Documentation
¶
Index ¶
- Variables
- func CanRestartSelf() bool
- func ConfigureService(c *service.Config)
- func ControlService(s service.Service, name, action string) error
- func CopyDir(srcPath string, destPath string) error
- func GeoDataVersion(ipPath string) string
- func LatestVersion() string
- func NPC() (string, error)
- func NPS() (string, error)
- func Relaunch(exe string) error
- func RemoveStaleExecutables()
- func RestartAfterUpdate(s service.Service, name string, replaced []string) error
- func RestartSelf(exe string) error
- func SetGeoDataPaths(ipPath, sitePath string)
- func SyncGeoData(srcConf, ipPath, sitePath string) error
- func UninstallService(s service.Service, name string) error
- func UpdateAvailable() bool
- func UpdateSelfNpc(name string) error
- func WaitForRelaunch()
- func WarnOldProcesses(pids []int32)
- type GeoFile
- type GeoUpdate
- type SelfUpdate
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
var BuildTarget string
var ErrRestartUnsupported = errors.New("a process not run as a Windows service cannot restart itself reliably")
ErrRestartUnsupported is returned by UpdateSelf where the calling process cannot restart itself reliably.
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 the process image is replaced in place. A Windows process has to be started anew; that is only reliable for a service, which the service manager restarts, while whatever started any other process would see it exit.
func ConfigureService ¶ added in v0.34.9
ConfigureService sets the platform specific settings of c.
func ControlService ¶ added in v0.34.8
ControlService runs a service control action. SysV init systems are driven through the init script directly so BusyBox based systems such as OpenWrt work as well.
func CopyDir ¶
CopyDir copies the files under srcPath into destPath, creating directories as needed.
func GeoDataVersion ¶ added in v0.34.9
GeoDataVersion returns the release the geodata files next to ipPath come from, "" when unknown.
func LatestVersion ¶ added in v0.34.9
func LatestVersion() string
LatestVersion returns the tag of the latest release as last queried, or "" before a query succeeded. A stale or missing tag is queried again in the background, every 6 hours, or 10 minutes after a failure.
func NPC ¶ added in v0.34.8
NPC installs the npc executable and returns the path the service should run.
func NPS ¶ added in v0.34.8
NPS installs the nps executable, web assets and, on a fresh install, the config directory. It returns the path the service should run.
func Relaunch ¶ added in v0.34.9
Relaunch replaces the calling process, which does not run as a service, with exe run with the same arguments and environment. On Unix the process image is replaced in place. Windows has no such call: exe is started to wait for the caller to exit, and the caller exits.
func RemoveStaleExecutables ¶ added in v0.34.8
func RemoveStaleExecutables()
RemoveStaleExecutables deletes executables that an earlier update moved aside on Windows. They stay locked until the process running them exits, so failures are ignored and retried on the next start or update.
func RestartAfterUpdate ¶ added in v0.34.8
RestartAfterUpdate restarts the service so it runs the replaced executables. Only an installed and running service is restarted; otherwise the new version takes effect on the next start. When the service is known to run an executable outside replaced it is left alone, since a restart would not pick up the update. A nil s means the service manager is unavailable.
func RestartSelf ¶ added in v0.34.9
RestartSelf makes the calling process continue as exe, the executable an update replaced, and returns only on failure, with one exception: a Windows service hands the restart to the service manager and returns at once, to be stopped by it shortly. On Unix 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 SetGeoDataPaths ¶ added in v0.34.9
func SetGeoDataPaths(ipPath, sitePath string)
SetGeoDataPaths sets where nps keeps its geodata files, for update to refresh them from the release package.
func SyncGeoData ¶ added in v0.34.9
SyncGeoData copies the geodata files of an unpacked release in srcConf to ipPath and sitePath when the release has newer ones than those in place, or when a file is missing. Newer files from UpdateGeoData are kept.
func UninstallService ¶ added in v0.34.9
UninstallService 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.
func UpdateAvailable ¶ added in v0.34.9
func UpdateAvailable() bool
UpdateAvailable reports whether the latest release known is newer than this build.
func UpdateSelfNpc ¶ added in v0.34.9
UpdateSelfNpc updates the running npc, installed as the system service name or not, to the latest release and restarts it as the new version. It returns nil without restarting when the running version is the latest; otherwise it returns only on failure, or at once for a Windows service, which the service manager then restarts.
func WaitForRelaunch ¶ added in v0.34.9
func WaitForRelaunch()
WaitForRelaunch waits, in a process started by Relaunch, until the process it replaces has exited and released what it held, such as its ports.
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
GeoFile is one geodata file: its name in the release and its local path.
type GeoUpdate ¶ added in v0.34.9
type GeoUpdate struct {
// Version is the release the files now come from, "" when unknown.
Version string
// Updated lists the files that were replaced.
Updated []string
}
GeoUpdate is the result of UpdateGeoData.
func UpdateGeoData ¶ added in v0.34.9
UpdateGeoData downloads the latest geoip.dat and geosite.dat to ipPath and sitePath. A file whose content already matches the release is left alone. Each file is checked against its SHA-256 digest and replaced atomically, so that a reader never sees a partial file.
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 UpdateSelfNps ¶ added in v0.34.9
func UpdateSelfNps(name string) (*SelfUpdate, error)
UpdateSelfNps updates the running nps, installed as the system service name or not, to the latest release, leaving the restart to the caller. A nil update with a nil error means the running version is the latest; an update with an error means the executables were replaced but the web assets were not, and the restart is still due.
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 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
}
UpdateResult describes a completed update.
func ForceUpdateNpc ¶ added in v0.34.10
func ForceUpdateNpc(service string) (*UpdateResult, error)
ForceUpdateNpc installs the latest client release regardless of the running version.
func ForceUpdateNps ¶ added in v0.34.10
func ForceUpdateNps(service string) (*UpdateResult, error)
ForceUpdateNps installs the latest server release regardless of the running version.
func UpdateNpc ¶
func UpdateNpc(service string) (*UpdateResult, error)
UpdateNpc replaces the npc executables with the latest release. A nil result with a nil error means the running version is already the latest.
func UpdateNps ¶
func UpdateNps(service string) (*UpdateResult, error)
UpdateNps replaces the nps executables with the latest release and then refreshes the web assets of the current run directory. A nil result with a nil error means the running version is already the latest.