package daemon

import ""

Package daemon implements a service for mediating access to the data store, and its client.

Most RPCs exposed by the service correspond to the methods of Store in the store package and are not documented here.


Package Files

client.go daemon.go serve.go service.go sock_unix.go spawn.go spawn_unix.go umask_unix.go


const Version = -93

Version is the API version. It should be bumped any time the API changes.


var (
    // ErrDaemonUnreachable is returned when the daemon cannot be reached after
    // several retries.
    ErrDaemonUnreachable = errors.New("daemon offline")
var Program prog.Program = program{}

Program is the daemon subprogram.

func Serve

func Serve(sockpath, dbpath string)

Serve runs the daemon service, listening on the socket specified by sockpath and serving data from dbpath. It quits upon receiving SIGTERM, SIGINT or when all active clients have disconnected.

func Spawn

func Spawn(cfg *SpawnConfig) error

Spawn spawns a daemon process in the background by invoking BinPath, passing BinPath, DbPath and SockPath as command-line arguments after resolving them to absolute paths. The daemon log file is created in RunDir, and the stdout and stderr of the daemon is redirected to the log file.

A suitable ProcAttr is chosen depending on the OS and makes sure that the daemon is detached from the current terminal, so that it is not affected by I/O or signals in the current terminal and keeps running after the current process quits.

type Client

type Client interface {

    ResetConn() error
    Close() error

    Pid() (int, error)
    SockPath() string
    Version() (int, error)

Client represents a daemon client.

func NewClient

func NewClient(sockPath string) Client

NewClient creates a new Client instance that talks to the socket. Connection creation is deferred to the first request.

type SpawnConfig

type SpawnConfig struct {
    // BinPath is the path to the Elvish binary itself, used when forking. This
    // field is used only when spawning the daemon. If empty, it is
    // automatically determined with os.Executable.
    BinPath string
    // DbPath is the path to the database.
    DbPath string
    // SockPath is the path to the socket on which the daemon will serve
    // requests.
    SockPath string
    // RunDir is the directory in which to place the daemon log file.
    RunDir string

SpawnConfig keeps configurations for spawning the daemon.

Package daemon imports 15 packages (graph) and is imported by 3 packages. Updated 3 weeks ago.

Tools for package owners.