runner

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package runner exposes the APIs used by God for deploy and manage services in the Go ecosystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	User           string `yaml:"user"`
	Host           string `yaml:"host"`
	Port           string `yaml:"port"`
	PrivateKeyPath string `yaml:"private_key_path"`

	GoExecPath     string `yaml:"go_exec_path"`
	GoBinDirectory string `yaml:"go_bin_directory"`
	GoInstall      string `yaml:"go_install"`

	GoPrivate     string `yaml:"go_private"`
	NetrcMachine  string `yaml:"netrc_machine"`
	NetrcLogin    string `yaml:"netrc_login"`
	NetrcPassword string `yaml:"netrc_password"`

	SystemdPath              string `yaml:"systemd_path"`
	SystemdServicesDirectory string `yaml:"systemd_services_directory"`
	SystemdLingerDirectory   string `yaml:"systemd_linger_directory"`

	ExecStart             string `yaml:"exec_start"`
	WorkingDirectory      string `yaml:"working_directory"`
	Environment           string `yaml:"environment"`
	LogPath               string `yaml:"log_path"`
	RunAfterService       string `yaml:"run_after_service"`
	StartLimitBurst       int    `yaml:"start_limit_burst"`
	StartLimitIntervalSec int    `yaml:"start_limit_interval_sec"`
	RestartSec            int    `yaml:"restart_sec"`

	CopyFiles []string `yaml:"copy_files"`

	Ignore bool `yaml:"ignore"`
}

Conf holds a service configuration.

type MessageStatus

type MessageStatus uint8

Types of messages. Types are normal, success and error.

const (
	// Normal message (uncolored)
	MessageNormal MessageStatus = 1 << iota // 1 << 0 which is 00000001
	// Success message (green)
	MessageSuccess // 1 << 1 which is 00000010
	// Error message (red)
	MessageError // 1 << 2 which is 00000100
	// Warning message (yellow)
	MessageWarning // 1 << 3 which is 00001000
)

type Runner

type Runner struct {
	QuietMode bool
	// contains filtered or unexported fields
}

func MakeRunner

func MakeRunner(confFilePath string) (*Runner, error)

MakeRunner loads the configuration from confFilePath and returns an initialized Runner.

func (*Runner) GetServiceNames

func (r *Runner) GetServiceNames() []string

GetServiceNames returns a slice with all not ignored services found in the configuration file.

func (*Runner) MakeService

func (r *Runner) MakeService(serviceName string) (Service, error)

MakeService makes a new Service using the configuration under serviceName key in the configuration file.

func (*Runner) SendMessage

func (runner *Runner) SendMessage(serviceName, text string, status MessageStatus)

SendMessage writes a message in the runner channel that can be captured and printed by the go routine started with StartPrintOutput.

func (*Runner) StartPrintOutput

func (runner *Runner) StartPrintOutput(services []string)

StartPrintOutput starts a go routine that read messages from runner channel and prints them.

func (*Runner) StopPrintOutput

func (runner *Runner) StopPrintOutput()

StopPrintOutput stop the go routine started with StartPrintOutput.

type Service

type Service struct {
	// The service name (key in the configuration YAML file)
	Name string
	// Configuration under the key in the configuration YAML file
	Conf *Conf
	// contains filtered or unexported fields
}

Service represents a service that will be installed and launched on the remote machine.

func (*Service) AuthPrivateRepo

func (s *Service) AuthPrivateRepo() error

func (*Service) CheckGo

func (s *Service) CheckGo() error

func (*Service) CheckLingering

func (s *Service) CheckLingering() error

func (*Service) CheckSystemd

func (s *Service) CheckSystemd() error

func (*Service) CheckWorkingDir added in v0.1.0

func (s *Service) CheckWorkingDir(createWorkingDirectory bool) error

func (*Service) CopyFile

func (service *Service) CopyFile(path, workingDirectory string) error

CopyFile copies the local file on the remote host to the remote workingDirectory. If the local file is a directory, create the directory on the remote host and recursively copy all files inside.

func (*Service) CopyFiles added in v0.1.0

func (s *Service) CopyFiles() error

func (*Service) CopyUnitServiceFile added in v0.1.0

func (service *Service) CopyUnitServiceFile() error

CopyUnitServiceFile copies the systemd unit service file on the remote host.

func (*Service) CreateServiceFile

func (s *Service) CreateServiceFile() error

func (*Service) DeleteDirIfEmpty added in v0.1.0

func (service *Service) DeleteDirIfEmpty(dirPath string) error

DeleteDirIfEmpty deletes remote directory only if empty.

func (*Service) DeleteExecutable

func (s *Service) DeleteExecutable() error

func (*Service) DeleteFile added in v0.1.0

func (service *Service) DeleteFile(path, workingDirectory string) error

DeleteFile deletes the file on the remote host relative to the remote workingDirectory.

func (*Service) DeleteFiles added in v0.1.0

func (s *Service) DeleteFiles(removeWorkingDirectory bool) error

func (*Service) DeleteServiceFile

func (s *Service) DeleteServiceFile() error

func (*Service) DisableService

func (s *Service) DisableService() error

func (*Service) EnableService

func (s *Service) EnableService() error

func (*Service) Exec

func (service *Service) Exec(cmd string) (string, error)

Exec runs cmd on the remote host.

func (*Service) GenerateServiceFile

func (service *Service) GenerateServiceFile(buf io.Writer)

GenerateServiceFile generates the systemd unit service file using the service configuration.

func (*Service) Install

func (s *Service) Install(createWorkingDirectory bool) error

func (*Service) InstallExecutable

func (s *Service) InstallExecutable() error

func (*Service) ParseCommand

func (service *Service) ParseCommand(cmd string) string

ParseCommand parses the cmd string replacing the variables with those present in the configuration.

func (*Service) PrintExec

func (service *Service) PrintExec(cmd, errorMessage string) error

PrintExec runs cmd on the remote host and sends the output on the runner channel.

func (*Service) ReloadDaemon

func (s *Service) ReloadDaemon() error

func (*Service) ResetFailedServices

func (s *Service) ResetFailedServices() error

func (*Service) RestartService

func (s *Service) RestartService() error

func (*Service) ShowServiceFile

func (s *Service) ShowServiceFile()

func (*Service) StartService

func (s *Service) StartService() error

func (*Service) StatusService

func (s *Service) StatusService() error

func (*Service) StopService

func (s *Service) StopService() error

func (*Service) Uninstall

func (s *Service) Uninstall(removeWorkingDirectory bool)

Jump to

Keyboard shortcuts

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