func main() {
	updatelater := flag.Bool("updatelater", false, "Update later")
	flag.Parse()

	had_update := false
	if !*updatelater && os.Getenv("GOAGAIN_PPID") == "" { // not after gone again
		log.Println("Initial check for updates; run with -updatelater to disable")
		had_update = update_once(false)
	}

	martini.Env = martini.Prod
	listen, err := goagain.Listener()
	if err != nil {
		listen, err = ostential.Listen()
		if err != nil {
			if _, ok := err.(ostential.FlagError); ok {
				flag.Usage()
				os.Exit(2)
				return
			}
			log.Fatalln(err)
		}

		if had_update { // goagain
			go func() {
				time.Sleep(time.Second) // not before goagain.Wait
				syscall.Kill(os.Getpid(), syscall.SIGUSR2)
				// goagain.ForkExec(listen)
			}()
		} else {
			go update_loop()
			go ostential.Serve(listen, ostential.LogOne, nil)
		}

	} else {
		go update_loop()
		go ostential.Serve(listen, ostential.LogOne, nil)

		if err := goagain.Kill(); err != nil {
			log.Fatalln(err)
		}
	}

	if _, err := goagain.Wait(listen); err != nil { // signals before won't be catched
		log.Fatalln(err)
	}
	if err := listen.Close(); err != nil {
		log.Fatalln(err)
	}
	time.Sleep(time.Second)
}
func main() {
	martini.Env = martini.Dev

	listen, err := ostential.Listen()
	if err == nil {
		log.Fatal(ostential.Serve(listen, ostential.LogAll, func(m *ostential.Modern) {
			m.Any("/debug/pprof/cmdline", pprof.Cmdline)
			m.Any("/debug/pprof/profile", pprof.Profile)
			m.Any("/debug/pprof/symbol", pprof.Symbol)
			m.Any("/debug/pprof/.*", pprof.Index)
		}))
	}
	if _, ok := err.(ostential.FlagError); !ok {
		log.Fatal(err)
	}
	flag.Usage()
	os.Exit(2)
}