本文整理汇总了Golang中github.com/juju/juju/mongo.ServiceName函数的典型用法代码示例。如果您正苦于以下问题:Golang ServiceName函数的具体用法?Golang ServiceName怎么用?Golang ServiceName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: placeNewMongo
// placeNewMongo tries to use mongorestore to replace an existing
// mongo with the dump in newMongoDumpPath returns an error if its not possible.
func placeNewMongo(newMongoDumpPath string, ver version.Number) error {
mongoRestore, err := restorePath()
if err != nil {
return errors.Annotate(err, "mongorestore not available")
}
mgoRestoreArgs, err := restoreArgsForVersion(ver, newMongoDumpPath)
if err != nil {
return errors.Errorf("cannot restore this backup version")
}
err = runCommand("initctl", "stop", mongo.ServiceName(""))
if err != nil {
return errors.Annotate(err, "failed to stop mongo")
}
err = runCommand(mongoRestore, mgoRestoreArgs...)
if err != nil {
return errors.Annotate(err, "failed to restore database dump")
}
err = runCommand("initctl", "start", mongo.ServiceName(""))
if err != nil {
return errors.Annotate(err, "failed to start mongo")
}
return nil
}
示例2: makeFakeInitScripts
func (s *localJujuTestSuite) makeFakeInitScripts(c *gc.C, env environs.Environ) (installable, installable) {
s.MakeTool(c, "start", `echo "some-service start/running, process 123"`)
namespace := env.Config().AllAttrs()["namespace"].(string)
// Mongo first...
mongoName := mongo.ServiceName(namespace)
mongoConf := common.Conf{
Desc: "fake mongo",
ExecStart: "echo FAKE",
}
mongoService := local.NewService(mongoName, mongoConf, s.svcData)
s.svcData.SetStatus(mongoName, "installed")
installed, err := mongoService.Installed()
c.Assert(err, jc.ErrorIsNil)
c.Check(installed, jc.IsTrue)
// ...then the machine agent
agentName := fmt.Sprintf("juju-agent-%s", namespace)
agentConf := common.Conf{
Desc: "fake agent",
ExecStart: "echo FAKE",
}
agentService := local.NewService(agentName, agentConf, s.svcData)
s.svcData.SetStatus(agentName, "installed")
installed, err = agentService.Installed()
c.Assert(err, jc.ErrorIsNil)
c.Check(installed, jc.IsTrue)
return mongoService, agentService
}
示例3: makeFakeUpstartScripts
func (s *localJujuTestSuite) makeFakeUpstartScripts(c *gc.C, env environs.Environ,
) (mongoService *upstart.Service, machineAgent *upstart.Service) {
upstartDir := c.MkDir()
s.PatchValue(&upstart.InitDir, upstartDir)
s.MakeTool(c, "start", `echo "some-service start/running, process 123"`)
namespace := env.Config().AllAttrs()["namespace"].(string)
mongoConf := common.Conf{
Desc: "fake mongo",
Cmd: "echo FAKE",
}
mongoService = upstart.NewService(mongo.ServiceName(namespace), mongoConf)
err := mongoService.Install()
c.Assert(err, gc.IsNil)
c.Assert(mongoService.Installed(), jc.IsTrue)
agentConf := common.Conf{
Desc: "fake agent",
Cmd: "echo FAKE",
}
machineAgent = upstart.NewService(fmt.Sprintf("juju-agent-%s", namespace), agentConf)
err = machineAgent.Install()
c.Assert(err, gc.IsNil)
c.Assert(machineAgent.Installed(), jc.IsTrue)
return mongoService, machineAgent
}
示例4: Destroy
func (e *manualEnviron) Destroy() error {
script := `
set -x
touch %s
pkill -%d jujud && exit
stop %s
rm -f /etc/init/juju*
rm -f /etc/rsyslog.d/*juju*
rm -fr %s %s
exit 0
`
script = fmt.Sprintf(
script,
utils.ShQuote(path.Join(
agent.DefaultPaths.DataDir,
agent.UninstallAgentFile,
)),
terminationworker.TerminationSignal,
mongo.ServiceName(""),
utils.ShQuote(agent.DefaultPaths.DataDir),
utils.ShQuote(agent.DefaultPaths.LogDir),
)
_, err := runSSHCommand(
"[email protected]"+e.envConfig().bootstrapHost(),
[]string{"sudo", "/bin/bash"}, script,
)
return err
}
示例5: PatchServices
func PatchServices(patchValue func(interface{}, interface{}), data *svctesting.FakeServiceData) {
patchValue(&mongoRemoveService, func(namespace string) error {
data.AddCall("RemoveService", namespace)
data.SetStatus(mongo.ServiceName(namespace), "")
return data.NextErr()
})
patchValue(&discoverService, func(name string) (agentService, error) {
return NewService(name, common.Conf{}, data), nil
})
}
示例6: TestIsServiceInstalledWhenInstalled
func (s *serviceSuite) TestIsServiceInstalledWhenInstalled(c *gc.C) {
namespace := "some-namespace"
svcName := mongo.ServiceName(namespace)
svcData := svctesting.NewFakeServiceData(svcName)
mongo.PatchService(s.PatchValue, svcData)
isInstalled, err := mongo.IsServiceInstalled(namespace)
c.Assert(err, jc.ErrorIsNil)
c.Assert(isInstalled, jc.IsTrue)
}
示例7: TestRemoveService
func (s *MongoSuite) TestRemoveService(c *gc.C) {
namespace := "namespace"
s.data.SetStatus(mongo.ServiceName(namespace), "running")
err := mongo.RemoveService(namespace)
c.Assert(err, jc.ErrorIsNil)
removed := s.data.Removed()
if !c.Check(removed, gc.HasLen, 1) {
c.Check(removed[0].Name(), gc.Equals, "juju-db-namespace")
c.Check(removed[0].Conf(), jc.DeepEquals, common.Conf{})
}
s.data.CheckCallNames(c, "Stop", "Remove")
}
示例8: TestEnsureServerServerExistsNotRunningIsStarted
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningIsStarted(c *gc.C) {
dataDir := c.MkDir()
namespace := "namespace"
mockShellCommand(c, &s.CleanupSuite, "apt-get")
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例9: TestEnsureServerServerExistsNotRunningStartError
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningStartError(c *gc.C) {
dataDir := c.MkDir()
namespace := "namespace"
mockShellCommand(c, &s.CleanupSuite, "apt-get")
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
failure := errors.New("won't start")
s.data.SetErrors(nil, nil, nil, failure) // Installed, Exists, Running, Running, Start
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Check(errors.Cause(err), gc.Equals, failure)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例10: TestInstallMongodServiceExists
func (s *MongoSuite) TestInstallMongodServiceExists(c *gc.C) {
output := mockShellCommand(c, &s.CleanupSuite, "apt-get")
dataDir := c.MkDir()
namespace := "namespace"
s.data.SetStatus(mongo.ServiceName(namespace), "running")
s.data.SetErrors(nil, nil, nil, errors.New("shouldn't be called"))
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running")
// We still attempt to install mongodb, despite the service existing.
cmds := getMockShellCalls(c, output)
c.Check(cmds, gc.HasLen, 1)
}
示例11: TestEnsureServerServerExistsNotRunningStartError
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningStartError(c *gc.C) {
dataDir := c.MkDir()
namespace := "namespace"
pm, err := coretesting.GetPackageManager()
c.Assert(err, jc.ErrorIsNil)
testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
failure := errors.New("won't start")
s.data.SetErrors(nil, nil, nil, failure) // Installed, Exists, Running, Running, Start
err = mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Check(errors.Cause(err), gc.Equals, failure)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例12: TestEnsureServerServerExistsNotRunningIsStarted
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningIsStarted(c *gc.C) {
dataDir := c.MkDir()
namespace := "namespace"
mockShellCommand(c, &s.CleanupSuite, "apt-get")
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
// These should still be written out even if the service was installed.
s.assertSSLKeyFile(c, dataDir)
s.assertSharedSecretFile(c, dataDir)
s.assertMongoConfigFile(c)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例13: TestInstallMongodServiceExists
func (s *MongoSuite) TestInstallMongodServiceExists(c *gc.C) {
pm, err := coretesting.GetPackageManager()
c.Assert(err, jc.ErrorIsNil)
testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)
if pm.PackageManager == "yum" {
testing.PatchExecutableAsEchoArgs(c, s, "chcon")
testing.PatchExecutableAsEchoArgs(c, s, "semanage")
}
dataDir := c.MkDir()
namespace := "namespace"
s.data.SetStatus(mongo.ServiceName(namespace), "running")
s.data.SetErrors(nil, nil, nil, errors.New("shouldn't be called"))
err = mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running")
}
示例14: TestEnsureServerServerExistsNotRunningIsStarted
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningIsStarted(c *gc.C) {
dataDir := c.MkDir()
namespace := "namespace"
pm, err := coretesting.GetPackageManager()
c.Assert(err, jc.ErrorIsNil)
testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
err = mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
// These should still be written out even if the service was installed.
s.assertSSLKeyFile(c, dataDir)
s.assertSharedSecretFile(c, dataDir)
s.assertMongoConfigFile(c)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例15: TestMongoAptGetFails
func (s *MongoSuite) TestMongoAptGetFails(c *gc.C) {
s.PatchValue(&version.Current.Series, "trusty")
// Any exit code from apt-get that isn't 0 or 100 will be treated
// as unexpected, skipping the normal retry loop. failCmd causes
// the command to exit with 1.
binDir := c.MkDir()
s.PatchEnvPathPrepend(binDir)
failCmd(filepath.Join(binDir, "apt-get"))
// Set the mongodb service as installed but not running.
namespace := "namespace"
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("test-writer", &tw, loggo.ERROR), jc.ErrorIsNil)
defer loggo.RemoveWriter("test-writer")
dataDir := c.MkDir()
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
// Even though apt-get failed, EnsureServer should continue and
// not return the error - even though apt-get failed, the Juju
// mongodb package is most likely already installed.
// The error should be logged however.
c.Assert(err, jc.ErrorIsNil)
c.Check(tw.Log(), jc.LogMatches, []jc.SimpleMessage{
{loggo.ERROR, `packaging command failed: .+`},
{loggo.ERROR, `cannot install/upgrade mongod \(will proceed anyway\): packaging command failed`},
})
// Verify that EnsureServer continued and started the mongodb service.
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}