本文整理汇总了Golang中github.com/litl/galaxy/log.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewStore
func NewStore(ttl uint64, registryURL string) *Store {
s := &Store{
TTL: ttl,
pollCh: make(chan bool),
restartChan: make(chan *ConfigChange, 10),
}
u, err := url.Parse(registryURL)
if err != nil {
log.Fatalf("ERROR: Unable to parse %s", err)
}
switch strings.ToLower(u.Scheme) {
case "redis":
s.Backend = &RedisBackend{
RedisHost: u.Host,
}
s.Backend.connect()
case "consul":
s.Backend = NewConsulBackend()
default:
log.Fatalf("ERROR: Unsupported registry backend: %s", u)
}
return s
}
示例2: initOrDie
func initOrDie() {
if registryURL == "" {
log.Fatalf("ERROR: Registry URL not specified. Use '-registry redis://127.0.0.1:6379' or set 'GALAXY_REGISTRY_URL'")
}
configStore = config.NewStore(config.DefaultTTL, registryURL)
serviceRuntime = runtime.NewServiceRuntime(configStore, dns, hostIP)
apps, err := configStore.ListAssignments(env, pool)
if err != nil {
log.Fatalf("ERROR: Could not retrieve service configs for /%s/%s: %s", env, pool, err)
}
workerChans = make(map[string]chan string)
for _, app := range apps {
appCfg, err := configStore.GetApp(app, env)
if err != nil {
log.Fatalf("ERROR: Could not retrieve service config for /%s/%s: %s", env, pool, err)
}
workerChans[appCfg.Name()] = make(chan string)
}
signalsChan = make(chan os.Signal, 1)
signal.Notify(signalsChan, os.Interrupt, os.Kill, syscall.SIGTERM)
go deregisterHost(signalsChan)
}
示例3: NewServiceRuntime
func NewServiceRuntime(configStore *config.Store, dns, hostIP string) *ServiceRuntime {
var err error
var client *docker.Client
dockerZero, err := dockerBridgeIp()
if err != nil {
log.Fatalf("ERROR: Unable to find docker0 bridge: %s", err)
}
endpoint := GetEndpoint()
if certPath := os.Getenv("DOCKER_CERT_PATH"); certPath != "" {
cert := certPath + "/cert.pem"
key := certPath + "/key.pem"
ca := certPath + "/ca.pem"
client, err = docker.NewTLSClient(endpoint, cert, key, ca)
} else {
client, err = docker.NewClient(endpoint)
}
if err != nil {
log.Fatalf("ERROR: Unable to initialize docker client: %s: %s", err, endpoint)
}
client.HTTPClient.Timeout = 60 * time.Second
return &ServiceRuntime{
dns: dns,
configStore: configStore,
hostIP: hostIP,
dockerIP: dockerZero,
dockerClient: client,
}
}
示例4: ensureEnv
func ensureEnv() {
envs, err := configStore.ListEnvs()
if err != nil {
log.Fatalf("ERROR: Could not check envs: %s", err)
}
if strings.TrimSpace(env) == "" {
log.Fatalf("ERROR: Need an env. Use '-env <env>'. Existing envs are: %s.", strings.Join(envs, ","))
}
}
示例5: ensurePool
func ensurePool() {
pools, err := configStore.ListPools(env)
if err != nil {
log.Fatalf("ERROR: Could not check pools: %s", err)
}
if strings.TrimSpace(pool) == "" {
log.Fatalf("ERROR: Need a pool. Use '-pool <pool>'. Existing pools are: %s", strings.Join(pools, ","))
}
}
示例6: waitAndDelete
// wait until a stack is in a final state, then delete it
func waitAndDelete(name string) {
log.Println("Attempting to delete stack:", name)
// we need to get the StackID in order to lookup DELETE events
desc, err := stack.DescribeStacks(name)
if err != nil {
log.Fatalf("ERROR: %s", err)
} else if len(desc.Stacks) == 0 {
log.Fatal("ERROR: could not describe stack:", name)
}
stackId := desc.Stacks[0].Id
err = stack.WaitForComplete(stackId, 5*time.Minute)
if err != nil {
log.Fatal(err)
}
_, err = stack.Delete(name)
if err != nil {
log.Fatal(err)
}
// wait
err = stack.WaitForComplete(stackId, 5*time.Minute)
if err != nil {
log.Fatal(err)
}
log.Println("Deleted stack:", name)
}
示例7: stackTemplate
// Print a Cloudformation template to stdout.
func stackTemplate(c *cli.Context) {
stackName := c.Args().First()
if c.String("region") != "" {
stack.Region = c.String("region")
}
if stackName == "" {
os.Stdout.Write(stack.DefaultGalaxyTemplate())
return
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
stackTmpl, err := stack.GetTemplate(stackName)
if err != nil {
if err, ok := err.(*aws.Error); ok {
if err.Code == "ValidationError" && strings.Contains(err.Message, "does not exist") {
log.Fatalf("ERROR: Stack '%s' does not exist", stackName)
}
}
log.Fatal(err)
}
if _, err := os.Stdout.Write(stackTmpl); err != nil {
log.Fatal(err)
}
}
示例8: poolCreate
func poolCreate(c *cli.Context) {
ensureEnvArg(c)
ensurePoolArg(c)
initStore(c)
created, err := configStore.CreatePool(utils.GalaxyPool(c), utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: Could not create pool: %s", err)
return
}
if created {
log.Printf("Pool %s created\n", utils.GalaxyPool(c))
} else {
log.Printf("Pool %s already exists\n", utils.GalaxyPool(c))
}
ec2host, err := runtime.EC2PublicHostname()
if err != nil || ec2host == "" {
log.Debug("not running from AWS, skipping pool creation")
return
}
// now create the cloudformation stack
// is this fails, the stack can be created separately with
// stack:create_pool
stackCreatePool(c)
}
示例9: appList
func appList(c *cli.Context) {
initStore(c)
err := commander.AppList(configStore, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
示例10: appRun
func appRun(c *cli.Context) {
ensureEnvArg(c)
initStore(c)
initRuntime(c)
app := ensureAppParam(c, "app:run")
if len(c.Args()) < 2 {
log.Fatalf("ERROR: Missing command to run.")
return
}
err := commander.AppRun(configStore, serviceRuntime, app, utils.GalaxyEnv(c), c.Args()[1:])
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
示例11: poolList
func poolList(c *cli.Context) {
initStore(c)
envs := []string{utils.GalaxyEnv(c)}
if utils.GalaxyEnv(c) == "" {
var err error
envs, err = configStore.ListEnvs()
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
columns := []string{"ENV | POOL | APPS "}
for _, env := range envs {
pools, err := configStore.ListPools(env)
if err != nil {
log.Fatalf("ERROR: cannot list pools: %s", err)
return
}
if len(pools) == 0 {
columns = append(columns, strings.Join([]string{
env,
"",
""}, " | "))
continue
}
for _, pool := range pools {
assigments, err := configStore.ListAssignments(env, pool)
if err != nil {
log.Fatalf("ERROR: cannot list pool assignments: %s", err)
}
columns = append(columns, strings.Join([]string{
env,
pool,
strings.Join(assigments, ",")}, " | "))
}
}
output := columnize.SimpleFormat(columns)
log.Println(output)
}
示例12: appBackup
// Backup app config to a file or STDOUT
func appBackup(c *cli.Context) {
initStore(c)
env := utils.GalaxyEnv(c)
if env == "" {
log.Fatal("ERROR: env is required. Pass --env or set GALAXY_ENV")
}
backup := &backupData{
Time: time.Now(),
}
toBackup := c.Args()
if len(toBackup) == 0 {
appList, err := configStore.ListApps(env)
if err != nil {
log.Fatalf("ERROR: %s\n", err)
}
for _, app := range appList {
toBackup = append(toBackup, app.Name())
}
}
errCount := 0
for _, app := range toBackup {
data, err := getAppBackup(app, env)
if err != nil {
// log errors and continue
log.Errorf("ERROR: %s [%s]", err, app)
errCount++
continue
}
backup.Apps = append(backup.Apps, data)
}
if errCount > 0 {
fmt.Printf("WARNING: backup completed with %d errors\n", errCount)
defer os.Exit(errCount)
}
j, err := json.MarshalIndent(backup, "", " ")
if err != nil {
log.Fatal(err)
}
fileName := c.String("file")
if fileName != "" {
if err := ioutil.WriteFile(fileName, j, 0666); err != nil {
log.Fatal(err)
}
return
}
os.Stdout.Write(j)
}
示例13: ensureAppParam
func ensureAppParam(c *cli.Context, command string) string {
app := c.Args().First()
if app == "" {
cli.ShowCommandHelp(c, command)
log.Fatal("ERROR: app name missing")
}
exists, err := appExists(app, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: can't deteremine if %s exists: %s", app, err)
}
if !exists {
log.Fatalf("ERROR: %s does not exist. Create it first.", app)
}
return app
}
示例14: getBase
// return --base, or try to find a base cloudformation stack
func getBase(c *cli.Context) string {
errNoBase := fmt.Errorf("could not identify a unique base stack")
base := c.String("base")
if base != "" {
return base
}
descResp, err := stack.DescribeStacks("")
if err != nil {
log.Fatal(err)
}
for _, stack := range descResp.Stacks {
// first check for galaxy:base tag
baseTag := false
for _, t := range stack.Tags {
if t.Key == "galaxy" && t.Value == "base" {
baseTag = true
}
}
if baseTag {
if base != "" {
err = errNoBase
}
base = stack.Name
continue
}
parts := strings.Split(stack.Name, "-")
// check for "-base" in the name
if parts[len(parts)-1] == "base" {
if base != "" {
err = errNoBase
}
base = stack.Name
continue
}
// the best we can do for now is look for a stack with a single word
if len(parts) == 1 {
if base != "" {
err = errNoBase
}
base = stack.Name
log.Printf("Warning: guessing base stack: %s", base)
}
}
if err != nil {
log.Fatalf("%s: %s", err, "use --base")
}
return base
}
示例15: pgPsql
func pgPsql(c *cli.Context) {
ensureEnvArg(c)
initStore(c)
app := ensureAppParam(c, "pg:psql")
appCfg, err := configStore.GetApp(app, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: Unable to run command: %s.", err)
return
}
database_url := appCfg.Env()["DATABASE_URL"]
if database_url == "" {
log.Printf("No DATABASE_URL configured. Set one with config:set first.")
return
}
if !strings.HasPrefix(database_url, "postgres://") {
log.Printf("DATABASE_URL is not a postgres database.")
return
}
cmd := exec.Command("psql", database_url)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// Ignore SIGINT while the process is running
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
defer func() {
signal.Stop(ch)
close(ch)
}()
go func() {
for {
_, ok := <-ch
if !ok {
break
}
}
}()
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v\n", err)
}
}