Documentation
¶
Overview ¶
Package daemon runs one modlock process per state directory that owns the creator's store and peer, and connects the other modlock processes to it.
The daemon holds an exclusive lock on its directory's daemon.lock for its whole life and serves starpc over a local socket beside it. A client holds start.lock while it connects, and starts a detached daemon when none answers, waiting for its ready line. A daemon started by hand takes start.lock while it binds, one that Start launched relies on its starter holding it, and idle shutdown takes it too, so a client sees either a daemon that is listening or no daemon at all, never one that is closing.
Index ¶
- Constants
- Variables
- func Dir() (string, error)
- func NewSRPCDaemonHandler(impl SRPCDaemonServer, serviceID string) srpc.Handler
- func Ready()
- func SRPCRegisterDaemon(mux srpc.Mux, impl SRPCDaemonServer) error
- func Serve(ctx context.Context, dir, version string, idle time.Duration, mux srpc.Mux, ...) error
- func Start(ctx context.Context, exe string, args []string, logPath string) error
- func Stop(ctx context.Context, dir string) (bool, error)
- type Client
- type GetStatusRequest
- func (m *GetStatusRequest) CloneMessageVT() protobuf_go_lite.CloneMessage
- func (m *GetStatusRequest) CloneVT() *GetStatusRequest
- func (this *GetStatusRequest) EqualMessageVT(thatMsg any) bool
- func (this *GetStatusRequest) EqualVT(that *GetStatusRequest) bool
- func (x *GetStatusRequest) MarshalJSON() ([]byte, error)
- func (x *GetStatusRequest) MarshalProtoJSON(s *json.MarshalState)
- func (x *GetStatusRequest) MarshalProtoText() string
- func (m *GetStatusRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *GetStatusRequest) MarshalToVT(dAtA []byte) (int, error)
- func (m *GetStatusRequest) MarshalVT() (dAtA []byte, err error)
- func (*GetStatusRequest) ProtoMessage()
- func (x *GetStatusRequest) Reset()
- func (m *GetStatusRequest) SizeVT() (n int)
- func (x *GetStatusRequest) String() string
- func (x *GetStatusRequest) UnmarshalJSON(b []byte) error
- func (x *GetStatusRequest) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (m *GetStatusRequest) UnmarshalVT(dAtA []byte) error
- type GetStatusResponse
- func (m *GetStatusResponse) CloneMessageVT() protobuf_go_lite.CloneMessage
- func (m *GetStatusResponse) CloneVT() *GetStatusResponse
- func (this *GetStatusResponse) EqualMessageVT(thatMsg any) bool
- func (this *GetStatusResponse) EqualVT(that *GetStatusResponse) bool
- func (x *GetStatusResponse) GetClients() uint32
- func (x *GetStatusResponse) GetPid() uint32
- func (x *GetStatusResponse) GetStartedUnixMs() int64
- func (x *GetStatusResponse) GetVersion() string
- func (x *GetStatusResponse) MarshalJSON() ([]byte, error)
- func (x *GetStatusResponse) MarshalProtoJSON(s *json.MarshalState)
- func (x *GetStatusResponse) MarshalProtoText() string
- func (m *GetStatusResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *GetStatusResponse) MarshalToVT(dAtA []byte) (int, error)
- func (m *GetStatusResponse) MarshalVT() (dAtA []byte, err error)
- func (*GetStatusResponse) ProtoMessage()
- func (x *GetStatusResponse) Reset()
- func (m *GetStatusResponse) SizeVT() (n int)
- func (x *GetStatusResponse) String() string
- func (x *GetStatusResponse) UnmarshalJSON(b []byte) error
- func (x *GetStatusResponse) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (m *GetStatusResponse) UnmarshalVT(dAtA []byte) error
- type SRPCDaemonClient
- type SRPCDaemonHandler
- func (SRPCDaemonHandler) GetMethodIDs() []string
- func (d *SRPCDaemonHandler) GetServiceID() string
- func (d *SRPCDaemonHandler) InvokeMethod(serviceID, methodID string, strm srpc.Stream) (bool, error)
- func (SRPCDaemonHandler) InvokeMethod_GetStatus(impl SRPCDaemonServer, strm srpc.Stream) error
- func (SRPCDaemonHandler) InvokeMethod_Stop(impl SRPCDaemonServer, strm srpc.Stream) error
- type SRPCDaemonServer
- type SRPCDaemon_GetStatusStream
- type SRPCDaemon_StopStream
- type StopRequest
- func (m *StopRequest) CloneMessageVT() protobuf_go_lite.CloneMessage
- func (m *StopRequest) CloneVT() *StopRequest
- func (this *StopRequest) EqualMessageVT(thatMsg any) bool
- func (this *StopRequest) EqualVT(that *StopRequest) bool
- func (x *StopRequest) MarshalJSON() ([]byte, error)
- func (x *StopRequest) MarshalProtoJSON(s *json.MarshalState)
- func (x *StopRequest) MarshalProtoText() string
- func (m *StopRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *StopRequest) MarshalToVT(dAtA []byte) (int, error)
- func (m *StopRequest) MarshalVT() (dAtA []byte, err error)
- func (*StopRequest) ProtoMessage()
- func (x *StopRequest) Reset()
- func (m *StopRequest) SizeVT() (n int)
- func (x *StopRequest) String() string
- func (x *StopRequest) UnmarshalJSON(b []byte) error
- func (x *StopRequest) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (m *StopRequest) UnmarshalVT(dAtA []byte) error
- type StopResponse
- func (m *StopResponse) CloneMessageVT() protobuf_go_lite.CloneMessage
- func (m *StopResponse) CloneVT() *StopResponse
- func (this *StopResponse) EqualMessageVT(thatMsg any) bool
- func (this *StopResponse) EqualVT(that *StopResponse) bool
- func (x *StopResponse) MarshalJSON() ([]byte, error)
- func (x *StopResponse) MarshalProtoJSON(s *json.MarshalState)
- func (x *StopResponse) MarshalProtoText() string
- func (m *StopResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *StopResponse) MarshalToVT(dAtA []byte) (int, error)
- func (m *StopResponse) MarshalVT() (dAtA []byte, err error)
- func (*StopResponse) ProtoMessage()
- func (x *StopResponse) Reset()
- func (m *StopResponse) SizeVT() (n int)
- func (x *StopResponse) String() string
- func (x *StopResponse) UnmarshalJSON(b []byte) error
- func (x *StopResponse) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (m *StopResponse) UnmarshalVT(dAtA []byte) error
Constants ¶
const ( // SocketName is the daemon's socket within its state directory. SocketName = "modlock.sock" // StateEnv names the environment variable that overrides the state // directory. StateEnv = "MODLOCK_STATE" )
const SRPCDaemonServiceID = "modlock.daemon.Daemon"
Variables ¶
var ( // ErrRunning reports that another daemon already holds the state // directory. ErrRunning = errors.New("a modlock daemon already runs for this state directory") )
Functions ¶
func Dir ¶
Dir returns the state directory: $MODLOCK_STATE, or modlock/state in the user's configuration directory.
func NewSRPCDaemonHandler ¶
func NewSRPCDaemonHandler(impl SRPCDaemonServer, serviceID string) srpc.Handler
NewSRPCDaemonHandler constructs a new RPC handler. serviceID: if empty, uses default: modlock.daemon.Daemon
func Ready ¶
func Ready()
Ready tells the process that started this daemon that it listens, and stops writing to the standard output that process reads.
func SRPCRegisterDaemon ¶
func SRPCRegisterDaemon(mux srpc.Mux, impl SRPCDaemonServer) error
SRPCRegisterDaemon registers the implementation with the mux. Uses the default serviceID: modlock.daemon.Daemon
func Serve ¶
func Serve(ctx context.Context, dir, version string, idle time.Duration, mux srpc.Mux, ready func()) error
Serve runs the daemon of release version for dir. It takes the directory's lock, listens on its socket, calls ready, and serves the Daemon service and the rest of mux until ctx ends, a client stops it, or no client has stayed connected for idle. It returns ErrRunning when another daemon holds dir.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one modlock process's connection to its PC's daemon.
func Connect ¶
func Connect(ctx context.Context, dir, version string, start func(context.Context) error) (*Client, error)
Connect connects to the daemon for dir that belongs to release version. It starts one with start when none runs, and replaces one of another release. start must return once the new daemon listens, as Start does.
func (*Client) Status ¶
func (c *Client) Status() *GetStatusResponse
Status returns the daemon's status when the client connected.
type GetStatusRequest ¶
type GetStatusRequest struct {
// contains filtered or unexported fields
}
GetStatusRequest asks for the daemon's status.
func (*GetStatusRequest) CloneMessageVT ¶
func (m *GetStatusRequest) CloneMessageVT() protobuf_go_lite.CloneMessage
func (*GetStatusRequest) CloneVT ¶
func (m *GetStatusRequest) CloneVT() *GetStatusRequest
func (*GetStatusRequest) EqualMessageVT ¶
func (this *GetStatusRequest) EqualMessageVT(thatMsg any) bool
func (*GetStatusRequest) EqualVT ¶
func (this *GetStatusRequest) EqualVT(that *GetStatusRequest) bool
func (*GetStatusRequest) MarshalJSON ¶
func (x *GetStatusRequest) MarshalJSON() ([]byte, error)
MarshalJSON marshals the GetStatusRequest to JSON.
func (*GetStatusRequest) MarshalProtoJSON ¶
func (x *GetStatusRequest) MarshalProtoJSON(s *json.MarshalState)
MarshalProtoJSON marshals the GetStatusRequest message to JSON.
func (*GetStatusRequest) MarshalProtoText ¶
func (x *GetStatusRequest) MarshalProtoText() string
func (*GetStatusRequest) MarshalToSizedBufferVT ¶
func (m *GetStatusRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
func (*GetStatusRequest) MarshalToVT ¶
func (m *GetStatusRequest) MarshalToVT(dAtA []byte) (int, error)
func (*GetStatusRequest) MarshalVT ¶
func (m *GetStatusRequest) MarshalVT() (dAtA []byte, err error)
func (*GetStatusRequest) ProtoMessage ¶
func (*GetStatusRequest) ProtoMessage()
func (*GetStatusRequest) Reset ¶
func (x *GetStatusRequest) Reset()
func (*GetStatusRequest) SizeVT ¶
func (m *GetStatusRequest) SizeVT() (n int)
func (*GetStatusRequest) String ¶
func (x *GetStatusRequest) String() string
func (*GetStatusRequest) UnmarshalJSON ¶
func (x *GetStatusRequest) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the GetStatusRequest from JSON.
func (*GetStatusRequest) UnmarshalProtoJSON ¶
func (x *GetStatusRequest) UnmarshalProtoJSON(s *json.UnmarshalState)
UnmarshalProtoJSON unmarshals the GetStatusRequest message from JSON.
func (*GetStatusRequest) UnmarshalVT ¶
func (m *GetStatusRequest) UnmarshalVT(dAtA []byte) error
type GetStatusResponse ¶
type GetStatusResponse struct {
// pid is the daemon's process ID.
Pid uint32 `protobuf:"varint,1,opt,name=pid,proto3" json:"pid,omitempty"`
// version is the modlock release the daemon belongs to, such as v0.1.10.
Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`
// started_unix_ms is when the daemon started, in Unix milliseconds.
StartedUnixMs int64 `protobuf:"varint,3,opt,name=started_unix_ms,json=startedUnixMs,proto3" json:"startedUnixMs,omitempty"`
// clients counts the connected modlock processes, this one included.
Clients uint32 `protobuf:"varint,4,opt,name=clients,proto3" json:"clients,omitempty"`
// contains filtered or unexported fields
}
GetStatusResponse describes the running daemon.
func (*GetStatusResponse) CloneMessageVT ¶
func (m *GetStatusResponse) CloneMessageVT() protobuf_go_lite.CloneMessage
func (*GetStatusResponse) CloneVT ¶
func (m *GetStatusResponse) CloneVT() *GetStatusResponse
func (*GetStatusResponse) EqualMessageVT ¶
func (this *GetStatusResponse) EqualMessageVT(thatMsg any) bool
func (*GetStatusResponse) EqualVT ¶
func (this *GetStatusResponse) EqualVT(that *GetStatusResponse) bool
func (*GetStatusResponse) GetClients ¶
func (x *GetStatusResponse) GetClients() uint32
func (*GetStatusResponse) GetPid ¶
func (x *GetStatusResponse) GetPid() uint32
func (*GetStatusResponse) GetStartedUnixMs ¶
func (x *GetStatusResponse) GetStartedUnixMs() int64
func (*GetStatusResponse) GetVersion ¶
func (x *GetStatusResponse) GetVersion() string
func (*GetStatusResponse) MarshalJSON ¶
func (x *GetStatusResponse) MarshalJSON() ([]byte, error)
MarshalJSON marshals the GetStatusResponse to JSON.
func (*GetStatusResponse) MarshalProtoJSON ¶
func (x *GetStatusResponse) MarshalProtoJSON(s *json.MarshalState)
MarshalProtoJSON marshals the GetStatusResponse message to JSON.
func (*GetStatusResponse) MarshalProtoText ¶
func (x *GetStatusResponse) MarshalProtoText() string
func (*GetStatusResponse) MarshalToSizedBufferVT ¶
func (m *GetStatusResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error)
func (*GetStatusResponse) MarshalToVT ¶
func (m *GetStatusResponse) MarshalToVT(dAtA []byte) (int, error)
func (*GetStatusResponse) MarshalVT ¶
func (m *GetStatusResponse) MarshalVT() (dAtA []byte, err error)
func (*GetStatusResponse) ProtoMessage ¶
func (*GetStatusResponse) ProtoMessage()
func (*GetStatusResponse) Reset ¶
func (x *GetStatusResponse) Reset()
func (*GetStatusResponse) SizeVT ¶
func (m *GetStatusResponse) SizeVT() (n int)
func (*GetStatusResponse) String ¶
func (x *GetStatusResponse) String() string
func (*GetStatusResponse) UnmarshalJSON ¶
func (x *GetStatusResponse) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the GetStatusResponse from JSON.
func (*GetStatusResponse) UnmarshalProtoJSON ¶
func (x *GetStatusResponse) UnmarshalProtoJSON(s *json.UnmarshalState)
UnmarshalProtoJSON unmarshals the GetStatusResponse message from JSON.
func (*GetStatusResponse) UnmarshalVT ¶
func (m *GetStatusResponse) UnmarshalVT(dAtA []byte) error
type SRPCDaemonClient ¶
type SRPCDaemonClient interface {
// SRPCClient returns the underlying SRPC client.
SRPCClient() srpc.Client
// GetStatus returns which daemon is running.
GetStatus(ctx context.Context, in *GetStatusRequest) (*GetStatusResponse, error)
// Stop makes the daemon close its socket and exit, so a client of another
// release can start its own.
Stop(ctx context.Context, in *StopRequest) (*StopResponse, error)
}
func NewSRPCDaemonClient ¶
func NewSRPCDaemonClient(cc srpc.Client) SRPCDaemonClient
func NewSRPCDaemonClientWithServiceID ¶
func NewSRPCDaemonClientWithServiceID(cc srpc.Client, serviceID string) SRPCDaemonClient
type SRPCDaemonHandler ¶
type SRPCDaemonHandler struct {
// contains filtered or unexported fields
}
func (SRPCDaemonHandler) GetMethodIDs ¶
func (SRPCDaemonHandler) GetMethodIDs() []string
func (*SRPCDaemonHandler) GetServiceID ¶
func (d *SRPCDaemonHandler) GetServiceID() string
func (*SRPCDaemonHandler) InvokeMethod ¶
func (SRPCDaemonHandler) InvokeMethod_GetStatus ¶
func (SRPCDaemonHandler) InvokeMethod_GetStatus(impl SRPCDaemonServer, strm srpc.Stream) error
func (SRPCDaemonHandler) InvokeMethod_Stop ¶
func (SRPCDaemonHandler) InvokeMethod_Stop(impl SRPCDaemonServer, strm srpc.Stream) error
type SRPCDaemonServer ¶
type SRPCDaemonServer interface {
// GetStatus returns which daemon is running.
GetStatus(context.Context, *GetStatusRequest) (*GetStatusResponse, error)
// Stop makes the daemon close its socket and exit, so a client of another
// release can start its own.
Stop(context.Context, *StopRequest) (*StopResponse, error)
}
type SRPCDaemon_StopStream ¶
type StopRequest ¶
type StopRequest struct {
// contains filtered or unexported fields
}
StopRequest asks the daemon to exit.
func (*StopRequest) CloneMessageVT ¶
func (m *StopRequest) CloneMessageVT() protobuf_go_lite.CloneMessage
func (*StopRequest) CloneVT ¶
func (m *StopRequest) CloneVT() *StopRequest
func (*StopRequest) EqualMessageVT ¶
func (this *StopRequest) EqualMessageVT(thatMsg any) bool
func (*StopRequest) EqualVT ¶
func (this *StopRequest) EqualVT(that *StopRequest) bool
func (*StopRequest) MarshalJSON ¶
func (x *StopRequest) MarshalJSON() ([]byte, error)
MarshalJSON marshals the StopRequest to JSON.
func (*StopRequest) MarshalProtoJSON ¶
func (x *StopRequest) MarshalProtoJSON(s *json.MarshalState)
MarshalProtoJSON marshals the StopRequest message to JSON.
func (*StopRequest) MarshalProtoText ¶
func (x *StopRequest) MarshalProtoText() string
func (*StopRequest) MarshalToSizedBufferVT ¶
func (m *StopRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
func (*StopRequest) MarshalToVT ¶
func (m *StopRequest) MarshalToVT(dAtA []byte) (int, error)
func (*StopRequest) MarshalVT ¶
func (m *StopRequest) MarshalVT() (dAtA []byte, err error)
func (*StopRequest) ProtoMessage ¶
func (*StopRequest) ProtoMessage()
func (*StopRequest) Reset ¶
func (x *StopRequest) Reset()
func (*StopRequest) SizeVT ¶
func (m *StopRequest) SizeVT() (n int)
func (*StopRequest) String ¶
func (x *StopRequest) String() string
func (*StopRequest) UnmarshalJSON ¶
func (x *StopRequest) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the StopRequest from JSON.
func (*StopRequest) UnmarshalProtoJSON ¶
func (x *StopRequest) UnmarshalProtoJSON(s *json.UnmarshalState)
UnmarshalProtoJSON unmarshals the StopRequest message from JSON.
func (*StopRequest) UnmarshalVT ¶
func (m *StopRequest) UnmarshalVT(dAtA []byte) error
type StopResponse ¶
type StopResponse struct {
// contains filtered or unexported fields
}
StopResponse confirms that the daemon is stopping.
func (*StopResponse) CloneMessageVT ¶
func (m *StopResponse) CloneMessageVT() protobuf_go_lite.CloneMessage
func (*StopResponse) CloneVT ¶
func (m *StopResponse) CloneVT() *StopResponse
func (*StopResponse) EqualMessageVT ¶
func (this *StopResponse) EqualMessageVT(thatMsg any) bool
func (*StopResponse) EqualVT ¶
func (this *StopResponse) EqualVT(that *StopResponse) bool
func (*StopResponse) MarshalJSON ¶
func (x *StopResponse) MarshalJSON() ([]byte, error)
MarshalJSON marshals the StopResponse to JSON.
func (*StopResponse) MarshalProtoJSON ¶
func (x *StopResponse) MarshalProtoJSON(s *json.MarshalState)
MarshalProtoJSON marshals the StopResponse message to JSON.
func (*StopResponse) MarshalProtoText ¶
func (x *StopResponse) MarshalProtoText() string
func (*StopResponse) MarshalToSizedBufferVT ¶
func (m *StopResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error)
func (*StopResponse) MarshalToVT ¶
func (m *StopResponse) MarshalToVT(dAtA []byte) (int, error)
func (*StopResponse) MarshalVT ¶
func (m *StopResponse) MarshalVT() (dAtA []byte, err error)
func (*StopResponse) ProtoMessage ¶
func (*StopResponse) ProtoMessage()
func (*StopResponse) Reset ¶
func (x *StopResponse) Reset()
func (*StopResponse) SizeVT ¶
func (m *StopResponse) SizeVT() (n int)
func (*StopResponse) String ¶
func (x *StopResponse) String() string
func (*StopResponse) UnmarshalJSON ¶
func (x *StopResponse) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the StopResponse from JSON.
func (*StopResponse) UnmarshalProtoJSON ¶
func (x *StopResponse) UnmarshalProtoJSON(s *json.UnmarshalState)
UnmarshalProtoJSON unmarshals the StopResponse message from JSON.
func (*StopResponse) UnmarshalVT ¶
func (m *StopResponse) UnmarshalVT(dAtA []byte) error