1package main 2 3import ( 4 "flag" 5 "fmt" 6 "net/http" 7 _ "net/http/pprof" 8 "os" 9 "os/signal" 10 "path/filepath" 11 "syscall" 12 "time" 13 14 "code.cloudfoundry.org/garden/server" 15 "code.cloudfoundry.org/lager" 16 "github.com/vito/houdini" 17) 18 19var listenNetwork = flag.String( 20 "listenNetwork", 21 "tcp", 22 "how to listen on the address (unix, tcp, etc.)", 23) 24 25var listenAddr = flag.String( 26 "listenAddr", 27 "0.0.0.0:7777", 28 "address to listen on", 29) 30 31var debugListenAddress = flag.String( 32 "debugListenAddress", 33 "127.0.0.1", 34 "address for the pprof debugger listen on", 35) 36 37var debugListenPort = flag.Int( 38 "debugListenPort", 39 7776, 40 "port for the pprof debugger to listen on", 41) 42 43var containerGraceTime = flag.Duration( 44 "containerGraceTime", 45 5*time.Minute, 46 "time after which to destroy idle containers", 47) 48 49var containersDir = flag.String( 50 "depot", 51 "./containers", 52 "directory in which to store containers", 53) 54 55func main() { 56 flag.Parse() 57 58 logger := lager.NewLogger("houdini") 59 logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG)) 60 61 depot, err := filepath.Abs(*containersDir) 62 if err != nil { 63 logger.Fatal("failed-to-determine-depot-dir", err) 64 } 65 66 backend := houdini.NewBackend(depot) 67 68 gardenServer := server.New(*listenNetwork, *listenAddr, *containerGraceTime, backend, logger) 69 70 err = gardenServer.Start() 71 if err != nil { 72 logger.Fatal("failed-to-start-server", err) 73 } 74 75 logger.Info("started", lager.Data{ 76 "network": *listenNetwork, 77 "addr": *listenAddr, 78 }) 79 80 signals := make(chan os.Signal, 1) 81 82 go func() { 83 <-signals 84 gardenServer.Stop() 85 os.Exit(0) 86 }() 87 88 signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) 89 90 debugListenAddr := fmt.Sprintf("%s:%d", *debugListenAddress, *debugListenPort) 91 92 err = http.ListenAndServe(debugListenAddr, nil) 93 if err != nil { 94 logger.Fatal("failed-to-start-debug-server", err) 95 } 96 97 select {} 98} 99