geneos

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package geneos provides internal features to manage a typical `Best Practice` installation layout and the conventions that have formed around that structure over many years.

Index

Constants

View Source
const (
	LOCALHOST = "localhost"
	ALLHOSTS  = "all"
)

Default host labels that always exist

View Source
const DisableExtension = "disabled"

DisableExtension is the suffix added to instance config files to mark them disabled

View Source
const OldUserHostFile = "geneos-hosts.json"

OldUserHostFile is a legacy name that will be deprecated in the future

Variables

View Source
var (
	ErrInvalidArgs  = errors.New("invalid arguments")
	ErrNotSupported = errors.New("not supported")
	ErrIsADirectory = errors.New("is a directory")
	ErrDisabled     = errors.New("instance is disabled")
	ErrProtected    = errors.New("instance is protected")
	ErrRunning      = errors.New("instance is running")
	ErrNotRunning   = errors.New("instance is not running")
)

Useful errors for the package to return

Can also be used by other packages

View Source
var RootCAFile = "rootCA"

RootCAFile is the file base name for the root certificate authority created with the TLS commands

View Source
var SigningCertFile string

SigningCertFile is the file base name for the signing certificate created with the TLS commands

Functions

func CleanRelativePath added in v1.5.0

func CleanRelativePath(path string) (clean string, err error)

given a path return a cleaned version. If the cleaning results in and absolute path or one that tries to ascend the tree then return an error

func CompareVersion added in v1.5.0

func CompareVersion(version1, version2 string) int

CompareVersion takes two Geneos package versions and returns an int that is 0 if they are identical, negative if version1 < version2 and positive is version1 > version2. If the version is prefixed with non numeric values then "GA" is always greater thn "RA" (general versus restricted availability) for the same numeric version, otherwise a lexical comparison is done on the prefixes.

If either version is empty or unparseable then the return value is set to favour the other version - or 0 if both are empty strings.

func EvalOptions

func EvalOptions(options ...Options) (d *geneosOptions)

func FilenameFromHTTPResp

func FilenameFromHTTPResp(resp *http.Response, u *url.URL) (filename string, err error)

FilenameFromHTTPResp decodes and returns the filename from the HTTP(S) request. It tried to extract the filename from the COntent-Disposition header and if that fails returns the basename of the URL Path.

func Init

func Init(h *Host, options ...Options) (err error)

Init initialises a Geneos environment by creating a directory structure and then it calls the initialisation functions for each component type registered.

If the directory is not empty and the Force() option is not passed then nothing is changed

func InitHosts added in v1.5.0

func InitHosts(app string)

InitHosts initialises the host settings and is only called from the root command to set the initial values of host.LOCAL and host.ALL and reads the host configuration file. LOCAL and ALL cannot be initialised outside a function as there would be a definition loop.

func Initialise added in v1.5.0

func Initialise(app string)

Initialise is called from the main command initialisation

func Install

func Install(h *Host, ct *Component, options ...Options) (err error)

Install a Geneos software release. The destination host h and the component type ct must be given. options controls behaviour like local only and restarts of affected instances.

func LatestArchive added in v1.5.0

func LatestArchive(r *Host, dir, filterString string, filterFunc func(os.DirEntry) bool) (latest string, err error)

LatestArchive returns the latest archive file for component ct on host r based on semver. A prefix filter can be used to limit matches and a filter function to further refine matches.

If there is semver metadata, check for platform_id on host and remove any non-platform metadata from list before sorting

func LatestVersion added in v1.5.0

func LatestVersion(r *Host, ct *Component, prefix string) (v string, err error)

LatestVersion returns the name of the latest release for component type ct on host h. The comparison is done using semantic versioning and any metadata is ignored. The matching is limited by the optional prefix filter. An error is returned if there are problems accessing the directories or parsing any names as semantic versions.

func LoadHostConfig added in v1.5.0

func LoadHostConfig()

LoadHostConfig loads configuration entries from the host configuration file.

func Open added in v1.5.0

func Open(source string, options ...Options) (from io.ReadCloser, filename string, err error)

