creatavisor

package module
v0.0.0-...-c067c3c Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoUpgrade

func DoUpgrade(cfg *Config, info *UpgradeInfo) error

DoUpgrade will be called after the log message has been parsed and the process has terminated. We can now make any changes to the underlying directory without interference and leave it in a state, so we can make a proper restart

func DownloadBinary

func DownloadBinary(cfg *Config, info *UpgradeInfo) error

DownloadBinary will grab the binary and place it in the proper directory

func EnsureBinary

func EnsureBinary(path string) error

EnsureBinary ensures the file exists and is executable, or returns an error

func GetDownloadURL

func GetDownloadURL(info *UpgradeInfo) (string, error)

GetDownloadURL will check if there is an arch-dependent binary specified in Info

func LaunchProcess

func LaunchProcess(cfg *Config, args []string, stdout, stderr io.Writer) (bool, error)

LaunchProcess runs a subprocess and returns when the subprocess exits, either when it dies, or *after* a successful upgrade.

func MarkExecutable

func MarkExecutable(path string) error

MarkExecutable will try to set the executable bits if not already set Fails if file doesn't exist or we cannot set those bits

func OSArch

func OSArch() string

Types

type Config

type Config struct {
	Home                  string
	Name                  string
	AllowDownloadBinaries bool
	RestartAfterUpgrade   bool
}

Config is the information passed in to control the daemon

func GetConfigFromEnv

func GetConfigFromEnv() (*Config, error)

GetConfigFromEnv will read the environmental variables into a config and then validate it is reasonable

func (*Config) CurrentBin

func (cfg *Config) CurrentBin() (string, error)

CurrentBin is the path to the currently selected binary (genesis if no link is set) This will resolve the symlink to the underlying directory to make it easier to debug

func (*Config) GenesisBin

func (cfg *Config) GenesisBin() string

GenesisBin is the path to the genesis binary - must be in place to start manager

func (*Config) Root

func (cfg *Config) Root() string

Root returns the root directory where all info lives

func (*Config) SetCurrentUpgrade

func (cfg *Config) SetCurrentUpgrade(upgradeName string) error

SetCurrentUpgrade sets the named upgrade to be the current link, returns error if this binary doesn't exist

func (*Config) SymLinkToGenesis

func (cfg *Config) SymLinkToGenesis() (string, error)

Symlink to genesis

func (*Config) UpgradeBin

func (cfg *Config) UpgradeBin(upgradeName string) string

UpgradeBin is the path to the binary for the named upgrade

func (*Config) UpgradeDir

func (cfg *Config) UpgradeDir(upgradeName string) string

UpgradeDir is the directory named upgrade

type UpgradeConfig

type UpgradeConfig struct {
	Binaries map[string]string `json:"binaries"`
}

UpgradeConfig is expected format for the info field to allow auto-download

type UpgradeInfo

type UpgradeInfo struct {
	Name string
	Info string
}

UpgradeInfo is the details from the regexp

func WaitForUpdate

func WaitForUpdate(scanner *bufio.Scanner) (*UpgradeInfo, error)

WaitForUpdate will listen to the scanner until a line matches upgradeRegexp. It returns (info, nil) on a matching line It returns (nil, err) if the input stream errored It returns (nil, nil) if the input closed without ever matching the regexp

func WaitForUpgradeOrExit

func WaitForUpgradeOrExit(cmd *exec.Cmd, scanOut, scanErr *bufio.Scanner) (*UpgradeInfo, error)

WaitForUpgradeOrExit listens to both output streams of the process, as well as the process state itself When it returns, the process is finished and all streams have closed.

It returns (info, nil) if an upgrade should be initiated (and we killed the process) It returns (nil, err) if the process died by itself, or there was an issue reading the pipes It returns (nil, nil) if the process exited normally without triggering an upgrade. This is very unlikely to happened with "start" but may happened with short-lived commands like `creatad export ...`

type WaitResult

type WaitResult struct {
	// contains filtered or unexported fields
}

WaitResult is used to wrap feedback on cmd state with some mutex logic. This is needed as multiple go-routines can affect this - two read pipes that can trigger upgrade As well as the command, which can fail

func (*WaitResult) AsResult

func (u *WaitResult) AsResult() (*UpgradeInfo, error)

AsResult reads the data protected by mutex to avoid race conditions

func (*WaitResult) SetError

func (u *WaitResult) SetError(myErr error)

SetError will set with the first error using a mutex don't set it once info is set, that means we chose to kill the process

func (*WaitResult) SetUpgrade

func (u *WaitResult) SetUpgrade(up *UpgradeInfo)

SetUpgrade sets first non-nil upgrade info, ensure error is then nil pass in a command to shutdown on successful upgrade

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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