juju: github.com/juju/juju/service Index | Files | Directories

package service

import "github.com/juju/juju/service"

Index

Package Files

agent.go agentconf.go agentinfo.go discovery.go service.go

Constants

const (
    InitSystemSystemd = "systemd"
    InitSystemUpstart = "upstart"
    InitSystemWindows = "windows"
    InitSystemSnap    = "snap"
)

These are the names of the init systems recognized by juju.

Variables

var ListServices = func() ([]string, error) {
    hostSeries, err := series.HostSeries()
    if err != nil {
        return nil, errors.Trace(err)
    }
    initName, err := VersionInitSystem(hostSeries)
    if err != nil {
        return nil, errors.Trace(err)
    }
    var services []string
    switch initName {
    case InitSystemWindows:
        services, err = windows.ListServices()
    case InitSystemSnap:
        services, err = snap.ListServices()
    case InitSystemUpstart:
        services, err = upstart.ListServices()
    case InitSystemSystemd:
        services, err = systemd.ListServices()
    default:
        return nil, errors.NotFoundf("init system %q", initName)
    }
    if err != nil {
        return nil, errors.Annotatef(err, "failed to list %s services", initName)
    }
    return services, nil
}

ListServices lists all installed services on the running system

var NewService = func(name string, conf common.Conf, series string) (Service, error) {
    if name == "" {
        return nil, errors.New("missing name")
    }

    initSystem, err := versionInitSystem(series)
    if err != nil {
        return nil, errors.Trace(err)
    }
    return newService(name, conf, initSystem, series)
}

NewService returns a new Service based on the provided info.

func AgentConf Uses

func AgentConf(info AgentInfo, renderer shell.Renderer) common.Conf

AgentConf returns the data that defines an init service config for the identified agent.

func ContainerAgentConf Uses

func ContainerAgentConf(info AgentInfo, renderer shell.Renderer, containerType string) common.Conf

ContainerAgentConf returns the data that defines an init service config for the identified agent running in a container.

func DiscoverInitSystemScript Uses

func DiscoverInitSystemScript() string

DiscoverInitSystemScript returns the shell script to use when discovering the local init system. The script is quite specific to bash, so it includes an explicit bash shbang.

func FindUnitServiceNames Uses

func FindUnitServiceNames(svcNames []string) map[string]string

FindUnitServiceNames accepts a collection of service names as managed by the local init system. Any that are identified as being for unit agents are returned, keyed on the unit name.

func InstallAndStart Uses

func InstallAndStart(svc ServiceActions) error

InstallAndStart installs the provided service and tries starting it. The first few Start failures are ignored.

func ListServicesScript Uses

func ListServicesScript() string

ListServicesScript returns the commands that should be run to get a list of service names on a host.

func ManuallyRestart Uses

func ManuallyRestart(svc ServiceActions) error

ManuallyRestart restarts the service by applying its Restart method or by falling back to calling Stop and Start

func Restart Uses

func Restart(name string) error

Restart restarts the named service.

func ShutdownAfterConf Uses

func ShutdownAfterConf(serviceName string) (common.Conf, error)

ShutdownAfterConf builds a service conf that will cause the host to shut down after the named service stops.

func VersionInitSystem Uses

func VersionInitSystem(series string) (string, error)

VersionInitSystem returns an init system name based on the provided series. If one cannot be identified a NotFound error is returned.

type AgentInfo Uses

type AgentInfo struct {

    // ID is the string that identifies the agent uniquely within
    // a juju environment.
    ID  string

    // Kind is the kind of agent.
    Kind AgentKind

    // DataDir is the path to the agent's data dir.
    DataDir string

    // LogDir is the path to the agent's log dir.
    LogDir string
    // contains filtered or unexported fields
}

AgentInfo holds commonly used information about a juju agent.

func NewAgentInfo Uses

func NewAgentInfo(kind AgentKind, id, dataDir, logDir string) AgentInfo

NewAgentInfo composes a new AgentInfo for the given essentials.

func NewMachineAgentInfo Uses

func NewMachineAgentInfo(id, dataDir, logDir string) AgentInfo

NewMachineAgentInfo returns a new AgentInfo for a machine agent.

func NewUnitAgentInfo Uses

func NewUnitAgentInfo(id, dataDir, logDir string) AgentInfo

