Example #1
0
func (s *initSystemSuite) TestInstallCommandsLogfile(c *gc.C) {
	name := "jujud-machine-0"
	s.conf.Logfile = "/var/log/juju/machine-0.log"
	service := s.newService(c)
	commands, err := service.InstallCommands()
	c.Assert(err, jc.ErrorIsNil)

	user, group := systemd.SyslogUserGroup()
	test := systemdtesting.WriteConfTest{
		Service: name,
		DataDir: s.dataDir,
		Expected: strings.Replace(
			s.newConfStr(name),
			"ExecStart=/var/lib/juju/bin/jujud machine-0",
			"ExecStart=/var/lib/juju/init/jujud-machine-0/exec-start.sh",
			-1),
		Script: `
# Set up logging.
touch '/var/log/juju/machine-0.log'
chown `[1:] + user + `:` + group + ` '/var/log/juju/machine-0.log'
chmod 0600 '/var/log/juju/machine-0.log'
exec >> '/var/log/juju/machine-0.log'
exec 2>&1

# Run the script.
` + jujud + " machine-0",
	}
	test.CheckCommands(c, commands)
}
Example #2
0
func (s *initSystemSuite) TestNewServiceLogfile(c *gc.C) {
	s.conf.Logfile = "/var/log/juju/machine-0.log"
	service := s.newService(c)

	user, group := systemd.SyslogUserGroup()
	dirname := fmt.Sprintf("%s/init/%s", s.dataDir, s.name)
	script := `
#!/usr/bin/env bash

# Set up logging.
touch '/var/log/juju/machine-0.log'
chown `[1:] + user + `:` + group + ` '/var/log/juju/machine-0.log'
chmod 0600 '/var/log/juju/machine-0.log'
exec >> '/var/log/juju/machine-0.log'
exec 2>&1

# Run the script.
` + jujud + " machine-0"
	c.Check(service, jc.DeepEquals, &systemd.Service{
		Service: common.Service{
			Name: s.name,
			Conf: common.Conf{
				Desc:      s.conf.Desc,
				ExecStart: dirname + "/exec-start.sh",
				Logfile:   "/var/log/juju/machine-0.log",
			},
		},
		UnitName: s.name + ".service",
		ConfName: s.name + ".service",
		Dirname:  dirname,
		Script:   []byte(script),
	})
	// This gives us a more readable output if they aren't equal.
	c.Check(string(service.Script), gc.Equals, script)
	c.Check(strings.Split(string(service.Script), "\n"), jc.DeepEquals, strings.Split(script, "\n"))
}