本文整理汇总了Golang中github.com/juju/juju/service.NewService函数的典型用法代码示例。如果您正苦于以下问题:Golang NewService函数的具体用法?Golang NewService怎么用?Golang NewService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewService函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNewServiceKnown
func (s *serviceSuite) TestNewServiceKnown(c *gc.C) {
for _, test := range []struct {
series string
initSystem string
}{
{
series: "vivid",
initSystem: service.InitSystemSystemd,
}, {
series: "trusty",
initSystem: service.InitSystemUpstart,
}, {
series: "win2012",
initSystem: service.InitSystemWindows,
},
} {
svc, err := service.NewService(s.Name, s.Conf, test.series)
if !c.Check(err, jc.ErrorIsNil) {
continue
}
switch test.initSystem {
case service.InitSystemSystemd:
c.Check(svc, gc.FitsTypeOf, &systemd.Service{})
case service.InitSystemUpstart:
c.Check(svc, gc.FitsTypeOf, &upstart.Service{})
case service.InitSystemWindows:
c.Check(svc, gc.FitsTypeOf, &windows.Service{})
}
c.Check(svc.Name(), gc.Equals, s.Name)
c.Check(svc.Conf(), jc.DeepEquals, s.Conf)
}
}
开发者ID:howbazaar,项目名称:juju,代码行数:33,代码来源:service_test.go
示例2: uninstallAgent
func (a *MachineAgent) uninstallAgent(agentConfig agent.Config) error {
var errors []error
agentServiceName := agentConfig.Value(agent.AgentServiceName)
if agentServiceName == "" {
// For backwards compatibility, handle lack of AgentServiceName.
agentServiceName = os.Getenv("UPSTART_JOB")
}
if agentServiceName != "" {
if err := service.NewService(agentServiceName, common.Conf{}).Remove(); err != nil {
errors = append(errors, fmt.Errorf("cannot remove service %q: %v", agentServiceName, err))
}
}
// Remove the juju-run symlink.
if err := os.Remove(jujuRun); err != nil && !os.IsNotExist(err) {
errors = append(errors, err)
}
namespace := agentConfig.Value(agent.Namespace)
if err := mongo.RemoveService(namespace); err != nil {
errors = append(errors, fmt.Errorf("cannot stop/remove mongo service with namespace %q: %v", namespace, err))
}
if err := os.RemoveAll(agentConfig.DataDir()); err != nil {
errors = append(errors, err)
}
if len(errors) == 0 {
return nil
}
return fmt.Errorf("uninstall failed: %v", errors)
}
开发者ID:zhouqt,项目名称:juju,代码行数:29,代码来源:machine.go
示例3: findUpstartJob
// findUpstartJob tries to find an upstart job matching the
// given unit name in one of these formats:
// jujud-<deployer-tag>:<unit-tag>.conf (for compatibility)
// jujud-<unit-tag>.conf (default)
func (ctx *SimpleContext) findUpstartJob(unitName string) service.Service {
unitsAndJobs, err := ctx.deployedUnitsUpstartJobs()
if err != nil {
return nil
}
if job, ok := unitsAndJobs[unitName]; ok {
svc := service.NewService(job, common.Conf{InitDir: ctx.initDir})
return svc
}
return nil
}
开发者ID:kapilt,项目名称:juju,代码行数:15,代码来源:simple.go
示例4: IsRunningLocally
// IsRunningLocally returns true if LXD is running locally.
func IsRunningLocally() (bool, error) {
installed, err := IsInstalledLocally()
if err != nil {
return installed, errors.Trace(err)
}
if !installed {
return false, nil
}
svc, err := service.NewService("lxd", common.Conf{}, series.HostSeries())
if err != nil {
return false, errors.Trace(err)
}
running, err := svc.Running()
if err != nil {
return running, errors.Trace(err)
}
return running, nil
}
开发者ID:bac,项目名称:juju,代码行数:22,代码来源:utils.go
示例5: shutdownInitCommands
func shutdownInitCommands(initSystem, series string) ([]string, error) {
shutdownCmd := "/sbin/shutdown -h now"
name := "juju-template-restart"
desc := "juju shutdown job"
execStart := shutdownCmd
conf := common.Conf{
Desc: desc,
Transient: true,
AfterStopped: "cloud-final",
ExecStart: execStart,
}
// systemd uses targets for synchronization of services
if initSystem == service.InitSystemSystemd {
conf.AfterStopped = "cloud-config.target"
}
svc, err := service.NewService(name, conf, series)
if err != nil {
return nil, errors.Trace(err)
}
cmds, err := svc.InstallCommands()
if err != nil {
return nil, errors.Trace(err)
}
startCommands, err := svc.StartCommands()
if err != nil {
return nil, errors.Trace(err)
}
cmds = append(cmds, startCommands...)
return cmds, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:36,代码来源:container_userdata.go
示例6: ToolsDir
}
func (cfg *InstanceConfig) ToolsDir(renderer shell.Renderer) string {
return cfg.agentInfo().ToolsDir(renderer)
}
func (cfg *InstanceConfig) InitService(renderer shell.Renderer) (service.Service, error) {
conf := service.AgentConf(cfg.agentInfo(), renderer)
name := cfg.MachineAgentServiceName
svc, err := newService(name, conf, cfg.Series)
return svc, errors.Trace(err)
}
var newService = func(name string, conf common.Conf, series string) (service.Service, error) {
return service.NewService(name, conf, series)
}
func (cfg *InstanceConfig) AgentConfig(
tag names.Tag,
toolsVersion version.Number,
) (agent.ConfigSetter, error) {
// TODO for HAState: the stateHostAddrs and apiHostAddrs here assume that
// if the instance is a controller then to use localhost. This may be
// sufficient, but needs thought in the new world order.
var password string
if cfg.MongoInfo == nil {
password = cfg.APIInfo.Password
} else {
password = cfg.MongoInfo.Password
}
开发者ID:makyo,项目名称:juju,代码行数:31,代码来源:instancecfg.go
示例7: shutdownInitCommands
func shutdownInitCommands(initSystem, series string) ([]string, error) {
// These files are removed just before the template shuts down.
cleanupOnShutdown := []string{
// We remove any dhclient lease files so there's no chance a
// clone to reuse a lease from the template it was cloned
// from.
"/var/lib/dhcp/dhclient*",
// Both of these sets of files below are recreated on boot and
// if we leave them in the template's rootfs boot logs coming
// from cloned containers will be appended. It's better to
// keep clean logs for diagnosing issues / debugging.
"/var/log/cloud-init*.log",
}
// Using EOC below as the template shutdown script is itself
// passed through cat > ... < EOF.
replaceNetConfCmd := fmt.Sprintf(
"/bin/cat > /etc/network/interfaces << EOC%sEOC\n ",
defaultEtcNetworkInterfaces,
)
paths := strings.Join(cleanupOnShutdown, " ")
removeCmd := fmt.Sprintf("/bin/rm -fr %s\n ", paths)
shutdownCmd := "/sbin/shutdown -h now"
name := "juju-template-restart"
desc := "juju shutdown job"
execStart := shutdownCmd
if environs.AddressAllocationEnabled() {
// Only do the cleanup and replacement of /e/n/i when address
// allocation feature flag is enabled.
execStart = replaceNetConfCmd + removeCmd + shutdownCmd
}
conf := common.Conf{
Desc: desc,
Transient: true,
AfterStopped: "cloud-final",
ExecStart: execStart,
}
// systemd uses targets for synchronization of services
if initSystem == service.InitSystemSystemd {
conf.AfterStopped = "cloud-config.target"
}
svc, err := service.NewService(name, conf, series)
if err != nil {
return nil, errors.Trace(err)
}
cmds, err := svc.InstallCommands()
if err != nil {
return nil, errors.Trace(err)
}
startCommands, err := svc.StartCommands()
if err != nil {
return nil, errors.Trace(err)
}
cmds = append(cmds, startCommands...)
return cmds, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:62,代码来源:container_userdata.go
示例8: Restore
// Restore handles either returning or creating a controller to a backed up status:
// * extracts the content of the given backup file and:
// * runs mongorestore with the backed up mongo dump
// * updates and writes configuration files
// * updates existing db entries to make sure they hold no references to
// old instances
// * updates config in all agents.
func (b *backups) Restore(backupId string, dbInfo *DBInfo, args RestoreArgs) (names.Tag, error) {
meta, backupReader, err := b.Get(backupId)
if err != nil {
return nil, errors.Annotatef(err, "could not fetch backup %q", backupId)
}
defer backupReader.Close()
workspace, err := NewArchiveWorkspaceReader(backupReader)
if err != nil {
return nil, errors.Annotate(err, "cannot unpack backup file")
}
defer workspace.Close()
// This might actually work, but we don't have a guarantee so we don't allow it.
if meta.Origin.Series != args.NewInstSeries {
return nil, errors.Errorf("cannot restore a backup made in a machine with series %q into a machine with series %q, %#v", meta.Origin.Series, args.NewInstSeries, meta)
}
// TODO(perrito666) Create a compatibility table of sorts.
vers := meta.Origin.Version
if vers.Major != 2 {
return nil, errors.Errorf("Juju version %v cannot restore backups made using Juju version %v", version.Current.Minor, vers)
}
backupMachine := names.NewMachineTag(meta.Origin.Machine)
// The path for the config file might change if the tag changed
// and also the rest of the path, so we assume as little as possible.
oldDatadir, err := paths.DataDir(args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot determine DataDir for the restored machine")
}
var oldAgentConfig agent.ConfigSetterWriter
oldAgentConfigFile := agent.ConfigPath(oldDatadir, args.NewInstTag)
if oldAgentConfig, err = agent.ReadConfig(oldAgentConfigFile); err != nil {
return nil, errors.Annotate(err, "cannot load old agent config from disk")
}
logger.Infof("stopping juju-db")
if err = mongo.StopService(); err != nil {
return nil, errors.Annotate(err, "failed to stop mongo")
}
// delete all the files to be replaced
if err := PrepareMachineForRestore(oldAgentConfig.MongoVersion()); err != nil {
return nil, errors.Annotate(err, "cannot delete existing files")
}
logger.Infof("deleted old files to place new")
if err := workspace.UnpackFilesBundle(filesystemRoot()); err != nil {
return nil, errors.Annotate(err, "cannot obtain system files from backup")
}
logger.Infof("placed new restore files")
var agentConfig agent.ConfigSetterWriter
// The path for the config file might change if the tag changed
// and also the rest of the path, so we assume as little as possible.
datadir, err := paths.DataDir(args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot determine DataDir for the restored machine")
}
agentConfigFile := agent.ConfigPath(datadir, backupMachine)
if agentConfig, err = agent.ReadConfig(agentConfigFile); err != nil {
return nil, errors.Annotate(err, "cannot load agent config from disk")
}
ssi, ok := agentConfig.StateServingInfo()
if !ok {
return nil, errors.Errorf("cannot determine state serving info")
}
APIHostPorts := network.NewHostPorts(ssi.APIPort, args.PrivateAddress, args.PublicAddress)
agentConfig.SetAPIHostPorts([][]network.HostPort{APIHostPorts})
if err := agentConfig.Write(); err != nil {
return nil, errors.Annotate(err, "cannot write new agent configuration")
}
logger.Infof("wrote new agent config for restore")
if backupMachine.Id() != "0" {
logger.Infof("extra work needed backup belongs to %q machine", backupMachine.String())
serviceName := "jujud-" + agentConfig.Tag().String()
aInfo := service.NewMachineAgentInfo(
agentConfig.Tag().Id(),
dataDir,
paths.MustSucceed(paths.LogDir(args.NewInstSeries)),
)
// TODO(perrito666) renderer should have a RendererForSeries, for the moment
// restore only works on linuxes.
renderer, _ := shell.NewRenderer("bash")
serviceAgentConf := service.AgentConf(aInfo, renderer)
svc, err := service.NewService(serviceName, serviceAgentConf, args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot generate service for the restored agent.")
//.........这里部分代码省略.........
开发者ID:kat-co,项目名称:juju,代码行数:101,代码来源:backups_linux.go
示例9: Restore
// Restore handles either returning or creating a controller to a backed up status:
// * extracts the content of the given backup file and:
// * runs mongorestore with the backed up mongo dump
// * updates and writes configuration files
// * updates existing db entries to make sure they hold no references to
// old instances
// * updates config in all agents.
func (b *backups) Restore(backupId string, args RestoreArgs) (names.Tag, error) {
meta, backupReader, err := b.Get(backupId)
if err != nil {
return nil, errors.Annotatef(err, "could not fetch backup %q", backupId)
}
defer backupReader.Close()
workspace, err := NewArchiveWorkspaceReader(backupReader)
if err != nil {
return nil, errors.Annotate(err, "cannot unpack backup file")
}
defer workspace.Close()
// TODO(perrito666) Create a compatibility table of sorts.
version := meta.Origin.Version
backupMachine := names.NewMachineTag(meta.Origin.Machine)
if err := mongo.StopService(); err != nil {
return nil, errors.Annotate(err, "cannot stop mongo to replace files")
}
// delete all the files to be replaced
if err := PrepareMachineForRestore(); err != nil {
return nil, errors.Annotate(err, "cannot delete existing files")
}
logger.Infof("deleted old files to place new")
if err := workspace.UnpackFilesBundle(filesystemRoot()); err != nil {
return nil, errors.Annotate(err, "cannot obtain system files from backup")
}
logger.Infof("placed new files")
var agentConfig agent.ConfigSetterWriter
// The path for the config file might change if the tag changed
// and also the rest of the path, so we assume as little as possible.
datadir, err := paths.DataDir(args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot determine DataDir for the restored machine")
}
agentConfigFile := agent.ConfigPath(datadir, backupMachine)
if agentConfig, err = agent.ReadConfig(agentConfigFile); err != nil {
return nil, errors.Annotate(err, "cannot load agent config from disk")
}
ssi, ok := agentConfig.StateServingInfo()
if !ok {
return nil, errors.Errorf("cannot determine state serving info")
}
APIHostPorts := network.NewHostPorts(ssi.APIPort, args.PrivateAddress)
agentConfig.SetAPIHostPorts([][]network.HostPort{APIHostPorts})
if err := agentConfig.Write(); err != nil {
return nil, errors.Annotate(err, "cannot write new agent configuration")
}
logger.Infof("wrote new agent config")
if backupMachine.Id() != "0" {
logger.Infof("extra work needed backup belongs to %q machine", backupMachine.String())
serviceName := "jujud-" + agentConfig.Tag().String()
aInfo := service.NewMachineAgentInfo(
agentConfig.Tag().Id(),
dataDir,
paths.MustSucceed(paths.LogDir(args.NewInstSeries)),
)
// TODO(perrito666) renderer should have a RendererForSeries, for the moment
// restore only works on linuxes.
renderer, _ := shell.NewRenderer("bash")
serviceAgentConf := service.AgentConf(aInfo, renderer)
svc, err := service.NewService(serviceName, serviceAgentConf, args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot generate service for the restored agent.")
}
if err := svc.Install(); err != nil {
return nil, errors.Annotate(err, "cannot install service for the restored agent.")
}
logger.Infof("new machine service")
}
logger.Infof("mongo service will be reinstalled to ensure its presence")
if err := ensureMongoService(agentConfig); err != nil {
return nil, errors.Annotate(err, "failed to reinstall service for juju-db")
}
logger.Infof("new mongo will be restored")
// Restore mongodb from backup
if err := placeNewMongoService(workspace.DBDumpDir, version); err != nil {
return nil, errors.Annotate(err, "error restoring state from backup")
}
// Re-start replicaset with the new value for server address
dialInfo, err := newDialInfo(args.PrivateAddress, agentConfig)
if err != nil {
return nil, errors.Annotate(err, "cannot produce dial information")
//.........这里部分代码省略.........
开发者ID:exekias,项目名称:juju,代码行数:101,代码来源:backups_linux.go
示例10: TestNewServiceUnknown
func (s *serviceSuite) TestNewServiceUnknown(c *gc.C) {
_, err := service.NewService(s.Name, s.Conf, "<unknown>")
c.Check(err, jc.Satisfies, errors.IsNotFound)
}
开发者ID:howbazaar,项目名称:juju,代码行数:5,代码来源:service_test.go
示例11: TestNewServiceMissingName
func (s *serviceSuite) TestNewServiceMissingName(c *gc.C) {
_, err := service.NewService("", s.Conf, service.InitSystemUpstart)
c.Check(err, gc.ErrorMatches, `.*missing name.*`)
}
开发者ID:howbazaar,项目名称:juju,代码行数:5,代码来源:service_test.go
示例12: service
// service returns a service.Service corresponding to the specified
// unit.
func (ctx *SimpleContext) service(unitName string) service.Service {
tag := names.NewUnitTag(unitName).String()
svcName := "jujud-" + tag
svc := service.NewService(svcName, common.Conf{InitDir: ctx.initDir})
return svc
}
开发者ID:kapilt,项目名称:juju,代码行数:8,代码来源:simple.go
注:本文中的github.com/juju/juju/service.NewService函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论