Documentation
¶
Index ¶
- Variables
- func AsConn(file *os.File) (net.Conn, error)
- func AsListener(file *os.File) (net.Listener, error)
- func IsValidFDName(name string) bool
- func Notify(state ...State) error
- func NotifyConn(conn *net.UnixConn, state ...State) error
- func NotifySocket() (*net.UnixConn, error)
- func NotifySocketNamed(name string) (*net.UnixConn, error)
- func NotifyWithFDs(name string, files []*os.File, state ...State) error
- func NotifyWithFDsConn(conn *net.UnixConn, name string, files []*os.File, state ...State) error
- func WaitBarrier(timeout time.Duration) error
- func WaitBarrierConn(conn *net.UnixConn, timeout time.Duration) error
- type ConnEntry
- type Entry
- type Filer
- type ListenerEntry
- type LogFn
- type NotifyAccessOption
- type Option
- type State
- type Store
- func (s *Store) AddConn(conn net.Conn, name string, data []byte) error
- func (s *Store) AddFile(file *os.File, name string, data []byte) error
- func (s *Store) AddFiler(filer Filer, name string, data []byte) error
- func (s *Store) AddListener(ln net.Listener, name string, state []byte) error
- func (s *Store) Close()
- func (s *Store) RemoveConn(name string) (res []ConnEntry, err error)
- func (s *Store) RemoveFile(name string) []Entry
- func (s *Store) RemoveListener(name string) (res []ListenerEntry, err error)
- func (s *Store) Restore()
- func (s *Store) RestoreFilelist(filelist map[string][]*os.File)
- func (s *Store) Send() error
- func (s *Store) SendConn(conn *net.UnixConn) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrShortWrite = errors.New("short write") ErrNoFile = errors.New("File method missing") ErrNoSocket = errors.New("NOTIFY_SOCKET is empty") ErrNotOurName = errors.New("FDNAME was not the correct format") ErrWrongType = errors.New("fd is of the wrong type") ErrDataRead = errors.New("failed to read data from memfd") ErrUnexpectedRead = errors.New("did not expect to read anything") )
var ( NOTIFY_SOCKET = "NOTIFY_SOCKET" LISTEN_PID = "LISTEN_PID" LISTEN_FDS = "LISTEN_FDS" LISTEN_FDNAMES = "LISTEN_FDNAMES" )
Functions ¶
func AsConn ¶
AsConn is a helper function that tries to convert the file given to a net.Conn, the passed in file is closed on success
func AsListener ¶
AsListener is a helper function that tries to convert the file given to a net.Listener, the passed in file is closed on success
func IsValidFDName ¶
func Notify ¶
Notify is like sd_notify (https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#Description)
func NotifyConn ¶
NotifyConn is like sd_notify (https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#Description), but lets you pass in your own connection to use to write to
func NotifySocket ¶
NotifySocket returns a connected UnixConn to the path in env NOTIFY_SOCKET
func NotifySocketNamed ¶ added in v1.2.0
NotifySocketNamed is like NotifySocket but lets you pick the name of the socket
func NotifyWithFDs ¶
NotifyWithFDs is like sd_notify_with_fds We add FDSTORE=1 and FDNAME={name} for you with the name given, the rest of state is prepended before the other two
func NotifyWithFDsConn ¶
NotifyWithFDsConn is NotifyWithFDs but lets you pass your own connection
func WaitBarrier ¶
WaitBarrier is like sd_notify_barrier
Types ¶
type ListenerEntry ¶
ListenerEntry is the type returned by the RemoveListener helper
type NotifyAccessOption ¶
type NotifyAccessOption string
const ( NotifyAccessNone NotifyAccessOption = "none" NotifyAccessAll NotifyAccessOption = "all" NotifyAccessMain NotifyAccessOption = "main" NotifyAccessExec NotifyAccessOption = "exec" )
type Option ¶ added in v1.2.0
type Option func(*storeOptions)
func ListenFDNamesOpt ¶ added in v1.2.0
ListenFDNamesOpt changes what environment variable to use instead of LISTEN_FDNAMES
func ListenFDStartOpt ¶ added in v1.2.0
ListenFDStartOpt changes at what fd number to start, the default is 3 since 0, 1, 2 are stdin, stdout, stderr respectively.
func ListenFDsOpt ¶ added in v1.2.0
ListenFDsOpt changes what environment variable to use instead of LISTEN_FDS
func ListenPIDOpt ¶ added in v1.2.0
ListenPIDOpt changes what environment variable to use instead of LISTEN_PID
func LoggerOpt ¶ added in v1.2.0
LoggerOpt changes where log lines go to, the default uses the log pkg
func NotifySocketOpt ¶ added in v1.2.0
NotifySocketOpt changes what environment variable to use instead of NOTIFY_SOCKET
type State ¶
type State string
func FDStoreRemove ¶
func MonotonicUsec ¶
func MonotonicUsec() State
MonotonicUsec is not implemented, since there is no clear way to get the value of CLOCK_MONOTONIC right now
func NotifyAccess ¶
func NotifyAccess(na NotifyAccessOption) State
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an abstraction on top of the file descriptor store of systemd, it lets you collect files, connections and listeners before sending them over to systemd for storage during restarts
func NewStore ¶
NewStore creates a new Store instance with the options given. Store is an abstraction on top of the systemd file descriptor store interface that lets you pass fds to systemd between service restarts. The defaults are configured to use what systemd uses.
func NewStoreListenFDs ¶
func NewStoreListenFDs() *Store
NewStoreListenFDs is a helper function to use the systemd default configuration and read and process the files stored in the fdstore. Equal to NewStore() followed by a call to Restore()
func (*Store) AddConn ¶
AddConn is like AddFile but takes a net.Conn, it is expected that the net.Conn given implements Filer. AddConn duplicates the connection fd
Returns error matching ErrNoFile if no File method was found or whatever the call to File() itself returns if it errors
func (*Store) AddFile ¶
AddFile adds a file to the store with the name given and associated data. The data is stored in an memfd when passed through the socket and can be any kind of data. The file given is duplicated before storing it
func (*Store) AddFiler ¶
AddFiler is like AddFile but takes any type with a File() (*os.File, error) method
Returns error from File() if any.
func (*Store) AddListener ¶
AddListener is like AddFile but takes a net.Listener, is is expected that the net.Listener given implements Filer. AddListener duplicates the listener fd
Returns error matching ErrNoFile if no File method was found or whatever the call to File() itself returns if it errors
func (*Store) Close ¶
func (s *Store) Close()
Close calls close on all files contained in the store and empties its internal map
func (*Store) RemoveConn ¶
RemoveConn finds and removes the entries associated with the name given and tries to return them as net.Conn, entries are not removed or returned if an error occurs.
Returns error matching ErrWrongType if an entry could not be converted
func (*Store) RemoveFile ¶
RemoveFile finds and removes the entries associated with the name given and returns them.
func (*Store) RemoveListener ¶
func (s *Store) RemoveListener(name string) (res []ListenerEntry, err error)
RemoveConn finds and removes the entries associated with the name given and tries to return them as net.Listener, entries are not removed or returned if an error occurs.
Returns error matching ErrWrongType if an entry could not be converted
func (*Store) Restore ¶ added in v1.2.0
func (s *Store) Restore()
Restore tries to restore the files from the fdstore, files that don't match what we expect are closed and removed from the fdstore through FDSTOREREMOVE, the environment variables configured to be used are unset after a call to Restore
func (*Store) RestoreFilelist ¶ added in v1.2.0
RestoreFilelist takes a list of files with names, typically retrieved from another process and tries to parse the names as if they were send by Store.Send