Exemple #1
0
func addMongoToBoot(c *cloudinit.Config, cfg *MachineConfig) error {
	addScripts(c,
		"mkdir -p /var/lib/juju/db/journal",
		// Otherwise we get three files with 100M+ each, which takes time.
		"dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc.0",
		"dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc.1",
		"dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc.2",
	)
	svc := upstart.NewService("juju-db")
	conf := &upstart.Conf{
		Service: *svc,
		Desc:    "juju state database",
		Cmd: "/opt/mongo/bin/mongod" +
			" --auth" +
			" --dbpath=/var/lib/juju/db" +
			" --sslOnNormalPorts" +
			" --sslPEMKeyFile " + shquote(cfg.dataFile("server.pem")) +
			" --sslPEMKeyPassword ignored" +
			" --bind_ip 0.0.0.0" +
			" --port " + fmt.Sprint(mgoPort) +
			" --noprealloc" +
			" --smallfiles",
	}
	cmds, err := conf.InstallCommands()
	if err != nil {
		return fmt.Errorf("cannot make cloud-init upstart script for the state database: %v", err)
	}
	addScripts(c, cmds...)
	return nil
}
Exemple #2
0
// upstartService returns an upstart.Service corresponding to the specified
// unit.
func (ctx *SimpleContext) upstartService(unitName string) *upstart.Service {
	tag := state.UnitTag(unitName)
	svcName := "jujud-" + tag
	svc := upstart.NewService(svcName)
	svc.InitDir = ctx.initDir
	return svc
}
Exemple #3
0
// upstartService returns an upstart.Service corresponding to the specified
// unit. Its name is badged according to the entity responsible for the
// context, so as to distinguish its own jobs from those installed by other
// means.
func (mgr *SimpleManager) upstartService(unitName string) *upstart.Service {
	entityName := state.UnitEntityName(unitName)
	svcName := "jujud-" + mgr.StateInfo.EntityName + ":" + entityName
	svc := upstart.NewService(svcName)
	svc.InitDir = mgr.InitDir
	return svc
}
Exemple #4
0
// 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) *upstart.Service {
	unitsAndJobs, err := ctx.deployedUnitsUpstartJobs()
	if err != nil {
		return nil
	}
	if job, ok := unitsAndJobs[unitName]; ok {
		svc := upstart.NewService(job)
		svc.InitDir = ctx.initDir
		return svc
	}
	return nil
}
Exemple #5
0
// Destroy is specified in the Environ interface.
func (env *localEnviron) Destroy(insts []instance.Instance) error {
	if !env.config.runningAsRoot {
		return fmt.Errorf("destroying a local environment must be done as root")
	}
	// Kill all running instances.
	containers, err := env.containerManager.ListContainers()
	if err != nil {
		return err
	}
	for _, inst := range containers {
		if err := env.containerManager.StopContainer(inst); err != nil {
			return err
		}
	}

	logger.Infof("removing service %s", env.machineAgentServiceName())
	machineAgent := upstart.NewService(env.machineAgentServiceName())
	machineAgent.InitDir = upstartScriptLocation
	if err := machineAgent.Remove(); err != nil {
		logger.Errorf("could not remove machine agent service: %v", err)
		return err
	}

	logger.Infof("removing service %s", env.mongoServiceName())
	mongo := upstart.NewService(env.mongoServiceName())
	mongo.InitDir = upstartScriptLocation
	if err := mongo.Remove(); err != nil {
		logger.Errorf("could not remove mongo service: %v", err)
		return err
	}

	// Remove the rootdir.
	logger.Infof("removing state dir %s", env.config.rootDir())
	if err := os.RemoveAll(env.config.rootDir()); err != nil {
		logger.Errorf("could not remove local state dir: %v", err)
		return err
	}

	return nil
}
Exemple #6
0
func addAgentToBoot(c *cloudinit.Config, cfg *MachineConfig, kind, entityName, args string) (*agent.Conf, error) {
	acfg, err := addAgentInfo(c, cfg, entityName)
	if err != nil {
		return nil, err
	}

	// Make the agent run via a symbolic link to the actual tools
	// directory, so it can upgrade itself without needing to change
	// the upstart script.
	toolsDir := environs.AgentToolsDir(cfg.DataDir, entityName)
	// TODO(dfc) ln -nfs, so it doesn't fail if for some reason that the target already exists
	addScripts(c, fmt.Sprintf("ln -s %v %s", cfg.Tools.Binary, shquote(toolsDir)))

	svc := upstart.NewService("jujud-" + entityName)
	logPath := fmt.Sprintf("/var/log/juju/%s.log", entityName)
	cmd := fmt.Sprintf(
		"%s/jujud %s"+
			" --log-file %s"+
			" --data-dir '%s'"+
			" %s",
		toolsDir, kind,
		logPath,
		cfg.DataDir,
		args,
	)
	conf := &upstart.Conf{
		Service: *svc,
		Desc:    fmt.Sprintf("juju %s agent", entityName),
		Cmd:     cmd,
		Out:     logPath,
	}
	cmds, err := conf.InstallCommands()
	if err != nil {
		return nil, fmt.Errorf("cannot make cloud-init upstart script for the %s agent: %v", entityName, err)
	}
	addScripts(c, cmds...)
	return acfg, nil
}
func (s *UpstartSuite) TestInitDir(c *C) {
	svc := upstart.NewService("blah")
	c.Assert(svc.InitDir, Equals, "/etc/init")
}