Example #1
0
func main() {

	if _, err := NewDriver(); err != nil {
		log.Errorf("Failed to create driver: %s", err)
		return
	}

	support.WaitUntilSignal()
}
func main() {
	app := &App{}
	err := app.Init(info)
	if err != nil {
		app.Log.Fatalf("failed to initialize app: %v", err)
	}

	err = app.Export(app)
	if err != nil {
		app.Log.Fatalf("failed to export app: %v", err)
	}

	support.WaitUntilSignal()
}
Example #3
0
func main() {
	config.StableFlagFile = nconfig.String("/var/run/zigbee.stable", "zigbee", "stable-file")
	config.Hostname = nconfig.String("localhost", "zigbee", "host")

	_, err := NewDriver(config)
	if log.IsDebugEnabled() {
		log.Debugf("version - %s - running with configuration %+v", Version, config)
	}

	if err != nil {
		log.Fatalf("Failed to start ZigBee driver: %s", err)
	}

	support.WaitUntilSignal()
}
Example #4
0
func main() {

	app := &App{}
	err := app.Init(info)
	if err != nil {
		fmt.Println("failed to initialize app:", err)
	}

	err = app.Export(app)
	if err != nil {
		fmt.Println("failed to export app:", err)
	}

	support.WaitUntilSignal()
}
Example #5
0
func main() {
	config.StableFlagFile = nconfig.String("/var/run/zigbee.stable", "zigbee", "stable-file")
	config.Hostname = nconfig.String("localhost", "zigbee", "host")

	check, err := os.Open("/etc/disable-zigbee")
	if err != nil {

		// this is the expected case

		_, err := NewDriver(config)
		if log.IsDebugEnabled() {
			log.Debugf("version - %s - running with configuration %+v", Version, config)
		}

		if err != nil {
			log.Fatalf("Failed to start ZigBee driver: %s", err)
		}
	} else {
		check.Close()
		log.Debugf("version - %s - zigbee access disabled by /etc/disable-zigbee", Version)
	}

	support.WaitUntilSignal()
}
Example #6
0
func main() {

	log.Infof("Welcome home, Ninja.")

	if config.Bool(true, "homecloud.waitForNTP") {
		waitForNTP()
	}

	// The MQTT Connection
	conn, err := ninja.Connect("sphere-go-homecloud")
	if err != nil {
		log.Fatalf("Failed to connect to sphere: %s", err)
	}

	// An MQTT Connection used for outbound syncing connections
	syncConn := &models.SyncConnection{}
	syncConn.Conn, err = ninja.Connect("sphere-go-homecloud.sync")
	if err != nil {
		log.Fatalf("Failed to connect to sphere (sync): %s", err)
	}

	// Our redis pool
	pool := &redis.Pool{
		MaxIdle:     config.MustInt("homecloud.redis.maxIdle"),
		MaxActive:   config.Int(10, "homecloud.redis.maxActive"),
		IdleTimeout: config.MustDuration("homecloud.redis.idleTimeout"),
		Wait:        true,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", fmt.Sprintf("%s:%d", config.String("", "homecloud.redis.host"), config.MustInt("homecloud.redis.port")))
			if err != nil {
				return nil, err
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}

	// Not pretty.
	rpc.RedisPool = pool

	// Wait until we connect to redis successfully.
	for {
		c := pool.Get()

		if c.Err() == nil {
			c.Close()
			break
		}
		log.Warningf("Failed to connect to redis: %s", c.Err())
		time.Sleep(time.Second)
	}

	// Build the object graph using dependency injection
	injectables := []interface{}{}

	injectables = append(injectables, pool, conn, syncConn)
	injectables = append(injectables, &homecloud.HomeCloud{}, &homecloud.TimeSeriesManager{}, &homecloud.DeviceManager{}, &homecloud.ModuleManager{})
	injectables = append(injectables, state.NewStateManager())
	injectables = append(injectables, &rest.RestServer{})
	injectables = append(injectables, models.GetInjectables()...)

	err = inject.Populate(injectables...)

	if err != nil {
		log.Fatalf("Failed to construct the object graph: %s", err)
	}

	// Run PostConstruct on any objects that have it
	for _, node := range injectables {
		if n, ok := node.(postConstructable); ok {
			go func(c postConstructable) {
				if err := c.PostConstruct(); err != nil {
					log.Fatalf("Failed PostConstruct on object %s: %s", reflect.TypeOf(c).String(), err)
				}
			}(n)
		}
	}

	support.WaitUntilSignal()
	// So long, and thanks for all the fish.
}