aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-17 11:28:57 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-17 14:04:32 +0200
commit40a7183f3b4aa32379aa8b4949f5f9c5e32f79f6 (patch)
tree25a98c1b6c6c7b5e186ae3cf0dc11807b2fa088a /main.go
parentc07adb807c41a1545a9a0f5bbf40080d86946538 (diff)
Add SDKs support.
Don't allow to install SDKs through XDS for now. Only probe existing SDKs that have been manually installed using scripts/agl/install-agl-sdks.sh. Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'main.go')
-rw-r--r--main.go44
1 files changed, 31 insertions, 13 deletions
diff --git a/main.go b/main.go
index ba445f5..36586cf 100644
--- a/main.go
+++ b/main.go
@@ -13,6 +13,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
+ "github.com/iotbzh/xds-server/lib/crosssdk"
"github.com/iotbzh/xds-server/lib/model"
"github.com/iotbzh/xds-server/lib/syncthing"
"github.com/iotbzh/xds-server/lib/webserver"
@@ -39,15 +40,17 @@ var AppSubVersion = "unknown-dev"
// Context holds the XDS server context
type Context struct {
- ProgName string
- Cli *cli.Context
- Config *xdsconfig.Config
- Log *logrus.Logger
- SThg *st.SyncThing
- SThgCmd *exec.Cmd
- MFolder *model.Folder
- WWWServer *webserver.ServerService
- Exit chan os.Signal
+ ProgName string
+ Cli *cli.Context
+ Config *xdsconfig.Config
+ Log *logrus.Logger
+ SThg *st.SyncThing
+ SThgCmd *exec.Cmd
+ SThgInotCmd *exec.Cmd
+ MFolder *model.Folder
+ SDKs *crosssdk.SDKs
+ WWWServer *webserver.Server
+ Exit chan os.Signal
}
// NewContext Create a new instance of XDS server
@@ -86,9 +89,10 @@ func NewContext(cliCtx *cli.Context) *Context {
func handlerSigTerm(ctx *Context) {
<-ctx.Exit
if ctx.SThg != nil {
- ctx.Log.Infof("Stopping Syncthing... (PID %d)",
- ctx.SThgCmd.Process.Pid)
+ ctx.Log.Infof("Stoping Syncthing... (PID %d)", ctx.SThgCmd.Process.Pid)
ctx.SThg.Stop()
+ ctx.Log.Infof("Stoping Syncthing-inotify... (PID %d)", ctx.SThgInotCmd.Process.Pid)
+ ctx.SThg.StopInotify()
}
if ctx.WWWServer != nil {
ctx.Log.Infof("Stoping Web server...")
@@ -97,7 +101,7 @@ func handlerSigTerm(ctx *Context) {
os.Exit(1)
}
-// xdsServer main routine
+// XDS Server application main routine
func xdsApp(cliCtx *cli.Context) error {
var err error
@@ -130,7 +134,15 @@ func xdsApp(cliCtx *cli.Context) error {
}
ctx.Log.Infof("Syncthing started (PID %d)", ctx.SThgCmd.Process.Pid)
+ ctx.Log.Infof("Starting Syncthing-inotify...")
+ ctx.SThgInotCmd, err = ctx.SThg.StartInotify()
+ if err != nil {
+ return cli.NewExitError(err, 2)
+ }
+ ctx.Log.Infof("Syncthing-inotify started (PID %d)", ctx.SThgInotCmd.Process.Pid)
+
// Establish connection with local Syncthing (retry if connection fail)
+ time.Sleep(2 * time.Second)
retry := 10
err = nil
for retry > 0 {
@@ -177,8 +189,14 @@ func xdsApp(cliCtx *cli.Context) error {
return cli.NewExitError(err, 3)
}
+ // Init cross SDKs
+ ctx.SDKs, err = crosssdk.Init(ctx.Config, ctx.Log)
+ if err != nil {
+ return cli.NewExitError(err, 2)
+ }
+
// Create and start Web Server
- ctx.WWWServer = webserver.NewServer(ctx.Config, ctx.MFolder, ctx.Log)
+ ctx.WWWServer = webserver.New(ctx.Config, ctx.MFolder, ctx.SDKs, ctx.Log)
if err = ctx.WWWServer.Serve(); err != nil {
ctx.Log.Println(err)
return cli.NewExitError(err, 3)