github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/upgradeseries/service.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package upgradeseries 5 6 import ( 7 "github.com/juju/juju/service" 8 "github.com/juju/juju/service/common" 9 ) 10 11 // AgentService is a service managed by the local init system, for running a 12 // unit agent. 13 type AgentService interface { 14 Running() (bool, error) 15 Start() error 16 Stop() error 17 } 18 19 // ServiceAccess describes methods for interacting with the local init system. 20 type ServiceAccess interface { 21 // ListServices returns a slice of service 22 // names known by the local init system. 23 ListServices() ([]string, error) 24 25 // DiscoverService returns a service implementation 26 // based on the input service name and config. 27 DiscoverService(string) (AgentService, error) 28 } 29 30 // serviceAccess is the default implementation of ServiceAccess. 31 // It wraps methods from the service package. 32 type serviceAccess struct{} 33 34 var _ ServiceAccess = &serviceAccess{} 35 36 // ListServices lists all the running services on a machine. 37 func (s *serviceAccess) ListServices() ([]string, error) { 38 return service.ListServices() 39 } 40 41 // DiscoverService returns the interface for a service running on a the machine. 42 func (s *serviceAccess) DiscoverService(name string) (AgentService, error) { 43 return service.DiscoverService(name, common.Conf{}) 44 }