本文整理匯總了Golang中github.com/flynn/flynn/pkg/shutdown.Exit函數的典型用法代碼示例。如果您正苦於以下問題:Golang Exit函數的具體用法?Golang Exit怎麽用?Golang Exit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Exit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runVolumeDestroy
func runVolumeDestroy(args *docopt.Args) error {
if os.Getuid() != 0 {
fmt.Println("this command requires root!\ntry again with `sudo flynn-host destroy-volumes`.")
shutdown.ExitWithCode(1)
}
volPath := args.String["--volpath"]
includeData := args.Bool["--include-data"]
keepSystemImages := args.Bool["--keep-system-images"]
volumeDBPath := filepath.Join(volPath, "volumes.bolt")
// if there is no state db, nothing to do
if _, err := os.Stat(volumeDBPath); err != nil && os.IsNotExist(err) {
fmt.Printf("no volume state db exists at %q; already clean.\n", volumeDBPath)
shutdown.Exit()
}
// open state db. we're maybe using it; and regardless want to flock before removing it
vman, vmanErr := loadVolumeState(volumeDBPath)
// if '--include-data' specified and vman loaded, destroy volumes
allVolumesDestroyed := true
if vmanErr != nil {
fmt.Printf("%s\n", vmanErr)
} else if includeData == false {
fmt.Println("'--include-data' not specified; leaving backend data storage intact.")
} else {
if err := destroyVolumes(vman, keepSystemImages); err != nil {
fmt.Printf("%s\n", err)
allVolumesDestroyed = false
}
}
if !keepSystemImages {
// remove db file
if err := os.Remove(volumeDBPath); err != nil {
fmt.Printf("could not remove volume state db file %q: %s.\n", volumeDBPath, err)
shutdown.ExitWithCode(5)
}
fmt.Printf("state db file %q removed.\n", volumeDBPath)
}
// exit code depends on if all volumes were destroyed successfully or not
if includeData && !allVolumesDestroyed {
shutdown.ExitWithCode(6)
}
shutdown.Exit()
return nil
}
示例2: 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))
}
示例3: 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)))
}
示例4: 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))
}
示例5: main
func main() {
defer shutdown.Exit()
usage := `
usage: flynn-blobstore <command> [<args>...]
Commands:
help show usage for a specific command
cleanup delete file blobs from default backend
migrate move file blobs from default backend to a different backend
server run blobstore HTTP server
See 'flynn-blobstore help <command>' for more information on a specific command.
`[1:]
args, _ := docopt.Parse(usage, nil, true, version.String(), true)
cmd := args.String["<command>"]
cmdArgs := args.All["<args>"].([]string)
if cmd == "help" {
if len(cmdArgs) == 0 { // `flynn-blobstore help`
fmt.Println(usage)
return
} else { // `flynn-blobstore help <command>`
cmd = cmdArgs[0]
cmdArgs = []string{"--help"}
}
}
if err := runCommand(cmd, cmdArgs); err != nil {
log.Println(err)
shutdown.ExitWithCode(1)
}
}
示例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
/*
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)
}
}
示例8: 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()
}
示例9: 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()
}
示例10: main
func main() {
defer shutdown.Exit()
// Initialize main program and execute.
m := NewMain()
if err := m.Run(os.Args[1:]...); err != nil {
fmt.Fprintln(m.Stderr, err.Error())
os.Exit(1)
}
// Wait indefinitely.
<-(chan struct{})(nil)
}
示例11: main
func main() {
defer shutdown.Exit()
runner := &Runner{
bc: args.BootConfig,
events: make(chan Event),
networks: make(map[string]struct{}),
buildCh: make(chan struct{}, maxConcurrentBuilds),
clusters: make(map[string]*cluster.Cluster),
ircMsgs: make(chan string),
}
if err := runner.start(); err != nil {
shutdown.Fatal(err)
}
}
示例12: 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()
conf := ServerConfig{
SyslogAddr: *logAddr,
ApiAddr: *apiAddr,
Discoverd: discoverd.DefaultClient,
ServiceName: "logaggregator",
}
srv := NewServer(conf)
shutdown.BeforeExit(srv.Shutdown)
// get leader for snapshot (if any)
leader, err := conf.Discoverd.Service(conf.ServiceName).Leader()
if err == nil {
host, _, _ := net.SplitHostPort(leader.Addr)
log15.Info("loading snapshot from leader", "leader", host)
c, _ := client.New("http://" + host)
snapshot, err := c.GetSnapshot()
if err == nil {
if err := srv.LoadSnapshot(snapshot); err != nil {
log15.Error("error receiving snapshot from leader", "error", err)
}
snapshot.Close()
} else {
log15.Error("error getting snapshot from leader", "error", err)
}
} else {
log15.Info("error finding leader for snapshot", "error", err)
}
if err := srv.Start(); err != nil {
shutdown.Fatal(err)
}
<-make(chan struct{})
}
示例13: 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")
snapshotPath := flag.String("snapshot", "", "snapshot path")
flag.Parse()
a := NewAggregator(*logAddr)
if *snapshotPath != "" {
if err := a.ReplaySnapshot(*snapshotPath); err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() {
if err := a.TakeSnapshot(*snapshotPath); err != nil {
log15.Error("snapshot error", "err", err)
}
})
}
if err := a.Start(); err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(a.Shutdown)
listener, err := net.Listen("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)))
}
示例14: main
func main() {
defer shutdown.Exit()
flag.Parse()
addr := os.Getenv("PORT")
if addr == "" {
addr = *listenPort
}
addr = ":" + addr
var fs Filesystem
var storageDesc string
if *storageDir != "" {
fs = NewOSFilesystem(*storageDir)
storageDesc = *storageDir
} else {
var err error
db := postgres.Wait(nil, nil)
fs, err = NewPostgresFilesystem(db)
if err != nil {
shutdown.Fatal(err)
}
storageDesc = "Postgres"
}
if *serviceDiscovery {
hb, err := discoverd.AddServiceAndRegister("blobstore", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
}
log.Println("Blobstore serving files on " + addr + " from " + storageDesc)
mux := http.NewServeMux()
mux.Handle("/", handler(fs))
mux.Handle(status.Path, status.Handler(fs.Status))
h := httphelper.ContextInjector("blobstore", httphelper.NewRequestLogger(mux))
shutdown.Fatal(http.ListenAndServe(addr, h))
}
示例15: main
func main() {
defer shutdown.Exit()
flag.Parse()
addr := os.Getenv("PORT")
if addr == "" {
addr = *listenPort
}
addr = ":" + addr
var fs Filesystem
var storageDesc string
if *storageDir != "" {
fs = NewOSFilesystem(*storageDir)
storageDesc = *storageDir
} else {
db, err := postgres.Open("", "")
if err != nil {
shutdown.Fatal(err)
}
fs, err = NewPostgresFilesystem(db.DB)
if err != nil {
shutdown.Fatal(err)
}
storageDesc = "Postgres"
}
if *serviceDiscovery {
hb, err := discoverd.AddServiceAndRegister("blobstore", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
}
log.Println("Blobstore serving files on " + addr + " from " + storageDesc)
http.Handle("/", handler(fs))
status.AddHandler(fs.Status)
shutdown.Fatal(http.ListenAndServe(addr, nil))
}