NewUnitAgentInfo returns a new AgentInfo for a unit agent.

func (AgentInfo) ToolsDir Uses

func (ai AgentInfo) ToolsDir(renderer shell.Renderer) string

ToolsDir returns the path to the agent's tools dir.

type AgentKind Uses

type AgentKind string

AgentKind identifies the kind of agent.

const (
    AgentKindMachine AgentKind = "machine"
    AgentKindUnit    AgentKind = "unit"
)

These are the agent kinds in juju.

type ConfigureableService Uses

type ConfigureableService interface {
    // Configure performs any necessary configuration steps
    Configure() error

    // ReConfigureDuringRestart indicates whether Configure
    // should be called during a restart
    ReConfigureDuringRestart() bool
}

ConfigureableService performs tasks that need to occur between the software has been installed and when has started

type RestartableService Uses

type RestartableService interface {
    // Restart restarts the service.
    Restart() error
}

RestartableService is a service that directly supports restarting.

type Service Uses

type Service interface {
    ServiceActions

    // Name returns the service's name.
    Name() string

    // Conf returns the service's conf data.
    Conf() common.Conf

    // Running returns a boolean value that denotes
    // whether or not the service is running.
    Running() (bool, error)

    // Exists returns whether the service configuration exists in the
    // init directory with the same content that this Service would have
    // if installed.
    Exists() (bool, error)

    // Installed will return a boolean value that denotes
    // whether or not the service is installed.
    Installed() (bool, error)

    // InstallCommands returns the list of commands to run on a
    // (remote) host to install the service.
    InstallCommands() ([]string, error)

    // StartCommands returns the list of commands to run on a
    // (remote) host to start the service.
    StartCommands() ([]string, error)
}

Service represents a service in the init system running on a host.

func DiscoverService Uses

func DiscoverService(name string, conf common.Conf) (Service, error)

DiscoverService returns an interface to a service appropriate for the current system

type ServiceActions Uses

type ServiceActions interface {
    // Start will try to start the service.
    Start() error

    // Stop will try to stop the service.
    Stop() error

    // Install installs a service.
    Install() error

    // Remove will remove the service.
    Remove() error
}

ServiceActions represents the actions that may be requested for an init system service.

type SystemdServiceManager Uses

type SystemdServiceManager interface {
    // FindAgents finds all the agents available in the machine.
    FindAgents(dataDir string) (string, []string, []string, error)

    // WriteSystemdAgents creates systemd files and create symlinks for the
    // list of machine and units passed in the standard filepath.
    WriteSystemdAgents(
        machineAgent string, unitAgents []string, dataDir, symLinkSystemdDir, symLinkSystemdMultiUserDir string,
    ) ([]string, []string, []string, error)

    //CreateAgentConf creates the configfile for specified agent running on a
    // host with specified series.
    CreateAgentConf(agentName string, dataDir string) (common.Conf, error)

    // CopyAgentBinary copies all the tools into the path specified for each agent.
    CopyAgentBinary(
        machineAgent string, unitAgents []string, dataDir, toSeries, fromSeries string, jujuVersion version.Number) error

    // StartAllAgents starts all the agents in the machine with specified series.
    StartAllAgents(machineAgent string, unitAgents []string, dataDir string) (string, []string, error)

    // WriteServiceFiles writes the service files for machine and unit agents
    // in the '/lib/systemd/system' path.
    WriteServiceFiles() error
}

func NewServiceManager Uses

func NewServiceManager(
    isRunning func() bool,
    newService func(string, common.Conf) (Service, error),
) SystemdServiceManager

NewServiceManager allows creation of a new SystemdServiceManager from custom dependencies.

func NewServiceManagerWithDefaults Uses

func NewServiceManagerWithDefaults() SystemdServiceManager

NewServiceManagerWithDefaults returns a SystemdServiceManager created with sensible defaults.

type UpgradableService Uses

type UpgradableService interface {
    // WriteService writes the service conf data. If the service is
    // running, WriteService adds links to allow for manual and automatic
    // starting of the service.
    WriteService() error
}

Directories

PathSynopsis
common
common/testing
snapPackage snap is a minimal service.Service implementation, derived from the on service/upstart package.
systemd
systemd/testing
upstart
windows

Package service imports 28 packages (graph) and is imported by 359 packages. Updated 2019-10-17. Refresh now. Tools for package owners.