// NewProcess creates a new Process on a random port. func NewProcess() *Process { // Create temporary directory for data. path, err := ioutil.TempDir("", "flynn-redis-") if err != nil { panic(err) } // Create random port. ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { panic(err) } port := ln.Addr().(*net.TCPAddr).Port ln.Close() // Find parent directory for redis. binPath, err := exec.LookPath("redis-server") if err != nil { panic("redis-server not found in path: " + err.Error()) } // Create process p := &Process{Process: redis.NewProcess()} p.ID = fmt.Sprintf("P%d", atomic.AddUint64(&nextProcessID, 1)) p.BinDir = filepath.Dir(binPath) p.DataDir = path p.Port = strconv.Itoa(port) p.Password = "******" return p }
// NewMain returns a new instance of Main. func NewMain() *Main { return &Main{ ServiceName: DefaultServiceName, Addr: DefaultAddr, DataDir: DefaultDataDir, Process: redis.NewProcess(), Logger: log15.New("app", DefaultServiceName), DiscoverdClient: discoverd.DefaultClient, Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, } }