+/*
+ * Copyright (C) 2017-2018 "IoT.bzh"
+ * Author Sebastien Douheret <sebastien@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package xdsserver
import (
"syscall"
"time"
+ st "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/syncthing"
+ "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xdsconfig"
+ "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
- "github.com/iotbzh/xds-server/lib/xsapiv1"
-
- "github.com/iotbzh/xds-server/lib/syncthing"
- "github.com/iotbzh/xds-server/lib/xdsconfig"
)
const cookieMaxAge = "3600"
Config *xdsconfig.Config
Log *logrus.Logger
LogLevelSilly bool
+ LogSillyf func(format string, args ...interface{})
SThg *st.SyncThing
SThgCmd *exec.Cmd
SThgInotCmd *exec.Cmd
mfolders *Folders
sdks *SDKs
+ targets *Targets
WWWServer *WebServer
sessions *Sessions
+ events *Events
+ lock Lock
Exit chan os.Signal
}
}
log.Formatter = &logrus.TextFormatter{}
+ // Support silly logging (printed on log.debug)
sillyVal, sillyLog := os.LookupEnv("XDS_LOG_SILLY")
+ logSilly := sillyLog && sillyVal == "1"
+ sillyFunc := func(format string, args ...interface{}) {
+ if logSilly {
+ log.Debugf("SILLY: "+format, args...)
+ }
+ }
// Define default configuration
ctx := Context{
ProgName: cliCtx.App.Name,
Cli: cliCtx,
Log: log,
- LogLevelSilly: (sillyLog && sillyVal == "1"),
+ LogLevelSilly: logSilly,
+ LogSillyf: sillyFunc,
+ lock: Lock{LockCpt: 0},
Exit: make(chan os.Signal, 1),
}
ctx._logPrint("Logging file for HTTP requests: %s\n", logFileHTTPReq)
}
- // Create syncthing instance when section "syncthing" is present in config.json
+ // Create events management
+ ctx.events = EventsConstructor(ctx)
+
+ // Create syncthing instance when section "syncthing" is present in server-config.json
if ctx.Config.FileConf.SThgConf != nil {
ctx.SThg = st.NewSyncThing(ctx.Config, ctx.Log)
}
}
// Init model folder
- ctx.mfolders = FoldersNew(ctx)
+ ctx.mfolders = FoldersConstructor(ctx)
// Load initial folders config from disk
if err := ctx.mfolders.LoadConfig(); err != nil {
}
// Init cross SDKs
- ctx.sdks, err = NewSDKs(ctx)
+ ctx.sdks, err = SDKsConstructor(ctx)
if err != nil {
return -6, err
}
+ // Init target and terminals model
+ ctx.targets = TargetsConstructor(ctx)
+
+ // Load initial target & terminal config
+ if err := ctx.targets.LoadConfig(); err != nil {
+ return -6, err
+ }
+
// Create Web Server
- ctx.WWWServer = NewWebServer(ctx)
+ ctx.WWWServer = WebServerConstructor(ctx)
// Sessions manager
- ctx.sessions = NewClientSessions(ctx, cookieMaxAge)
+ ctx.sessions = ClientSessionsConstructor(ctx, cookieMaxAge)
+
+ // Check if a new package version is available
+ // and monitor updates
+ MonitorUpdates(ctx)
// Run Web Server until exit requested (blocking call)
if err = ctx.WWWServer.Serve(); err != nil {