Open returns an io.ReadCloser and the base filename for the given source. The source can be a `https` or `http“ URL or a path to a file or '-' for STDIN.

URLs are Parsed and fetched with the `http.Get“ function and so support proxies and basic authentication as supported by the http package.

As a special case, if the file path begins '~/' then it is relative to the home directory of the calling user, otherwise it is opened relative to the working directory of the process. If passed the option `geneos.Homedir()“ then this is used instead of the calling user's home directory

If source is a path to a directory then `geneos.ErrIsADirectory` is returned. If any other stage fails then err is returned from the underlying package.

func ReadFrom added in v1.5.0

func ReadFrom(source string, options ...Options) (b []byte, err error)

ReadFrom opens and, if successful, reads the contents of the source passed, returning a byte slice of the contents or an error. source can be a local file or a URL.

func ReadLocalConfigFile

func ReadLocalConfigFile(file string, config interface{}) (err error)

ReadLocalConfigFile reads a local configuration file without the need for a host connection, primarily for bootstrapping

func Root

func Root() string

Root return the absolute path to the local Geneos installation. If run on an older installation it may return the value from the legacy configuration item `itrshome` if `geneos` is not set.

func SaveHostConfig added in v1.5.0

func SaveHostConfig() error

SaveHostConfig writes the current hosts to the users hosts configuration file

func Update

func Update(h *Host, ct *Component, options ...Options) (err error)

Update will check and update the base link given in the options If the base link exists then the force option must be used to update it, otherwise it is created as expected. When called from unarchive() this allows new installs to work without explicitly calling update.

Types

type Component

type Component struct {
	Initialise       func(*Host, *Component)
	New              func(string) Instance
	Name             string
	LegacyPrefix     string
	RelatedTypes     []*Component
	ComponentMatches []string
	RealComponent    bool
	UsesKeyfiles     bool
	Templates        []Templates
	DownloadBase     DownloadBases
	DownloadInfix    string // if set replace this string with component name for download matches
	PortRange        string
	CleanList        string
	PurgeList        string
	Aliases          map[string]string
	Defaults         []string // ordered list of key=value pairs
	GlobalSettings   map[string]string
	Directories      []string
	GetPID           func(interface{}) (int, error) // if set, use this to get the PID of an instance
}

Component defines a register component

func AllComponents

func AllComponents() (cts []*Component)

AllComponents returns a slice of all registered components, include the Root component type

func FindComponent added in v1.5.0

func FindComponent(component string) *Component

FindComponent returns the component type by iterating over all the names registered by components and returning as soon as any value matches. The comparison is case-insensitive. nil is returned if the component does not match any known name.

func RealComponents

func RealComponents() (cts []*Component)

RealComponents returns a slice of all registered components that have their `RealComponent` field set to true.

func UsesKeyFiles added in v1.5.0

func UsesKeyFiles() (cts []*Component)

UsesKeyFiles returns a slice of registered components that use key files

func (*Component) InstancesDir added in v1.4.1

func (ct *Component) InstancesDir(h *Host) string

InstancesDir return the base directory for the instances of a component

func (Component) IsA added in v1.5.0

func (ct Component) IsA(name ...string) bool

IsA returns true is any of the names match the any of the names defined in ComponentMatches.

func (*Component) MakeComponentDirs added in v1.4.1

func (ct *Component) MakeComponentDirs(h *Host) (err error)

MakeComponentDirs creates the directory structure for the component. If ct is nil then the Root component type is used. If there is an error creating the directory or updating the ownership for superuser then this is immediate returned and the list of directories may only be partially created.

func (*Component) OrList added in v1.5.0

func (ct *Component) OrList(cts ...*Component) []*Component

OrList will return receiver, if not nil, or the list of component types passed as args. If no arguments are passed then all 'real' components (those with the `RealComponent` field set to true) are returned.

func (*Component) RegisterComponent added in v1.4.1

func (ct *Component) RegisterComponent(factory func(string) Instance)

RegisterComponent adds the given Component ct to the internal list of component types. The factory parameter is the Component's New() function, which has to be passed in to avoid initialisation loops as the function refers to the type being registered.

func (*Component) SharedPath added in v1.5.0

func (ct *Component) SharedPath(h *Host, subs ...interface{}) string

SharedPath return the shared directory for the component on host h joined to subdirectories and file given as subs.

func (Component) String

func (ct Component) String() (name string)

type DownloadBases

type DownloadBases struct {
	Resources string
	Nexus     string
}

DownloadBases define the base names for the download archived for standard and nexus downloads

type FileOwner added in v1.5.0

type FileOwner struct {
	Uid uint32
	Gid uint32
}

FileOwner is only available on Linux localhost

type Host added in v1.5.0

type Host struct {
	host.Host
	*config.Config
	// contains filtered or unexported fields
}

Host defines a host for seamless remote management

var (
	LOCAL *Host
	ALL   *Host
)

LOCAL and ALL are the global Host values that represent LOCALHOST and ALLHOSTS from above, and must always exist

func AllHosts added in v1.5.0

func AllHosts() (hs []*Host)

AllHosts returns a slice of all hosts, including LOCAL

func GetHost added in v1.5.0

func GetHost(name string) (h *Host)

GetHost returns a pointer to Host value. If passed an empty name, returns nil. If passed the special values LOCALHOST or ALLHOSTS then it will return the respective special values LOCAL or ALL. Otherwise it tries to lookup an existing host with the given name.

It will return nil if the named host is not found. Use NewHost() to initialise a new host

func Match added in v1.5.0

func Match(h string) (r []*Host)

Match returns a slice of all matching Hosts. Intended for use in range loops where the host could be specific or 'all'. If passed an empty string then returns an empty slice.

func NewHost added in v1.5.0

func NewHost(name string, options ...any) (h *Host)

NewHost is a factory method for Host. It returns an initialised Host and will store it in the global map. If name is "localhost" or "all" then it returns pseudo-hosts used for testing and ranges.

func RemoteHosts added in v1.5.0

func RemoteHosts() (hs []*Host)

RemoteHosts returns a slice of all valid (loaded and reachable) remote hosts

func (*Host) Delete added in v1.5.0

func (h *Host) Delete()

Delete host h from the internal list of hosts. Does not change the on-disk configuration file

func (*Host) Exists added in v1.5.0

func (h *Host) Exists() bool

Exists returns true if the host h has an initialised configuration

To check is a host can be contacted use the IsAvailable() instead

func (*Host) Filepath added in v1.5.0

func (h *Host) Filepath(parts ...interface{}) string

Filepath returns an absolute path rooted in the Geneos home directory on the host. Each argument is used as a path component and are joined using filepath.Join(). Each part can be a plain string or a type with a String() method - non-string types are rendered using fmt.Sprint() without further error checking.

func (*Host) FullName added in v1.5.0

func (h *Host) FullName(name string) string

FullName returns name with the host h label appended if there is no existing host label in the form `instance@host`. Any existing label is not checked or changed.

func (*Host) GetFileOwner added in v1.5.0

func (h *Host) GetFileOwner(info fs.FileInfo) (s FileOwner)

func (*Host) OrList added in v1.5.0

func (h *Host) OrList(hosts ...*Host) []*Host

OrList will return the receiver unless it is nil, or the list of all hosts passed as args. If no args are given and the receiver is nil then all hosts are returned.

func (*Host) ReadCert added in v1.5.0

func (r *Host) ReadCert(path string) (cert *x509.Certificate, err error)

read a PEM encoded cert from path, return the first found as a parsed certificate

func (*Host) ReadKey added in v1.5.0

func (r *Host) ReadKey(path string) (key *memguard.Enclave, err error)

ReadKey reads a keyfile and saves the PEM encoded key in an enclave (without type or headers)

func (*Host) SetOSReleaseEnv added in v1.5.0

func (h *Host) SetOSReleaseEnv() (err error)

SetOSReleaseEnv sets the `osinfo` configuration map to the values from either `/etc/os-release` (or `/usr/lib/os-release`) on Linux or simulates the values for Windows

func (*Host) Valid added in v1.5.0

func (h *Host) Valid()

Valid marks the host loaded and so qualified for saving to the hosts config file

func (*Host) WriteCert added in v1.5.0

func (r *Host) WriteCert(path string, cert *x509.Certificate) (err error)

write cert as PEM to path

func (*Host) WriteCerts added in v1.5.0

func (r *Host) WriteCerts(path string, certs ...*x509.Certificate) (err error)

concatenate certs and write to path

func (*Host) WriteKey added in v1.5.0

func (r *Host) WriteKey(path string, key *memguard.Enclave) (err error)

write a private key as PEM to path. sets file permissions to 0600 (before umask)

type Instance

type Instance interface {
	Config() *config.Config

	// getters and setters
	Name() string
	Home() string
	Type() *Component
	Host() *Host
	String() string

	// config
	Load() error
	Unload() error
	Loaded() bool

	// actions
	Add(template string, port uint16) error
	Command() ([]string, []string)
	Reload(params []string) (err error)
	Rebuild(bool) error
}

Instance interfaces contains the method set for an instance of a registered Component

type Options

type Options func(*geneosOptions)

func Basename

func Basename(b string) Options

Basename sets the package binary basename, defaults to active_prod, for symlinks for update.

func DoUpdate added in v1.4.1

func DoUpdate(r bool) Options

DoUpdate sets the option to also do an update after an install

func Force

func Force(o bool) Options

Force ignores existing directories or files

func LocalOnly

func LocalOnly(l bool) Options

LocalOnly stops downloads from external locations

func NoSave

func NoSave(n bool) Options

NoSave prevents downloads from being saved in the archive directory

func OverrideVersion

func OverrideVersion(s string) Options

OverrideVersion forces a specific version to be used and failure if not available

func Password

func Password(p config.Plaintext) Options

Password is the remote access password for downloads

func PlatformID

func PlatformID(id string) Options

PlatformID sets the (Linux) platform ID from the OS release info. Currently used to distinguish RHEL8 installs from others.

func Restart

func Restart(r bool) Options

Restart sets the instances to be restarted around the update

func Source

func Source(f string) Options

Source is the source of the installation and overrides all other settings include Local and download URLs. It can be a directory, in which case that directory is searched for the appropriate archive file(s)

func UseNexus

func UseNexus() Options

UseNexus sets the flag to use nexus.itrsgroup.com for internal downloads instead of the default download URL in the settings. This also influences the way the remote path is searched and build, not just the base URL.

func UseRoot added in v1.5.0

func UseRoot(h string) Options

UseRoot sets the Geneos installation home directory (aka `geneos` in the settings)

func UseSnapshots

func UseSnapshots() Options

UseSnapshots set the flag to use Nexus Snapshots rather than Releases.

func Username

func Username(u string) Options

Username is the remote access username for downloads

func Version

func Version(v string) Options

Version sets the desired version number, defaults to "latest" in most cases. The version number is in the form `[GA]X.Y.Z` (or `RA` for snapshots)

type ReleaseDetails added in v1.5.0

type ReleaseDetails struct {
	Component string    `json:"Component"`
	Host      string    `json:"Host"`
	Version   string    `json:"Version"`
	Latest    bool      `json:"Latest,string"`
	Links     []string  `json:"Links,omitempty"`
	ModTime   time.Time `json:"LastModified"`
	Path      string    `json:"Path"`
}

type Releases added in v1.5.0

type Releases []ReleaseDetails

func GetReleases added in v1.5.0

func GetReleases(h *Host, ct *Component) (releases Releases, err error)

GetReleases returns a slice of PackageDetails containing all the directories Geneos packages directory on the given host. Symlinks in the packages directory are matches to any targets and unmatched symlinks are ignored.

No validation is done on the contents, only that a directory exists.

func (Releases) Len added in v1.5.0

func (r Releases) Len() int

func (Releases) Less added in v1.5.0

func (r Releases) Less(i, j int) bool

func (Releases) Swap added in v1.5.0

func (r Releases) Swap(i, j int)

type Templates added in v1.5.0

type Templates struct {
	Filename string
	Content  []byte
}

Templates define the filename and embedded content for template files

Jump to

Keyboard shortcuts

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