X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=main.go;h=32083bbd41045c000486cc999a3c74a580984b7a;hb=fd312d109f78dd5b9825e8f1dae255d847a76f7a;hp=0a0ad0ab7da6a614e6b50cb02bb5693ffdec73c9;hpb=a50baa7c309f7eb55fe87c71f4c688ace325b6ac;p=src%2Fxds%2Fxds-agent.git diff --git a/main.go b/main.go index 0a0ad0a..32083bb 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( + "fmt" "log" "os" "time" @@ -11,8 +12,8 @@ import ( "github.com/codegangsta/cli" "github.com/iotbzh/xds-agent/lib/agent" "github.com/iotbzh/xds-agent/lib/syncthing" + "github.com/iotbzh/xds-agent/lib/webserver" "github.com/iotbzh/xds-agent/lib/xdsconfig" - "github.com/iotbzh/xds-agent/lib/xdsserver" ) const ( @@ -54,23 +55,24 @@ func xdsAgent(cliCtx *cli.Context) error { 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) - retry := 10 + maxRetry := 30 + retry := maxRetry for retry > 0 { if err := ctx.SThg.Connect(); err == nil { break } - ctx.Log.Infof("Establishing connection to Syncthing (retry %d/10)", retry) + ctx.Log.Infof("Establishing connection to Syncthing (retry %d/%d)", retry, maxRetry) time.Sleep(time.Second) retry-- } @@ -86,7 +88,7 @@ func xdsAgent(cliCtx *cli.Context) error { ctx.Log.Infof("Local Syncthing ID: %s", id) // Create and start Web Server - ctx.WWWServer = xdsserver.NewServer(ctx.Config, ctx.Log) + ctx.WWWServer = webserver.New(ctx.Config, ctx.Log) if err = ctx.WWWServer.Serve(); err != nil { log.Println(err) return cli.NewExitError(err, 3)