2017-03-22 17:39:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/clientapi/config"
|
|
|
|
"github.com/matrix-org/dendrite/clientapi/routing"
|
2017-03-29 13:05:43 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/storage"
|
|
|
|
"github.com/matrix-org/dendrite/clientapi/sync"
|
2017-03-22 17:39:08 +00:00
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
"github.com/matrix-org/dugong"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setupLogging(logDir string) {
|
|
|
|
_ = os.Mkdir(logDir, os.ModePerm)
|
|
|
|
log.AddHook(dugong.NewFSHook(
|
|
|
|
filepath.Join(logDir, "info.log"),
|
|
|
|
filepath.Join(logDir, "warn.log"),
|
|
|
|
filepath.Join(logDir, "error.log"),
|
|
|
|
&log.TextFormatter{
|
|
|
|
TimestampFormat: "2006-01-02 15:04:05.000000",
|
|
|
|
DisableColors: true,
|
|
|
|
DisableTimestamp: false,
|
|
|
|
DisableSorting: false,
|
|
|
|
}, &dugong.DailyRotationSchedule{GZip: true},
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bindAddr := os.Getenv("BIND_ADDRESS")
|
|
|
|
if bindAddr == "" {
|
|
|
|
log.Panic("No BIND_ADDRESS environment variable found.")
|
|
|
|
}
|
|
|
|
logDir := os.Getenv("LOG_DIR")
|
|
|
|
if logDir != "" {
|
|
|
|
setupLogging(logDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := config.Sync{
|
|
|
|
KafkaConsumerURIs: []string{"localhost:9092"},
|
|
|
|
RoomserverOutputTopic: "roomserverOutput",
|
2017-03-29 13:05:43 +00:00
|
|
|
DataSource: "postgres://dendrite:itsasecret@localhost/syncserver?sslmode=disable",
|
2017-03-22 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("Starting sync server")
|
|
|
|
|
2017-03-29 13:05:43 +00:00
|
|
|
db, err := storage.NewSyncServerDatabase(cfg.DataSource)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("startup: failed to create sync server database with data source %s : %s", cfg.DataSource, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
server, err := sync.NewServer(&cfg, db)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("startup: failed to create sync server: %s", err)
|
|
|
|
}
|
|
|
|
if err = server.Start(); err != nil {
|
|
|
|
log.Panicf("startup: failed to start sync server")
|
|
|
|
}
|
|
|
|
|
|
|
|
routing.SetupSyncServerListeners(http.DefaultServeMux, http.DefaultClient, cfg)
|
2017-03-22 17:39:08 +00:00
|
|
|
log.Fatal(http.ListenAndServe(bindAddr, nil))
|
|
|
|
}
|