本文整理匯總了Golang中github.com/flynn/flynn/pkg/shutdown.Fatal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fatal函數的具體用法?Golang Fatal怎麽用?Golang Fatal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fatal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
/*
ish: the Inexusable/Insecure/Internet SHell.
*/
func main() {
defer shutdown.Exit()
name := os.Getenv("NAME")
port := os.Getenv("PORT")
addr := ":" + port
if name == "" {
name = "ish-service"
}
l, err := net.Listen("tcp", addr)
if err != nil {
shutdown.Fatal(err)
}
defer l.Close()
hb, err := discoverd.AddServiceAndRegister(name, addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
http.HandleFunc("/ish", ish)
if err := http.Serve(l, nil); err != nil {
shutdown.Fatal(err)
}
}
示例2: main
func main() {
logger := log15.New("component", "scheduler")
logger.SetHandler(log15.LvlFilterHandler(log15.LvlInfo, log15.StdoutHandler))
log := logger.New("fn", "main")
log.Info("creating cluster and controller clients")
hc := &http.Client{Timeout: 5 * time.Second}
clusterClient := utils.ClusterClientWrapper(cluster.NewClientWithHTTP(nil, hc))
controllerClient, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
log.Error("error creating controller client", "err", err)
shutdown.Fatal(err)
}
log.Info("waiting for controller API to come up")
if _, err := discoverd.GetInstances("controller", 5*time.Minute); err != nil {
log.Error("error waiting for controller API", "err", err)
shutdown.Fatal(err)
}
s := NewScheduler(clusterClient, controllerClient, newDiscoverdWrapper(logger), logger)
log.Info("started scheduler", "backoffPeriod", s.backoffPeriod)
go s.startHTTPServer(os.Getenv("PORT"))
if err := s.Run(); err != nil {
shutdown.Fatal(err)
}
shutdown.Exit()
}
示例3: main
func main() {
defer shutdown.Exit()
db := postgres.Wait(&postgres.Conf{
Service: serviceName,
User: "flynn",
Password: os.Getenv("PGPASSWORD"),
Database: "postgres",
}, nil)
api := &pgAPI{db}
router := httprouter.New()
router.POST("/databases", httphelper.WrapHandler(api.createDatabase))
router.DELETE("/databases", httphelper.WrapHandler(api.dropDatabase))
router.GET("/ping", httphelper.WrapHandler(api.ping))
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
hb, err := discoverd.AddServiceAndRegister(serviceName+"-api", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
handler := httphelper.ContextInjector(serviceName+"-api", httphelper.NewRequestLogger(router))
shutdown.Fatal(http.ListenAndServe(addr, handler))
}
示例4: ConfigureNetworking
func (h *jobAPI) ConfigureNetworking(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
log := h.host.log.New("fn", "ConfigureNetworking")
log.Info("decoding config")
config := &host.NetworkConfig{}
if err := httphelper.DecodeJSON(r, config); err != nil {
log.Error("error decoding config", "err", err)
shutdown.Fatal(err)
}
// configure the network before returning a response in case the
// network coordinator requires the bridge to be created (e.g.
// when using flannel with the "alloc" backend)
h.host.networkOnce.Do(func() {
log.Info("configuring network", "subnet", config.Subnet, "mtu", config.MTU, "resolvers", config.Resolvers)
if err := h.host.backend.ConfigureNetworking(config); err != nil {
log.Error("error configuring network", "err", err)
shutdown.Fatal(err)
}
h.host.statusMtx.Lock()
h.host.status.Network = config
h.host.statusMtx.Unlock()
})
}
示例5: main
func main() {
defer shutdown.Exit()
dsn := &mariadb.DSN{
Host: serviceHost + ":3306",
User: "flynn",
Password: os.Getenv("MYSQL_PWD"),
Database: "mysql",
}
db, err := sql.Open("mysql", dsn.String())
api := &API{db}
router := httprouter.New()
router.POST("/databases", httphelper.WrapHandler(api.createDatabase))
router.DELETE("/databases", httphelper.WrapHandler(api.dropDatabase))
router.GET("/ping", httphelper.WrapHandler(api.ping))
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
hb, err := discoverd.AddServiceAndRegister(serviceName+"-api", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
handler := httphelper.ContextInjector(serviceName+"-api", httphelper.NewRequestLogger(router))
shutdown.Fatal(http.ListenAndServe(addr, handler))
}
示例6: main
func main() {
defer shutdown.Exit()
api := &API{}
router := httprouter.New()
router.POST("/databases", api.createDatabase)
router.DELETE("/databases", api.dropDatabase)
router.GET("/ping", api.ping)
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
hb, err := discoverd.AddServiceAndRegister(serviceName+"-api", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
handler := httphelper.ContextInjector(serviceName+"-api", httphelper.NewRequestLogger(router))
shutdown.Fatal(http.ListenAndServe(addr, handler))
}
示例7: main
func main() {
serviceName := os.Getenv("FLYNN_POSTGRES")
if serviceName == "" {
serviceName = "postgres"
}
singleton := os.Getenv("SINGLETON") == "true"
password := os.Getenv("PGPASSWORD")
const dataDir = "/data"
idFile := filepath.Join(dataDir, "instance_id")
idBytes, err := ioutil.ReadFile(idFile)
if err != nil && !os.IsNotExist(err) {
shutdown.Fatalf("error reading instance ID: %s", err)
}
id := string(idBytes)
if len(id) == 0 {
id = random.UUID()
if err := ioutil.WriteFile(idFile, []byte(id), 0644); err != nil {
shutdown.Fatalf("error writing instance ID: %s", err)
}
}
err = discoverd.DefaultClient.AddService(serviceName, &discoverd.ServiceConfig{
LeaderType: discoverd.LeaderTypeManual,
})
if err != nil && !httphelper.IsObjectExistsError(err) {
shutdown.Fatal(err)
}
inst := &discoverd.Instance{
Addr: ":5432",
Meta: map[string]string{pgIdKey: id},
}
hb, err := discoverd.DefaultClient.RegisterInstance(serviceName, inst)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
log := log15.New("app", "postgres")
pg := NewPostgres(Config{
ID: id,
Singleton: singleton,
DataDir: filepath.Join(dataDir, "db"),
BinDir: "/usr/lib/postgresql/9.5/bin/",
Password: password,
Logger: log.New("component", "postgres"),
ExtWhitelist: true,
WaitUpstream: true,
SHMType: "posix",
})
dd := sd.NewDiscoverd(discoverd.DefaultClient.Service(serviceName), log.New("component", "discoverd"))
peer := state.NewPeer(inst, id, pgIdKey, singleton, dd, pg, log.New("component", "peer"))
shutdown.BeforeExit(func() { peer.Close() })
go peer.Run()
shutdown.Fatal(ServeHTTP(pg.(*Postgres), peer, hb, log.New("component", "http")))
// TODO(titanous): clean shutdown of postgres
}
示例8: main
func main() {
defer shutdown.Exit()
apiPort := os.Getenv("PORT")
if apiPort == "" {
apiPort = "5000"
}
logAddr := flag.String("logaddr", ":3000", "syslog input listen address")
apiAddr := flag.String("apiaddr", ":"+apiPort, "api listen address")
flag.Parse()
a := NewAggregator(*logAddr)
if err := a.Start(); err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(a.Shutdown)
listener, err := reuseport.NewReusablePortListener("tcp4", *apiAddr)
if err != nil {
shutdown.Fatal(err)
}
hb, err := discoverd.AddServiceAndRegister("flynn-logaggregator", *logAddr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
shutdown.Fatal(http.Serve(listener, apiHandler(a)))
}
示例9: main
func main() {
m := NewMain()
if err := m.ParseFlags(os.Args[1:]); err != nil {
shutdown.Fatal(err)
}
if err := m.Run(); err != nil {
shutdown.Fatal(err)
}
<-(chan struct{})(nil)
}
示例10: main
func main() {
defer shutdown.Exit()
grohl.AddContext("app", "controller-scheduler")
grohl.Log(grohl.Data{"at": "start"})
go startHTTPServer()
if period := os.Getenv("BACKOFF_PERIOD"); period != "" {
var err error
backoffPeriod, err = time.ParseDuration(period)
if err != nil {
shutdown.Fatal(err)
}
grohl.Log(grohl.Data{"at": "backoff_period", "period": backoffPeriod.String()})
}
cc, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
shutdown.Fatal(err)
}
c := newContext(cc, cluster.NewClient())
c.watchHosts()
grohl.Log(grohl.Data{"at": "leaderwait"})
hb, err := discoverd.AddServiceAndRegister("controller-scheduler", ":"+os.Getenv("PORT"))
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
leaders := make(chan *discoverd.Instance)
stream, err := discoverd.NewService("controller-scheduler").Leaders(leaders)
if err != nil {
shutdown.Fatal(err)
}
for leader := range leaders {
if leader.Addr == hb.Addr() {
break
}
}
if err := stream.Err(); err != nil {
// TODO: handle discoverd errors
shutdown.Fatal(err)
}
stream.Close()
// TODO: handle demotion
grohl.Log(grohl.Data{"at": "leader"})
// TODO: periodic full cluster sync for anti-entropy
c.watchFormations()
}
示例11: main
func main() {
log := logger.New("fn", "main")
log.Info("creating controller client")
client, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
log.Error("error creating controller client", "err", err)
shutdown.Fatal(err)
}
log.Info("connecting to postgres")
db := postgres.Wait(nil, schema.PrepareStatements)
shutdown.BeforeExit(func() { db.Close() })
go func() {
status.AddHandler(func() status.Status {
_, err := db.ConnPool.Exec("ping")
if err != nil {
return status.Unhealthy
}
return status.Healthy
})
addr := ":" + os.Getenv("PORT")
hb, err := discoverd.AddServiceAndRegister("controller-worker", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
shutdown.Fatal(http.ListenAndServe(addr, nil))
}()
workers := que.NewWorkerPool(
que.NewClient(db.ConnPool),
que.WorkMap{
"deployment": deployment.JobHandler(db, client, logger),
"app_deletion": app_deletion.JobHandler(db, client, logger),
"domain_migration": domain_migration.JobHandler(db, client, logger),
"release_cleanup": release_cleanup.JobHandler(db, client, logger),
"app_garbage_collection": app_garbage_collection.JobHandler(db, client, logger),
},
workerCount,
)
workers.Interval = 5 * time.Second
log.Info("starting workers", "count", workerCount, "interval", workers.Interval)
workers.Start()
shutdown.BeforeExit(func() { workers.Shutdown() })
select {} // block and keep running
}
示例12: ConfigureNetworking
func (h *jobAPI) ConfigureNetworking(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
config := &host.NetworkConfig{}
if err := httphelper.DecodeJSON(r, config); err != nil {
shutdown.Fatal(err)
}
go h.networkOnce.Do(func() {
if err := h.host.backend.ConfigureNetworking(config); err != nil {
shutdown.Fatal(err)
}
h.statusMtx.Lock()
h.status.Network = config
h.statusMtx.Unlock()
})
}
示例13: ConnectLocal
func (d *DiscoverdManager) ConnectLocal(url string) error {
if d.localConnected() {
return errors.New("host: discoverd is already configured")
}
disc := discoverd.NewClientWithURL(url)
hb, err := disc.AddServiceAndRegisterInstance("flynn-host", d.inst)
if err != nil {
return err
}
d.mtx.Lock()
if d.peer != nil {
d.peer.Close()
}
d.local = hb
d.mtx.Unlock()
d.backend.SetDefaultEnv("DISCOVERD", url)
go func() {
if err := d.mux.Connect(disc, "flynn-logaggregator"); err != nil {
shutdown.Fatal(err)
}
}()
return nil
}
示例14: ConfigureDiscoverd
func (h *Host) ConfigureDiscoverd(config *host.DiscoverdConfig) {
log := h.log.New("fn", "ConfigureDiscoverd")
if config.JobID != "" {
log.Info("persisting discoverd job_id", "job.id", config.JobID)
if err := h.state.SetPersistentSlot("discoverd", config.JobID); err != nil {
log.Error("error assigning discoverd to persistent slot")
}
}
if config.URL != "" && config.DNS != "" {
go h.discoverdOnce.Do(func() {
log.Info("connecting to service discovery", "url", config.URL)
if err := h.discMan.ConnectLocal(config.URL); err != nil {
log.Error("error connecting to service discovery", "err", err)
shutdown.Fatal(err)
}
})
}
h.statusMtx.Lock()
h.status.Discoverd = config
h.backend.SetDiscoverdConfig(h.status.Discoverd)
h.statusMtx.Unlock()
if config.URL != "" {
h.volAPI.ConfigureClusterClient(config.URL)
}
}
示例15: ConfigureDiscoverd
func (h *jobAPI) ConfigureDiscoverd(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
log := h.host.log.New("fn", "ConfigureDiscoverd")
log.Info("decoding config")
var config host.DiscoverdConfig
if err := httphelper.DecodeJSON(r, &config); err != nil {
log.Error("error decoding config", "err", err)
httphelper.Error(w, err)
return
}
log.Info("config decoded", "url", config.URL, "dns", config.DNS)
h.host.statusMtx.Lock()
h.host.status.Discoverd = &config
h.host.statusMtx.Unlock()
if config.URL != "" && config.DNS != "" {
go h.host.discoverdOnce.Do(func() {
log.Info("connecting to service discovery", "url", config.URL)
if err := h.host.discMan.ConnectLocal(config.URL); err != nil {
log.Error("error connecting to service discovery", "err", err)
shutdown.Fatal(err)
}
})
}
}