Example #1
0
func main() {
	configPath := flag.String("agentConfig", "", "Agent config yaml")
	flag.Parse()

	logger := lager.NewLogger("redis-agent")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	config, err := agentconfig.Load(*configPath)
	if err != nil {
		logger.Fatal("Error loading config file", err, lager.Data{
			"path": *configPath,
		})
	}

	templateRedisConf(config, logger)

	redisResetter := resetter.New(
		config.DefaultConfPath,
		config.ConfPath,
		portChecker{},
		commandRunner{},
		config.MonitExecutablePath,
	)

	handler := auth.NewWrapper(
		config.AuthConfiguration.Username,
		config.AuthConfiguration.Password,
	).Wrap(
		agentapi.New(redisResetter, config.ConfPath),
	)

	http.Handle("/", handler)
	logger.Fatal("http-listen", http.ListenAndServe("localhost:"+config.Port, nil))
}
Example #2
0
func main() {
	brokerConfigPath := configPath()

	log := lager.NewLogger("redis-configmigrator")
	log.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	log.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	log.Info("Config File: " + brokerConfigPath)

	config, err := brokerconfig.ParseConfig(brokerConfigPath)
	if err != nil {
		log.Fatal("Loading config file", err, lager.Data{
			"broker-config-path": brokerConfigPath,
		})
	}

	migrator := &configmigrator.ConfigMigrator{
		RedisDataDir: config.RedisConfiguration.InstanceDataDirectory,
	}

	err = migrator.Migrate()
	if err != nil {
		log.Fatal("Could not migrate data", err)
	}
}
Example #3
0
func setupLogger(debug bool) {
	if debug {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	}
}
Example #4
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("cf-rabbitmq-broker")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	rand.Seed(time.Now().UTC().UnixNano())

	config, err := rabbitbroker.ReadConfig(configPath)
	if err != nil {
		logger.Fatal("read-config", err)
	}

	client, _ := rabbithole.NewClient(
		fmt.Sprintf("http://%s:15672", config.Rabbitmq.Hosts[0]),
		config.Rabbitmq.Administrator.Username,
		config.Rabbitmq.Administrator.Password)

	serviceBroker := rabbitbroker.New(config, client, rabbitbroker.RandomCredentialsGenerator{}, logger, rabbitbroker.BindingInfoResource{ProtocolInfo: rabbitbroker.ProtocolInfoResource{}})

	credentials := brokerapi.BrokerCredentials{
		Username: config.Service.Username,
		Password: config.Service.Password,
	}

	http.Handle("/", brokerapi.New(serviceBroker, logger, credentials))

	logger.Info("starting-server")
	if err := http.ListenAndServe(":4567", nil); err != nil {
		logger.Fatal("starting-server-failed", err)
	}
}
Example #5
0
// NewBroker is a constructor for a Broker webapp struct
func NewBroker() (subway *Broker) {
	subway = &Broker{}
	subway.Logger = lager.NewLogger("cf-subway")
	subway.Logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	subway.Logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))
	return subway
}
Example #6
0
func main() {
	logger := lager.NewLogger("backup")
	logger.RegisterSink(log.NewCliSink(lager.INFO))
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	var configPath string
	flag.StringVar(&configPath, "config", "", "Path to YML config file")

	flag.Parse()

	if _, err := os.Stat(configPath); os.IsNotExist(err) {
		logger.Error("snapshot-main", err, lager.Data{"event": "failed", "config_file": configPath})
		os.Exit(2)
	}

	backupConfig, err := backup.LoadBackupConfig(configPath)
	exitOnError(err, 78, logger, configPath)

	logFile, err := os.OpenFile(backupConfig.LogFilepath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660)
	if err != nil {
		logger.Error("snapshot-main", err, lager.Data{"event": "failed", "LogFilepath": backupConfig.LogFilepath})
	}
	logger.RegisterSink(lager.NewWriterSink(logFile, lager.INFO))

	// TODO: Should this really be a pointer not a struct?
	if (backupConfig.S3Config == backup.S3Configuration{}) {
		logger.Info("snapshot-main", lager.Data{"event": "cancelled", "message": "S3 configuration not found - skipping backup"})
		os.Exit(0)
	}

	backuper, err := backup.NewInstanceBackuper(*backupConfig, logger)
	exitOnError(err, 70, logger, configPath)

	backupResults := backuper.Backup()
	hasError := false
	for _, result := range backupResults {
		if result.Err != nil {
			hasError = true
			logger.Error(
				"snapshot-main",
				result.Err,
				lager.Data{
					"event":           "failed",
					"InstanceID":      result.InstanceID,
					"RedisConfigPath": result.RedisConfigPath,
					"NodeIP":          result.NodeIP,
				},
			)
		}
	}

	if hasError {
		os.Exit(70)
	}
}
Example #7
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("lattice-app")
	if quiet {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	}

	ports := getServerPorts()

	logger.Info("lattice-app.starting", lager.Data{"ports": ports})
	handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
	if err != nil {
		logger.Fatal("router.creation.failed", err)
	}

	index, err := helpers.FetchIndex()
	appName := fetchAppName()
	go func() {
		t := time.NewTicker(time.Second)
		for {
			<-t.C
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
			} else {
				fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
			}
		}
	}()

	wg := sync.WaitGroup{}
	for _, port := range ports {
		wg.Add(1)
		go func(wg *sync.WaitGroup, port string) {
			defer wg.Done()
			server := ifrit.Envoke(http_server.New(":"+port, handler))
			logger.Info("lattice-app.up", lager.Data{"port": port})
			err = <-server.Wait()
			if err != nil {
				logger.Error("shutting down server", err, lager.Data{"server port": port})
			}
			logger.Info("shutting down server", lager.Data{"server port": port})
		}(&wg, port)
	}
	wg.Wait()
	logger.Info("shutting latice app")
}
func (f *FakeCell) SpinUp(serviceClient bbs.ServiceClient) {
	//make a test-friendly AuctionRepDelegate using the auction package's SimulationRepDelegate
	f.SimulationRep = simulationrep.New(f.stack, "Z0", rep.Resources{
		DiskMB:     100,
		MemoryMB:   100,
		Containers: 100,
	})

	//spin up an http auction server
	logger := lager.NewLogger(f.cellID)
	logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))

	fakeLRPStopper := new(fake_lrp_stopper.FakeLRPStopper)
	fakeExecutorClient := new(executorfakes.FakeClient)
	fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)

	handlers := rephandlers.New(f.SimulationRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger)
	router, err := rata.NewRouter(rep.Routes, handlers)
	Expect(err).NotTo(HaveOccurred())
	f.server = httptest.NewServer(router)

	presence := models.NewCellPresence(
		f.cellID,
		f.server.URL,
		"az1",
		models.NewCellCapacity(512, 1024, 124),
		[]string{},
		[]string{})

	f.heartbeater = ifrit.Invoke(serviceClient.NewCellPresenceRunner(logger, &presence, time.Second))
}
Example #9
0
func main() {

	var err error

	brokerConfig, err = config.LoadFromFile(*configFile)
	if err != nil {
		panic(fmt.Errorf("configuration load error from file %s. Err: %s", *configFile, err))
	}

	serviceBroker := &myServiceBroker{}

	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	logger.Debug("config-load-success", lager.Data{"file-source": *configFile, "config": brokerConfig})

	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	addr := getListeningAddr(brokerConfig)

	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)

	http.Handle("/", brokerAPI)

	http.ListenAndServe(addr, nil)
	if err != nil {
		logger.Error("error-listenting", err)
	}
}
Example #10
0
func New(writer io.Writer) *GinkgoReporter {
	logger := lager.NewLogger("ginkgo")
	logger.RegisterSink(lager.NewWriterSink(writer, lager.DEBUG))
	return &GinkgoReporter{
		writer: writer,
		logger: logger,
	}
}
Example #11
0
func NewTestSink() *TestSink {
	buffer := gbytes.NewBuffer()

	return &TestSink{
		Sink:   lager.NewWriterSink(buffer, lager.DEBUG),
		buffer: buffer,
	}
}
Example #12
0
func NewTestLogger(component string) *TestLogger {
	logger := lager.NewLogger(component)

	testSink := NewTestSink()
	logger.RegisterSink(testSink)
	logger.RegisterSink(lager.NewWriterSink(ginkgo.GinkgoWriter, lager.DEBUG))

	return &TestLogger{logger, testSink}
}
Example #13
0
func main() {
	logger := lager.NewLogger("lattice-app")
	if quiet {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	}

	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}

	logger.Info("lattice-app.starting", lager.Data{"port": port})
	handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
	if err != nil {
		logger.Fatal("router.creation.failed", err)
	}

	index, err := helpers.FetchIndex()
	appName := helpers.FetchAppName()

	go func() {
		t := time.NewTicker(time.Second)
		for {
			<-t.C
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
			} else {
				fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
			}
		}
	}()

	server := ifrit.Envoke(http_server.New(":"+port, handler))
	logger.Info("lattice-app.up", lager.Data{"port": port})
	err = <-server.Wait()
	if err != nil {
		logger.Error("farewell", err)
	}
	logger.Info("farewell")
}
Example #14
0
func buildLogger(logLevel string) lager.Logger {
	laggerLogLevel, ok := logLevels[strings.ToUpper(logLevel)]
	if !ok {
		log.Fatal("Invalid log level: ", logLevel)
	}

	logger := lager.NewLogger("rds-broker")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, laggerLogLevel))

	return logger
}
Example #15
0
func main() {
	logger := lager.NewLogger("checkin")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	var opts Opts

	_, err := flags.Parse(&opts)
	if err != nil {
		logger.Error("parsing-flags", err)
		os.Exit(1)
	}

	// ts := oauth2.StaticTokenSource(
	// 	&oauth2.Token{AccessToken: opts.GitHubAccessToken},
	// )
	// tc := oauth2.NewClient(oauth2.NoContext, ts)
	// githubClient := github.NewClient(tc)

	// checker := build.NewConcourseChecker()
	// checker = build.NewStatusReporter(checker, githubClient.Repositories)

	dbConn, err := migration.Open(opts.DBDriver, opts.DBURL, migrations.Migrations)
	if err != nil {
		logger.Error("failed-to-run-migrations", err)
		os.Exit(1)
	}
	sqlDB := db.NewSQL(logger.Session("db"), dbConn)

	enqueuer := build.NewEnqueuer(sqlDB)
	apiServer := api.NewServer(opts.GitHubSecret, enqueuer)

	members := []grouper.Member{
		{
			"api",
			http_server.New(
				opts.Addr,
				apiServer,
			),
		},
	}

	group := grouper.NewParallel(os.Interrupt, members)
	running := ifrit.Invoke(sigmon.New(group))

	logger.Info("listening", lager.Data{
		"api": opts.Addr,
	})

	err = <-running.Wait()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Example #16
0
func logger() lager.Logger {
	logger := lager.NewLogger("ltc")
	var logLevel lager.LogLevel

	if os.Getenv("LTC_LOG_LEVEL") == "DEBUG" {
		logLevel = lager.DEBUG
	} else {
		logLevel = lager.INFO
	}

	logger.RegisterSink(lager.NewWriterSink(os.Stderr, logLevel))
	return logger
}
Example #17
0
func main() {
	logger := lager.NewLogger("garden-lame")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	client := NewLameClient(logger)
	backend := lameBackend{logger: logger, Client: client}
	srv := server.New("tcp", ":3000", 5*time.Minute, &backend, logger)
	srv.Start()

	exit := make(chan os.Signal)
	signal.Notify(exit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

	<-exit

	srv.Stop()
}
Example #18
0
func runMain(writer io.Writer) {

	if !flag.Parsed() {
		flag.Parse()
	}
	var err error
	brokerConfig, err = config.LoadFromFile(*configFile)

	if err != nil {
		panic(fmt.Errorf("configuration load error from file %s. Err: %s", *configFile, err))
	}

	logger.RegisterSink(lager.NewWriterSink(writer, getLogLevel(brokerConfig)))

	logger.Debug("config-load-success", lager.Data{"file-source": *configFile, "config": brokerConfig})

	mssqlPars := brokerConfig.BrokerMssqlConnection

	// set default sql driver if it is not set based on the OS
	if _, ok := mssqlPars["driver"]; !ok && brokerConfig.BrokerGoSqlDriver == "odbc" {
		if runtime.GOOS != "windows" {
			mssqlPars["driver"] = "freetds"
		} else {
			mssqlPars["driver"] = "sql server"
		}
	}

	mssqlProv = provisioner.NewMssqlProvisioner(logger, brokerConfig.BrokerGoSqlDriver, mssqlPars)
	err = mssqlProv.Init()
	if err != nil {
		logger.Fatal("error-initializing-provisioner", err)
	}

	serviceBroker := &mssqlServiceBroker{}

	brokerAPI := brokerapi.New(serviceBroker, logger, brokerConfig.Crednetials)
	http.Handle("/", brokerAPI)

	addr := getListeningAddr(brokerConfig)
	logger.Info("start-listening", lager.Data{"addr": addr})

	err = http.ListenAndServe(addr, exitOnPanicWrapper{http.DefaultServeMux})
	if err != nil {
		logger.Fatal("error-listening", err)
	}
}
Example #19
0
func (cmd *ATCCommand) constructLogger() (lager.Logger, *lager.ReconfigurableSink) {
	logger := lager.NewLogger("atc")

	logLevel := lager.INFO
	if cmd.Developer.DevelopmentMode {
		logLevel = lager.DEBUG
	}

	reconfigurableSink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), logLevel)
	logger.RegisterSink(reconfigurableSink)

	if cmd.Metrics.YellerAPIKey != "" {
		yellerSink := zest.NewYellerSink(cmd.Metrics.YellerAPIKey, cmd.Metrics.YellerEnvironment)
		logger.RegisterSink(yellerSink)
	}

	return logger, reconfigurableSink
}
Example #20
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("houdini")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	depot, err := filepath.Abs(*containersDir)
	if err != nil {
		logger.Fatal("failed-to-determine-depot-dir", err)
	}

	backend := houdini.NewBackend(depot)

	gardenServer := server.New(*listenNetwork, *listenAddr, *containerGraceTime, backend, logger)

	err = gardenServer.Start()
	if err != nil {
		logger.Fatal("failed-to-start-server", err)
	}

	logger.Info("started", lager.Data{
		"network": *listenNetwork,
		"addr":    *listenAddr,
	})

	signals := make(chan os.Signal, 1)

	go func() {
		<-signals
		gardenServer.Stop()
		os.Exit(0)
	}()

	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

	debugListenAddr := fmt.Sprintf("%s:%d", *debugListenAddress, *debugListenPort)

	err = http.ListenAndServe(debugListenAddr, nil)
	if err != nil {
		logger.Fatal("failed-to-start-debug-server", err)
	}

	select {}
}
Example #21
0
func configureLogger() lager.Logger {
	var lagerLogLevel lager.LogLevel
	switch *logLevel {
	case "debug":
		lagerLogLevel = lager.DEBUG
	case "info":
		lagerLogLevel = lager.INFO
	case "error":
		lagerLogLevel = lager.ERROR
	case "fatal":
		lagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unknown log level: %s", logLevel))
	}

	logger := lager.NewLogger("delphos")
	sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), lagerLogLevel)
	logger.RegisterSink(sink)

	return logger
}
Example #22
0
func NewLager(log *logger) Logger {
	var minLagerLogLevel lager.LogLevel
	switch log.LogLevel {
	case DEBUG:
		minLagerLogLevel = lager.DEBUG
	case INFO:
		minLagerLogLevel = lager.INFO
	case ERROR:
		minLagerLogLevel = lager.ERROR
	case FATAL:
		minLagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unknown log level: %s", log.LogLevel))
	}

	logger := lager.NewLogger(log.Name)
	logger.RegisterSink(lager.NewWriterSink(log.Writer, minLagerLogLevel))
	log.Logger = logger

	return log
}
func main() {
	isProducer := flag.Bool("producer", false, "Is this process a producer?")
	flag.Parse()

	logger := lager.NewLogger(fmt.Sprintf("Process-%d", os.Getpid()))
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	creds := rabbitmq.AMQPCredentials{
		Host:     "localhost",
		Port:     5672,
		Username: "******",
		Password: "******",
	}
	queue := "producers-consumers"

	if *isProducer {
		sender, err := rabbitmq.NewSender(creds, queue)
		mustNot(err)
		ch, err := gofigure.OutboundChannel(sender)
		mustNot(err)
		logger.Info("got-write-channel")

		ch <- "Hello consumers"
		logger.Info("sent-message")
	} else {
		receiver, err := rabbitmq.NewReceiver(creds, queue)
		mustNot(err)
		ch, err := gofigure.InboundChannel(receiver)
		mustNot(err)
		logger.Info("got-read-channel")

		data := <-ch
		logger.Info(data.(string))
		logger.Info("received-message")
	}

	logger.Info("done")

	select {}
}
Example #24
0
File: main.go Project: savaki/tsa
func main() {
	flag.Parse()

	logger := lager.NewLogger("tsa")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	if len(*forwardHost) == 0 {
		logger.Fatal("missing-flag", nil, lager.Data{"flag": "-forwardHost"})
	}

	atcEndpoint := rata.NewRequestGenerator(*atcAPIURL, atc.Routes)

	authorizedKeys, err := loadAuthorizedKeys(*authorizedKeysPath)
	if err != nil {
		logger.Fatal("failed-to-load-authorized-keys", err)
	}

	config, err := configureSSHServer(*hostKeyPath, authorizedKeys)
	if err != nil {
		logger.Fatal("failed-to-configure-ssh-server", err)
	}

	listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", *listenPort))
	if err != nil {
		logger.Fatal("failed-to-listen-for-connection", err)
	}

	logger.Info("listening")

	server := &registrarSSHServer{
		logger:            logger,
		heartbeatInterval: *heartbeatInterval,
		atcEndpoint:       atcEndpoint,
		forwardHost:       *forwardHost,
		config:            config,
		httpClient:        http.DefaultClient,
	}

	server.Serve(listener)
}
Example #25
0
func InitializeLogger(minLogLevel LogLevel) (lager.Logger, *lager.ReconfigurableSink, error) {
	var minLagerLogLevel lager.LogLevel
	switch minLogLevel {
	case LogLevelDebug:
		minLagerLogLevel = lager.DEBUG
	case LogLevelInfo:
		minLagerLogLevel = lager.INFO
	case LogLevelError:
		minLagerLogLevel = lager.ERROR
	case LogLevelFatal:
		minLagerLogLevel = lager.FATAL
	default:
		return nil, nil, fmt.Errorf("unknown log level: %s", minLogLevel)
	}

	logger := lager.NewLogger("garagepi")

	sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), minLagerLogLevel)
	logger.RegisterSink(sink)

	return logger, sink, nil
}
Example #26
0
func New(component string) (lager.Logger, *lager.ReconfigurableSink) {
	var minLagerLogLevel lager.LogLevel
	switch minLogLevel {
	case DEBUG:
		minLagerLogLevel = lager.DEBUG
	case INFO:
		minLagerLogLevel = lager.INFO
	case ERROR:
		minLagerLogLevel = lager.ERROR
	case FATAL:
		minLagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unknown log level: %s", minLogLevel))
	}

	logger := lager.NewLogger(component)

	sink := lager.NewReconfigurableSink(lager.NewWriterSink(os.Stdout, lager.DEBUG), minLagerLogLevel)
	logger.RegisterSink(sink)

	return logger, sink
}
Example #27
0
func New(component string) lager.Logger {
	if !flag.Parsed() {
		flag.Parse()
	}
	var minLagerLogLevel lager.LogLevel
	switch minLogLevel {
	case DEBUG:
		minLagerLogLevel = lager.DEBUG
	case INFO:
		minLagerLogLevel = lager.INFO
	case ERROR:
		minLagerLogLevel = lager.ERROR
	case FATAL:
		minLagerLogLevel = lager.FATAL
	default:
		panic(fmt.Errorf("unkown log level: %s", minLogLevel))
	}

	logger := lager.NewLogger(component)
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, minLagerLogLevel))

	return logger
}
Example #28
0
func (cmd *WorkerCommand) Execute(args []string) error {
	logger := lager.NewLogger("worker")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	worker, gardenRunner, err := cmd.gardenRunner(logger.Session("garden"), args)
	if err != nil {
		return err
	}

	baggageclaimRunner, err := cmd.baggageclaimRunner(logger.Session("baggageclaim"))
	if err != nil {
		return err
	}

	members := grouper.Members{
		{
			Name:   "garden",
			Runner: gardenRunner,
		},
		{
			Name:   "baggageclaim",
			Runner: baggageclaimRunner,
		},
	}

	if cmd.TSA.WorkerPrivateKey != "" {
		members = append(members, grouper.Member{
			Name:   "beacon",
			Runner: cmd.beaconRunner(logger.Session("beacon"), worker),
		})
	}

	runner := sigmon.New(grouper.NewParallel(os.Interrupt, members))

	return <-ifrit.Invoke(runner).Wait()
}
Example #29
0
func InitLoggerFromConfig(logger lager.Logger, c *config.Config, logCounter *schema.LogCounter) {
	if c.Logging.File != "" {
		file, err := os.OpenFile(c.Logging.File, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
		if err != nil {
			logger.Fatal("error-opening-log-file", err, lager.Data{"file": c.Logging.File})
		}
		var logLevel lager.LogLevel
		switch c.Logging.Level {
		case DEBUG:
			logLevel = lager.DEBUG
		case INFO:
			logLevel = lager.INFO
		case ERROR:
			logLevel = lager.ERROR
		case FATAL:
			logLevel = lager.FATAL
		default:
			panic(fmt.Errorf("unknown log level: %s", c.Logging.Level))
		}
		logger.RegisterSink(lager.NewWriterSink(file, logLevel))
	}

	logger.RegisterSink(logCounter)
}
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("ProcessReaper", func() {
	var reaper *system.ProcessReaper
	var waitFunc system.Wait4Func

	BeforeEach(func() {
		waitFunc = syscall.Wait4
	})

	JustBeforeEach(func() {
		logger := lager.NewLogger("process_reaper_test_logger")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.ERROR))
		reaper = system.StartReaper(logger, waitFunc)
	})

	AfterEach(func() {
		reaper.Stop()
	})

	It("waits for a process to return and returns its exit status", func() {
		cmd := exec.Command("sh", "-c", "exit 3")
		Expect(reaper.Start(cmd)).To(Succeed())

		Expect(reaper.Wait(cmd)).To(Equal(byte(3)))
	})

	It("waits for multiple processes", func() {