Added prints on startup.
[src/xds/xds-agent.git] / main.go
diff --git a/main.go b/main.go
index 93d13a2..eeb4036 100644 (file)
--- a/main.go
+++ b/main.go
@@ -3,12 +3,11 @@
 package main
 
 import (
+       "fmt"
        "log"
        "os"
        "time"
 
-       "fmt"
-
        "github.com/Sirupsen/logrus"
        "github.com/codegangsta/cli"
        "github.com/iotbzh/xds-agent/lib/agent"
@@ -37,33 +36,33 @@ var AppSubVersion = "unknown-dev"
 
 // xdsAgent main routine
 func xdsAgent(cliCtx *cli.Context) error {
+       var err error
 
        // Create Agent context
        ctx := agent.NewAgent(cliCtx)
 
        // Load config
-       cfg, err := xdsconfig.Init(cliCtx, ctx.Log)
+       ctx.Config, err = xdsconfig.Init(cliCtx, ctx.Log)
        if err != nil {
                return cli.NewExitError(err, 2)
        }
-       ctx.Config = &cfg
 
        // Start local instance of Syncthing and Syncthing-notify
-       ctx.SThg = st.NewSyncThing(ctx.Config.FileConf.SThgConf, ctx.Log)
+       ctx.SThg = st.NewSyncThing(ctx.Config, ctx.Log)
 
        ctx.Log.Infof("Starting Syncthing...")
        ctx.SThgCmd, err = ctx.SThg.Start()
        if err != nil {
                return cli.NewExitError(err, 2)
        }
-       ctx.Log.Infof("Syncthing started (PID %d)", ctx.SThgCmd.Process.Pid)
+       fmt.Printf("Syncthing started (PID %d)\n", 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)
+       fmt.Printf("Syncthing-inotify started (PID %d)\n", ctx.SThgInotCmd.Process.Pid)
 
        // Establish connection with local Syncthing (retry if connection fail)
        time.Sleep(3 * time.Second)
@@ -72,12 +71,11 @@ func xdsAgent(cliCtx *cli.Context) error {
                if err := ctx.SThg.Connect(); err == nil {
                        break
                }
-               ctx.Log.Infof("Establishing connection to Syncthing (retry %d/5)", retry)
+               ctx.Log.Infof("Establishing connection to Syncthing (retry %d/10)", retry)
                time.Sleep(time.Second)
                retry--
        }
-       if ctx.SThg == nil {
-               err = fmt.Errorf("ERROR: cannot connect to Syncthing (url: %s)", ctx.SThg.BaseURL)
+       if err != nil || retry == 0 {
                return cli.NewExitError(err, 2)
        }