コード例 #1
0
ファイル: main.go プロジェクト: yacloud-io/cf-redis-broker
func redisPIDProvider(instancePath string) process.PIDProvider {
	return func() (int, error) {
		instanceConf, err := redisconf.Load(path.Join(instancePath, "redis.conf"))
		if err != nil {
			return 0, err
		}

		client, err := client.Connect(
			client.Host("localhost"),
			client.Port(instanceConf.Port()),
			client.Password(instanceConf.Password()),
			client.CmdAliases(instanceConf.CommandAliases()),
		)
		if err != nil {
			return 0, err
		}

		pidfile, err := client.GetConfig("pidfile")
		if err != nil {
			return 0, err
		}
		return process.ReadPID(pidfile)
	}
}
コード例 #2
0
			BeforeEach(func() {
				pidFile, err := ioutil.TempFile("", "pid")
				Expect(err).ToNot(HaveOccurred())

				pidFilePath = pidFile.Name()

				_, err = pidFile.WriteString("1234")
				Expect(err).ToNot(HaveOccurred())

				err = pidFile.Close()
				Expect(err).ToNot(HaveOccurred())
			})

			It("reads the pid from the pid file", func() {
				pid, err := process.ReadPID(pidFilePath)
				Expect(err).ToNot(HaveOccurred())
				Expect(pid).To(Equal(1234))
			})

			Context("when the pid file is invalid", func() {
				BeforeEach(func() {
					err := ioutil.WriteFile(pidFilePath, []byte("bs"), os.ModePerm)
					Expect(err).ToNot(HaveOccurred())
				})

				It("returns an error", func() {
					_, err := process.ReadPID(pidFilePath)
					Expect(err).To(HaveOccurred())
				})
			})