本文整理汇总了Golang中github.com/litl/galaxy/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
示例2: 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)
}
示例3: 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)
}
示例4: cfgDir
// Return the path for the config directory, and create it if it doesn't exist
func cfgDir() string {
homeDir := utils.HomeDir()
if homeDir == "" {
log.Fatal("ERROR: Unable to determine current home dir. Set $HOME.")
}
configDir := filepath.Join(homeDir, ".galaxy")
_, err := os.Stat(configDir)
if err != nil && os.IsNotExist(err) {
err = os.Mkdir(configDir, 0700)
if err != nil {
log.Fatal("ERROR: cannot create config directory:", err)
}
}
return configDir
}
示例5: DefaultGalaxyTemplate
// Return a default template to create our base stack.
func DefaultGalaxyTemplate() []byte {
azResp, err := DescribeAvailabilityZones("")
if err != nil {
log.Warn(err)
return nil
}
p := &GalaxyTmplParams{
Name: "galaxy",
VPCCIDR: "10.24.0.1/16",
}
for i, az := range azResp.AvailabilityZones {
s := &SubnetTmplParams{
Name: fmt.Sprintf("galaxySubnet%d", i+1),
Subnet: fmt.Sprintf("10.24.%d.0/24", i+1),
AZ: az.Name,
}
p.Subnets = append(p.Subnets, s)
}
tmpl, err := GalaxyTemplate(p)
if err != nil {
// TODO
log.Fatal(err)
}
return tmpl
}
示例6: 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)
}
}
示例7: 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
}
示例8: stackInit
// create our base stack
func stackInit(c *cli.Context) {
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
exists, err := stack.Exists(stackName)
if exists {
log.Fatalf("ERROR: stack %s already exists", stackName)
} else if err != nil {
fmt.Println("EXISTS ERROR")
log.Fatal(err)
}
params := getInitOpts(c)
stackTmpl, err := stack.GalaxyTemplate(params)
if err != nil {
log.Fatalf("ERROR: %s", err)
}
if c.Bool("print") {
fmt.Println(string(stackTmpl))
return
}
opts := make(map[string]string)
opts["tag.galaxy"] = "base"
_, err = stack.Create(stackName, stackTmpl, opts)
if err != nil {
log.Fatalf("ERROR: %s", err)
}
log.Println("Initializing stack", stackName)
}
示例9: stackListEvents
// List recent events for a stack
// Shows up to 20 events, or 24 hours of events.
func stackListEvents(c *cli.Context) {
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
resp, err := stack.DescribeStackEvents(stackName)
if err != nil {
log.Fatal(err)
}
if len(resp.Events) == 0 {
log.Println("no events for", stackName)
return
}
firstTS := resp.Events[0].Timestamp.Add(-24 * time.Hour)
lines := []string{"TIMESTAMP | Logical ID | STATUS | REASON"}
format := "%s | %s | %s | %s"
for i, e := range resp.Events {
if i > 20 || e.Timestamp.Before(firstTS) {
break
}
displayTime := e.Timestamp.Format(time.Stamp)
line := fmt.Sprintf(format, displayTime, e.LogicalResourceId, e.ResourceStatus, e.ResourceStatusReason)
lines = append(lines, line)
}
output, _ := columnize.SimpleFormat(lines)
log.Println(output)
}
示例10: stackDelete
// delete a pool
func stackDelete(c *cli.Context) {
stackName := c.Args().First()
if stackName == "" {
log.Fatal("ERROR: stack name required")
}
ok := c.Bool("y")
if !ok {
switch strings.ToLower(promptValue(fmt.Sprintf("\nDelete Stack '%s'?", stackName), "n")) {
case "y", "yes":
ok = true
}
}
if !ok {
log.Fatal("aborted")
}
if c.String("region") != "" {
stack.Region = c.String("region")
}
waitAndDelete(stackName)
}
示例11: appCreate
func appCreate(c *cli.Context) {
ensureEnvArg(c)
initStore(c)
app := c.Args().First()
if app == "" {
cli.ShowCommandHelp(c, "app:create")
log.Fatal("ERROR: app name missing")
}
err := commander.AppCreate(configStore, app, utils.GalaxyEnv(c))
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
示例12: poolUnassign
func poolUnassign(c *cli.Context) {
ensureEnvArg(c)
ensurePoolArg(c)
initStore(c)
app := c.Args().First()
if app == "" {
cli.ShowCommandHelp(c, "pool:assign")
log.Fatal("ERROR: app name missing")
}
err := commander.AppUnassign(configStore, app, utils.GalaxyEnv(c), utils.GalaxyPool(c))
if err != nil {
log.Fatalf("ERROR: %s", err)
}
}
示例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: setCPUAutoScale
// seto autoscaling options for a pool
func setCPUAutoScale(c *cli.Context, pool *stack.Pool) {
scaleAdj := c.Int("scale-adj")
scaleUpDel := c.Int("scale-up-delay")
scaleDownDel := c.Int("scale-down-delay")
scaleUpCPU := c.Int("scale-up-cpu")
scaleDownCPU := c.Int("scale-down-cpu")
asgName := pool.ASG().Name
if asgName == "" {
log.Fatal("Error: missing ASG Name")
}
// Any options set to 0 will use template defaults.
// Don't autoscale if no options are set.
if scaleAdj != 0 || scaleUpDel != 0 || scaleDownDel != 0 || scaleUpCPU != 0 || scaleDownCPU != 0 {
pool.SetCPUAutoScaling(asgName, scaleAdj, scaleUpCPU, scaleUpDel, scaleDownCPU, scaleDownDel)
}
}
示例15: SSHCmd
func SSHCmd(host string, command string, background bool, debug bool) {
port := "22"
hostPort := strings.SplitN(host, ":", 2)
if len(hostPort) > 1 {
host, port = hostPort[0], hostPort[1]
}
cmd := exec.Command("/usr/bin/ssh",
"-o", "RequestTTY=yes",
host,
"-p", port,
"-C", "/bin/sh", "-i", "-l", "-c", "'"+command+"'")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
var b []byte
buf := bytes.NewBuffer(b)
cmd.Stderr = buf
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
if err := cmd.Wait(); err != nil {
log.Error(buf.String())
if exiterr, ok := err.(*exec.ExitError); ok {
// The program has exited with an exit code != 0
// This works on both Unix and Windows. Although package
// syscall is generally platform dependent, WaitStatus is
// defined for both Unix and Windows and in both cases has
// an ExitStatus() method with the same signature.
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
fmt.Fprintf(os.Stderr, "Command finished with error: %v\n", err)
os.Exit(status.ExitStatus())
}
} else {
fmt.Fprintf(os.Stderr, "Command finished with error: %v\n", err)
os.Exit(1)
}
}
}