Documentation ¶
Overview ¶
The service packge provides a way for a charm to start and stop a service that runs independently of the charm hooks.
Index ¶
- Variables
- func SystemLogger(osServiceName string)
- type Context
- type OSService
- type OSServiceParams
- type Service
- func (svc *Service) Call(method string, args interface{}, reply interface{}) error
- func (svc *Service) Register(r *hook.Registry, serviceName string, ...)
- func (svc *Service) Restart() error
- func (svc *Service) Start(args ...string) error
- func (svc *Service) Started() bool
- func (svc *Service) Stop() error
- func (svc *Service) StopAndRemove() error
Constants ¶
This section is empty.
Variables ¶
var NewService = func(p OSServiceParams) OSService { cfg := &service.Config{ Name: p.Name, DisplayName: p.Description, Executable: p.Exe, Arguments: p.Args, } var er error s := &srv{p: &program{name: p.Name}} s.p.Service, er = service.New(s.p, cfg) if er != nil { panic(er) } return s }
NewService is used to create a new service. It is defined as a variable so that it can be replaced for testing purposes.
Functions ¶
func SystemLogger ¶
func SystemLogger(osServiceName string)
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds the context provided to a running service.
func (*Context) ServeLocalRPC ¶
ServeLocalRPC starts a local RPC server serving methods on the given receiver value, using the net/rpc package (see rpc.Server.Register).
The methods may be invoked using the Service.Call method. Parameters and return values will be marshaled as JSON.
ServeLocalRPC returns the Command representing the running service.
type OSService ¶
type OSService interface { Install() error StopAndRemove() error Running() bool Stop() error Start() error }
OSService defines the interface provided by an operating system service. It is implemented by *upstart.Service (from github.com/juju/juju/service/upstart).
type OSServiceParams ¶
type OSServiceParams struct { // Name holds the name of the service. Name string // Description holds the description of the service. Description string // Exe holds the name of the executable to run. Exe string // Args holds any arguments to the executable, // which should be OK to to pass to the shell // without quoting. Args []string }
OSServiceParams holds the parameters for creating a new service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a long running service that runs outside of the usual charm hook context.
func (*Service) Call ¶
Call invokes a method on the service. See rpc.Client.Call for the full semantics.
func (*Service) Register ¶
func (svc *Service) Register(r *hook.Registry, serviceName string, start func(ctxt *Context, args []string) (hook.Command, error))
Register registers the service with the given registry. If serviceName is non-empty, it specifies the name of the service, otherwise the service will be named after the charm's unit.
When the service is started, the start function will be called with the context for the running service and any arguments that were passed to the Service.Start method. The start function should return a hook.Command representing the running service. When its Wait method returns, the service will exit.
Note that when the start function is called, the hook context will not be available, as at that point the hook will be running in the context of the OS-provided service runner (e.g. upstart).
func (*Service) Start ¶
Start starts the service if it is not already started, passing it the given arguments. If the arguments are different from the last time it was started, it will be stopped and then started again with the new arguments.
func (*Service) StopAndRemove ¶
StopAndRemove stops and removes the service completely.