func main() { runtime.GOMAXPROCS(runtime.NumCPU()) defer logger.Flush() if err := app.Run(os.Args); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }
// Fatalf formats a message to standard error and exits the program. // The message is also printed to standard output if standard error // is redirected to a different file. func Fatalf(format string, args ...interface{}) { w := io.MultiWriter(os.Stdout, os.Stderr) outf, _ := os.Stdout.Stat() errf, _ := os.Stderr.Stat() if outf != nil && errf != nil && os.SameFile(outf, errf) { w = os.Stderr } fmt.Fprintf(w, "Fatal: "+format+"\n", args...) logger.Flush() os.Exit(1) }
func StartEthereum(ethereum *eth.Ethereum) { glog.V(logger.Info).Infoln("Starting", ethereum.Name()) if err := ethereum.Start(); err != nil { Fatalf("Error starting Shift: %v", err) } go func() { sigc := make(chan os.Signal, 1) signal.Notify(sigc, os.Interrupt) defer signal.Stop(sigc) <-sigc glog.V(logger.Info).Infoln("Got interrupt, shutting down...") go ethereum.Stop() logger.Flush() for i := 10; i > 0; i-- { <-sigc if i > 1 { glog.V(logger.Info).Infoln("Already shutting down, please be patient.") glog.V(logger.Info).Infoln("Interrupt", i-1, "more times to induce panic.") } } glog.V(logger.Error).Infof("Force quitting: this might not end so well.") panic("boom") }() }