service

package
v0.0.0-...-c60bc85 Latest Latest
Warning

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

Go to latest
Published: May 19, 2017 License: LGPL-3.0 Imports: 18 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
var NewService = func(p OSServiceParams) OSService {
	cmd := p.Exe + " " + strings.Join(p.Args, " ")
	return &upstart.Service{
		Name: p.Name,
		Conf: common.Conf{
			InitDir: "/etc/init",
			Desc:    p.Description,
			Cmd:     cmd,
			Out:     p.Output,
		},
	}
}

NewService is used to create a new service. It is defined as a variable so that it can be replaced for testing purposes.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context holds the context provided to a running service.

func (*Context) ServeLocalRPC

func (ctxt *Context) ServeLocalRPC(rcvr interface{}) (hook.Command, error)

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

	// Output holds the file where output will be put.
	Output 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

func (svc *Service) Call(method string, args interface{}, reply interface{}) error

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) Restart

func (svc *Service) Restart() error

func (*Service) Start

func (svc *Service) Start(args ...string) error

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) Started

func (svc *Service) Started() bool

Started reports whether the service has been started.

func (*Service) Stop

func (svc *Service) Stop() error

Stop stops the service running.

func (*Service) StopAndRemove

func (svc *Service) StopAndRemove() error

StopAndRemove stops and removes the service completely.

Jump to

Keyboard shortcuts

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