You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
package main
|
|
|
|
import (
|
|
lucifer3 "git.aiterp.net/lucifer3/server"
|
|
"git.aiterp.net/lucifer3/server/events"
|
|
"git.aiterp.net/lucifer3/server/services"
|
|
"git.aiterp.net/lucifer3/server/services/effectenforcer"
|
|
"git.aiterp.net/lucifer3/server/services/httpapiv1"
|
|
"git.aiterp.net/lucifer3/server/services/hue"
|
|
"git.aiterp.net/lucifer3/server/services/mysqldb"
|
|
"git.aiterp.net/lucifer3/server/services/nanoleaf"
|
|
"git.aiterp.net/lucifer3/server/services/script"
|
|
"git.aiterp.net/lucifer3/server/services/tradfri"
|
|
"git.aiterp.net/lucifer3/server/services/uistate"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"strconv"
|
|
"syscall"
|
|
)
|
|
|
|
func main() {
|
|
bus := lucifer3.EventBus{}
|
|
|
|
resolver := services.NewResolver()
|
|
variables := script.NewVariables()
|
|
|
|
database, err := mysqldb.Connect(
|
|
env("LUCIFER4_DB_HOST"),
|
|
envInt("LUCIFER4_DB_PORT"),
|
|
env("LUCIFER4_DB_USER"),
|
|
env("LUCIFER4_DB_PASSWORD"),
|
|
env("LUCIFER4_DB_SCHEMA"),
|
|
)
|
|
if err != nil {
|
|
log.Fatalln("Database failed", err)
|
|
}
|
|
|
|
httpAPI, err := httpapiv1.New(env("LUCIFER4_HTTP_LISTEN"))
|
|
if err != nil {
|
|
log.Fatalln("HTTP Listen failed", err)
|
|
}
|
|
|
|
bus.JoinPrivileged(resolver)
|
|
bus.Join(effectenforcer.NewService(resolver))
|
|
bus.Join(nanoleaf.NewService())
|
|
bus.Join(hue.NewService())
|
|
bus.Join(tradfri.NewService())
|
|
bus.Join(uistate.NewService())
|
|
bus.Join(script.NewService(resolver, variables))
|
|
bus.Join(database)
|
|
bus.Join(httpAPI)
|
|
bus.Join(variables)
|
|
|
|
bus.RunEvent(events.Started{})
|
|
|
|
exitSignal := make(chan os.Signal)
|
|
signal.Notify(exitSignal, os.Interrupt, os.Kill, syscall.SIGTERM)
|
|
sig := <-exitSignal
|
|
log.Println("Received signal", sig)
|
|
}
|
|
|
|
func env(key string) string {
|
|
value := os.Getenv(key)
|
|
if value == "" {
|
|
log.Fatalln("Expected env:", key)
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func envInt(key string) int {
|
|
value, err := strconv.Atoi(os.Getenv(key))
|
|
if err != nil {
|
|
log.Fatalln("Expected numeric env:", key)
|
|
}
|
|
|
|
return value
|
|
}
|