daemon

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: GPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRestartSocket         = fmt.Errorf("daemon stop requested to wait for socket activation")
	ErrRestartServiceFailure = fmt.Errorf("daemon stop requested due to service failure")
	ErrRestartCheckFailure   = fmt.Errorf("daemon stop requested due to check failure")
)
View Source
var API = []*Command{{

	Path:    "/v1/system-info",
	GuestOK: true,
	GET:     v1SystemInfo,
}, {
	Path:    "/v1/health",
	GuestOK: true,
	GET:     v1Health,
}, {
	Path:   "/v1/warnings",
	UserOK: true,
	GET:    v1GetWarnings,
	POST:   v1AckWarnings,
}, {
	Path:   "/v1/changes",
	UserOK: true,
	GET:    v1GetChanges,
}, {
	Path:   "/v1/changes/{id}",
	UserOK: true,
	GET:    v1GetChange,
	POST:   v1PostChange,
}, {
	Path:   "/v1/changes/{id}/wait",
	UserOK: true,
	GET:    v1GetChangeWait,
}, {
	Path:   "/v1/services",
	UserOK: true,
	GET:    v1GetServices,
	POST:   v1PostServices,
}, {
	Path:   "/v1/services/{name}",
	UserOK: true,
	GET:    v1GetService,
	POST:   v1PostService,
}, {
	Path:   "/v1/plan",
	UserOK: true,
	GET:    v1GetPlan,
}, {
	Path:   "/v1/layers",
	UserOK: true,
	POST:   v1PostLayers,
}, {
	Path:   "/v1/files",
	UserOK: true,
	GET:    v1GetFiles,
	POST:   v1PostFiles,
}, {
	Path:   "/v1/logs",
	UserOK: true,
	GET:    v1GetLogs,
}, {
	Path:   "/v1/exec",
	UserOK: true,
	POST:   v1PostExec,
}, {
	Path:   "/v1/tasks/{task-id}/websocket/{websocket-id}",
	UserOK: true,
	GET:    v1GetTaskWebsocket,
}, {
	Path:   "/v1/signals",
	UserOK: true,
	POST:   v1PostSignals,
}, {
	Path:   "/v1/checks",
	UserOK: true,
	GET:    v1GetChecks,
}, {
	Path:   "/v1/notices",
	UserOK: true,
	GET:    v1GetNotices,
	POST:   v1PostNotices,
}, {
	Path:   "/v1/notices/{id}",
	UserOK: true,
	GET:    v1GetNotice,
}}

Functions

func SetRebootMode

func SetRebootMode(mode RebootMode)

SetRebootMode configures how the system issues a reboot. The default reboot handler mode is SystemdMode, which relies on systemd (or similar) provided functionality to reboot.

Types

type Command

type Command struct {
	Path       string
	PathPrefix string
	//
	GET         ResponseFunc
	PUT         ResponseFunc
	POST        ResponseFunc
	DELETE      ResponseFunc
	GuestOK     bool
	UserOK      bool
	UntrustedOK bool
	AdminOnly   bool
	// contains filtered or unexported fields
}

A Command routes a request to an individual per-verb ResponseFUnc

func (*Command) Daemon

func (c *Command) Daemon() *Daemon

func (*Command) ServeHTTP

func (c *Command) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Daemon

type Daemon struct {
	Version   string
	StartTime time.Time
	// contains filtered or unexported fields
}

A Daemon listens for requests and routes them to the right command

func New

func New(opts *Options) (*Daemon, error)

func (*Daemon) CanStandby

func (d *Daemon) CanStandby() bool

func (*Daemon) Dying

func (d *Daemon) Dying() <-chan struct{}

func (*Daemon) HandleRestart

func (d *Daemon) HandleRestart(t restart.RestartType)

HandleRestart implements overlord.RestartBehavior.

func (*Daemon) Init

func (d *Daemon) Init() error

Init sets up the Daemon's internal workings. Don't call more than once.

func (*Daemon) Overlord

func (d *Daemon) Overlord() *overlord.Overlord

func (*Daemon) RebootIsFine

func (d *Daemon) RebootIsFine(st *state.State) error

RebootIsFine implements part of overlord.RestartBehavior.

func (*Daemon) RebootIsMissing

func (d *Daemon) RebootIsMissing(st *state.State) error

RebootIsMissing implements part of overlord.RestartBehavior.

func (*Daemon) SetDegradedMode

func (d *Daemon) SetDegradedMode(err error)

SetDegradedMode puts the daemon into a degraded mode which will the error given in the "err" argument for commands that are not marked as readonlyOK.

This is useful to report errors to the client when the daemon cannot work because e.g. a sanity check failed or the system is out of diskspace.

When the system is fine again calling "DegradedMode(nil)" is enough to put the daemon into full operation again.

func (*Daemon) SetServiceArgs

func (d *Daemon) SetServiceArgs(serviceArgs map[string][]string) error

SetServiceArgs sets the provided service arguments to their respective services, by passing the arguments to the service manager responsible under daemon overlord.

func (*Daemon) Start

func (d *Daemon) Start() error

func (*Daemon) Stop

func (d *Daemon) Stop(sigCh chan<- os.Signal) error

Stop shuts down the Daemon.

type Options

type Options struct {
	// Dir is the pebble directory where all setup is found. Defaults to /var/lib/pebble/default.
	Dir string

	// SocketPath is an optional path for the unix socket used for the client
	// to communicate with the daemon. Defaults to a hidden (dotted) name inside
	// the pebble directory.
	SocketPath string

	// HTTPAddress is the address for the plain HTTP API server, for example
	// ":4000" to listen on any address, port 4000. If not set, the HTTP API
	// server is not started.
	HTTPAddress string

	// ServiceOuput is an optional io.Writer for the service log output, if set, all services
	// log output will be written to the writer.
	ServiceOutput io.Writer

	// OverlordExtension is an optional interface used to extend the capabilities
	// of the Overlord.
	OverlordExtension overlord.Extension
}

Options holds the daemon setup required for the initialization of a new daemon.

type RebootMode

type RebootMode int
const (
	// Reboot uses systemd
	SystemdMode RebootMode = iota + 1
	// Reboot uses direct kernel syscalls
	SyscallMode
)

type Response

type Response interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Response knows how to serve itself, and how to find itself

func AsyncResponse

func AsyncResponse(result map[string]interface{}, change string) Response

func ErrorResponse added in v1.5.0

func ErrorResponse(status int, format string, v ...interface{}) Response

ErrorResponse builds an error Response that returns the status and formatted message.

If no arguments are provided, formatting is disabled, and the format string is used as is and not interpreted in any way.

func SyncResponse

func SyncResponse(result interface{}) Response

type ResponseFunc

type ResponseFunc func(*Command, *http.Request, *UserState) Response

A ResponseFunc handles one of the individual verbs for a method

type ResponseType

type ResponseType string
const (
	ResponseTypeSync  ResponseType = "sync"
	ResponseTypeAsync ResponseType = "async"
	ResponseTypeError ResponseType = "error"
)

type UserState

type UserState struct{}

UserState represents the state of an authenticated API user.

The struct is currently empty as the behaviors haven't been implemented yet.

Jump to

Keyboard shortcuts

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