ctrl

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 14 Imported by: 9

README

gone daemon ctrl

Package gone/daemon/crtl creates general UNIX domain socket server which can execute commands inside the daemon process by implementing a simple Command interface.

Commands can be long-running (as outputting accesslog) and client connections to the socket will survive daemon reload and re-spawning.

This has all kinds of potential usage. Inspecting and/or manipulating state, tweaking log levels and in general instrument the daemon in ways not possible with simple OS signaling.

You can connect to the socket with simple command line tools:

rlwrap nc -U /var/run/mydaemon/cmd.sock

or feed it commands directly:

cat <(echo accesslog) - | nc -U /var/run/mydaemon/cmd.sock

The ctrl package is still somewhat experimental in terms of concept and API.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCommand

func RegisterCommand(name string, cmd Command)

RegisterCommand registers an implementation of the Command interface under a command name

Types

type Command

type Command interface {
	// ShotUsage provides a short description of command argument syntax and possibly a comment.
	// to be printed a listing of commands.
	ShortUsage() (syntax string, comment string)

	// Usage let the command provide it's own full documentation, being passed the command name
	// the command is registered under.
	Usage(cmd string, out io.Writer)

	// Invoke invokes the command being passed a context an io.Writer to the socket
	// the command name used to invoke it and it's arguments.
	// Invoke has the option of returning function to be invoked
	// asynchronously and - optionally command line to potentially make it persistent.
	// The persistent command will be re-executed
	// after a reload - whether or not that is in a new process
	Invoke(ctx context.Context, conn io.Writer, cmd string, args []string) (async func(), persistent string, err error)
}

Command is the interface of a specific command

type Server

type Server struct {

	// Path on which the server will listen.
	Addr string
	// Systemd socket name. If no Addr is given the socket can be provided
	// via systemd socket activation.
	ListenerFdName string

	// The command invoking the help system
	HelpCommand string
	// The command to cause the server to close a connection.
	QuitCommand string

	// The command to cause the server to close a connection after replying
	OneshotCommand string

	// A logger to log errors during client connections to.
	Logger srv.LoggerFunc
	// contains filtered or unexported fields
}

Server implements a server accepting connections on a UNIX domain socket on which registered commands can be invoked. The client connections to this socket will survive process Reload and Replacement.

func (*Server) Description

func (s *Server) Description() string

Description implement gone/daemon/srv.Descripter interface.

func (*Server) Listen

func (s *Server) Listen() (err error)

Listen implement the gone/daemon/srv.Listener interface and pick an already open listener FD or create one.

func (*Server) Serve

func (s *Server) Serve() (err error)

Serve implement the gone/daemon/srv.Server interface. It is synchronous (does not implement Wait). All connections should exit ASAP when Shutdown is called.

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown implements the srv.Server interface for the control socket server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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