Beispiel #1
0
func Run(args cli.Args) {
	c := cli.ParseArgs(args)
	initProfiling(c.HTTPProf, c.ProfileCPU, c.ProfileCPUFile)
	initLogging(c.LogLevel, c.ColorLog)

	// If the user Ctrl-C's, shutdown properly
	quit := make(chan int)
	go catchInterrupt(quit)
	// Watch for SIGUSR1
	go catchDebug()

	dconf := configureDaemon(c)
	d := daemon.NewDaemon(dconf)

	stopDaemon := make(chan int)
	go d.Start(stopDaemon)

	// Debug only - forces connection on start.  Violates thread safety.
	if c.ConnectTo != "" {
		_, err := d.Pool.Pool.Connect(c.ConnectTo)
		if err != nil {
			log.Panic(err)
		}
	}

	if !c.DisableGUI {
		go gui.LaunchGUI(d)
	}

	host := fmt.Sprintf("%s:%d", c.WebInterfaceAddr, c.WebInterfacePort)

	if c.WebInterface {
		if c.WebInterfaceHTTPS {
			// Verify cert/key parameters, and if neither exist, create them
			errs := gui.CreateCertIfNotExists(host, c.WebInterfaceCert,
				c.WebInterfaceKey)
			if len(errs) != 0 {
				for _, err := range errs {
					logger.Error(err.Error())
				}
			} else {
				go gui.LaunchWebInterfaceHTTPS(host, c.GUIDirectory, d,
					c.WebInterfaceCert, c.WebInterfaceKey)
			}
		} else {
			go gui.LaunchWebInterface(host, c.GUIDirectory, d)
		}
	}

	<-quit
	stopDaemon <- 1

	logger.Info("Shutting down")
	d.Shutdown()
	logger.Info("Goodbye")
}
Beispiel #2
0
func Run(c *Config) {
	scheme := "http"
	if c.WebInterfaceHTTPS {
		scheme = "https"
	}
	host := fmt.Sprintf("%s:%d", c.WebInterfaceAddr, c.WebInterfacePort)
	fullAddress := fmt.Sprintf("%s://%s", scheme, host)
	logger.Critical("Full address: %s", fullAddress)

	if c.PrintWebInterfaceAddress {
		fmt.Println(fullAddress)
		return
	}

	initProfiling(c.HTTPProf, c.ProfileCPU, c.ProfileCPUFile)
	initLogging(c.LogLevel, c.ColorLog)

	// If the user Ctrl-C's, shutdown properly
	quit := make(chan int)
	go catchInterrupt(quit)
	// Watch for SIGUSR1
	go catchDebug()

	gui.InitWalletRPC(c.WalletDirectory)

	dconf := configureDaemon(c)
	d := daemon.NewDaemon(dconf)

	stopDaemon := make(chan int)
	go d.Start(stopDaemon)

	// Debug only - forces connection on start.  Violates thread safety.
	if c.ConnectTo != "" {
		_, err := d.Pool.Pool.Connect(c.ConnectTo)
		if err != nil {
			log.Panic(err)
		}
	}

	if c.WebInterface {
		var err error
		if c.WebInterfaceHTTPS {
			// Verify cert/key parameters, and if neither exist, create them
			errs := gui.CreateCertIfNotExists(host, c.WebInterfaceCert, c.WebInterfaceKey)
			if len(errs) != 0 {
				for _, err := range errs {
					logger.Error(err.Error())
				}
				logger.Error("gui.CreateCertIfNotExists failure")
				os.Exit(1)
			}

			err = gui.LaunchWebInterfaceHTTPS(host, c.GUIDirectory, d, c.WebInterfaceCert, c.WebInterfaceKey)
		} else {
			err = gui.LaunchWebInterface(host, c.GUIDirectory, d)
		}

		if err != nil {
			logger.Error(err.Error())
			logger.Error("Failed to start web GUI")
			os.Exit(1)
		}

		if c.LaunchBrowser {
			go func() {
				// Wait a moment just to make sure the http interface is up
				time.Sleep(time.Millisecond * 100)

				logger.Info("Launching System Browser with %s", fullAddress)
				if err := util.OpenBrowser(fullAddress); err != nil {
					logger.Error(err.Error())
				}
			}()
		}
	}

	/*
		time.Sleep(5)
		tx := InitTransaction()
		_ = tx
		err, _ = d.Visor.Visor.InjectTxn(tx)
		if err != nil {
			log.Panic(err)
		}
	*/

	<-quit
	stopDaemon <- 1

	logger.Info("Shutting down")
	d.Shutdown()
	logger.Info("Goodbye")
}