- 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(3 * time.Second)
- retry := 10
- for retry > 0 {
- if err := ctx.SThg.Connect(); err == nil {
- break
- }
- ctx.Log.Infof("Establishing connection to Syncthing (retry %d/5)", retry)
- time.Sleep(time.Second)
- retry--
- }
- if ctx.SThg == nil {
- err = fmt.Errorf("ERROR: cannot connect to Syncthing (url: %s)", ctx.SThg.BaseURL)
- return cli.NewExitError(err, 2)
- }
-
- // Retrieve Syncthing config
- id, err := ctx.SThg.IDGet()
- if err != nil {
- return cli.NewExitError(err, 2)
- }
- ctx.Log.Infof("Local Syncthing ID: %s", id)
-
- // Create and start Web Server
- ctx.WWWServer = xdsserver.NewServer(ctx.Config, ctx.Log)
- if err = ctx.WWWServer.Serve(); err != nil {
- log.Println(err)
- return cli.NewExitError(err, 3)
- }
-
- return cli.NewExitError("Program exited ", 4)