当前位置: 首页>>代码示例>>Golang>>正文


Golang gologit.Fatalf函数代码示例

本文整理汇总了Golang中github.com/cactus/gologit.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Fatalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LoadConfig

func LoadConfig(filepath string) {
	if _, err := os.Stat(filepath); os.IsNotExist(err) {
		gologit.Fatalf("%s not present or not readable", filepath)
	}

	buffer := &bytes.Buffer{}
	buffer.WriteString("[main]\n")
	f, err := os.Open(filepath)
	if err != nil {
		gologit.Printf("Error reading config file %s", filepath)
		gologit.Fatal(err)
	}
	defer f.Close()

	_, err = buffer.ReadFrom(f)
	if err != nil {
		gologit.Printf("Error reading config file %s", filepath)
		gologit.Fatal(err)
	}

	err = gcfg.ReadInto(&Config, buffer)
	if err != nil {
		gologit.Printf("Error parsing config file %s", filepath)
		gologit.Fatal(err)
	}
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:26,代码来源:config.go

示例2: setCmdRun

func setCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to set properties\n")
	}

	if len(args) < 2 {
		gologit.Fatalln("Improper usage")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	props, err := ParseProps(args[1:]...)
	if err != nil {
		gologit.Fatalln(err)
	}

	for _, prop := range props {
		prefix := ""
		if _, ok := CustomProperties[prop[0]]; ok {
			prefix = "org.freebsd.iocage:"
		}
		zfsArgs := []string{
			"set",
			fmt.Sprintf("%s%s=%s", prefix, prop[0], prop[1]),
			jail.Path,
		}
		core.ZFSMust(fmt.Errorf("Error setting property"), zfsArgs...)
	}
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:33,代码来源:cmd_set.go

示例3: releaseDestroyCmdRun

func releaseDestroyCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to destroy\n")
	}

	release, err := core.FindRelease(args[0])
	if err != nil {
		gologit.Fatalf("Release '%s' not found!\n", args[0])
	}

	fmt.Printf("Ready to remove release: %s\n", release.Name)
	if !force {
		fmt.Print("Are you sure [yN]? ")
		var response string
		_, err = fmt.Scanln(&response)
		if err != nil {
			if err.Error() == "unexpected newline" {
				os.Exit(0)
			}
			gologit.Fatalf("%s", err)
		}

		response = strings.ToLower(strings.TrimSpace(response))
		if len(response) != 1 || response[0] != 'y' {
			return
		}
	}

	fmt.Printf("Destroying: %s\n", release.Name)
	core.ZFSMust(
		fmt.Errorf("Error destroying release"),
		"destroy", "-fr", release.Path)
	os.RemoveAll(release.Mountpoint)
}
开发者ID:cactus,项目名称:rollcage,代码行数:35,代码来源:cmd_release.go

示例4: snapshotCmdRun

func snapshotCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to snapshot\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	var snapname string
	if len(args) > 1 {
		snapname = strings.TrimLeft(args[1], "@")
	} else {
		snapname = fmt.Sprintf(
			"ioc-%s", time.Now().Format("2006-01-02_15:04:05"))
	}

	zfsCmd := []string{"snapshot"}
	if recusiveSnapshot {
		zfsCmd = append(zfsCmd, "-r")
	}
	zfsCmd = append(zfsCmd, fmt.Sprintf("%s/[email protected]%s", jail.Path, snapname))
	core.ZFSMust(fmt.Errorf("Error removing snapshot"), zfsCmd...)
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:26,代码来源:cmd_snapshot.go

示例5: stopCmdRun

func stopCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to stop\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	if !jail.IsRunning() {
		gologit.Fatalf("Jail is not running!\n")
	}

	// create file
	f, err := os.OpenFile(jail.GetLogPath(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
	if err != nil {
		gologit.Fatal(err)
	}
	defer f.Close()

	fmt.Printf("* Stopping %s (%s)\n", jail.HostUUID, jail.Tag)
	fmt.Printf("  + Removing jail process\n")

	file, err := ioutil.TempFile(os.TempDir(), "rollcage.")
	defer os.Remove(file.Name())

	jailConfig := jail.JailConfig()
	gologit.Debugln(jailConfig)
	file.WriteString(jailConfig)
	file.Close()

	excmd := exec.Command(
		"/usr/sbin/jail",
		"-f", file.Name(),
		"-r", fmt.Sprintf("ioc-%s", jail.HostUUID))
	excmd.Stdout = f
	excmd.Stderr = f
	err = excmd.Run()
	if err != nil {
		gologit.Fatal(err)
	}

	// mostly for safety...
	fmt.Printf("  + Tearing down mounts\n")
	umountCmd("-afvF", path.Join(jail.Mountpoint, "fstab"))
	umountCmd(path.Join(jail.Mountpoint, "root/dev/fd"))
	umountCmd(path.Join(jail.Mountpoint, "root/dev"))
	umountCmd(path.Join(jail.Mountpoint, "root/proc"))

	// TODO: basejail here?
	// TODO: rctl stuff here...
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:54,代码来源:cmd_stop.go

示例6: snapremoveCmdRun

func snapremoveCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to snapremove\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	matchers := args[1:]
	gologit.Debugf("matchers: %#v\n", matchers)

	zfsArgs := []string{"list", "-Hrt", "snapshot",
		"-o", "name", "-d2", jail.Path}
	lines := core.SplitOutput(core.ZFSMust(
		fmt.Errorf("Error listing snapshots"),
		zfsArgs...))

	rmlist := []string{}
	for _, line := range lines {
		if len(line) == 0 || len(line[0]) == 0 {
			continue
		}
		snapname := strings.SplitN(line[0], "@", 2)[1]
		gologit.Debugf("source snapname: %#v\n", snapname)
		for _, m := range matchers {
			if snapremoveRegex {
				matched, err := regexp.MatchString(m, snapname)
				if err != nil {
					gologit.Fatalf("Regex error: %s", err)
				}
				if matched {
					rmlist = append(rmlist, line[0])
					continue
				}
			} else {
				if m == snapname {
					rmlist = append(rmlist, line[0])
					continue
				}
			}
		}
	}
	gologit.Debugf("match list: %#v\n", rmlist)

	for _, snap := range rmlist {
		fmt.Printf("Removing snapshot: %s\n", strings.SplitN(snap, "@", 2)[1])
		core.ZFSMust(
			fmt.Errorf("Error removing snapshot"),
			"destroy", "-r", snap)
	}
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:54,代码来源:cmd_snapremove.go

示例7: restartCmdRun

func restartCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to stop\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	if !jail.IsRunning() {
		gologit.Fatalf("Jail is not running!\n")
	}

	// create file
	f, err := os.OpenFile(jail.GetLogPath(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
	if err != nil {
		gologit.Fatal(err)
	}
	defer f.Close()

	props := jail.GetProperties()

	jexec := []string{fmt.Sprintf("ioc-%s", jail.HostUUID)}

	jexec_stop := append(jexec, core.SplitFieldsQuoteSafe(props.GetIOC("exec_stop"))...)
	excmd := exec.Command("/usr/sbin/jexec", jexec_stop...)
	excmd.Stdout = f
	excmd.Stderr = f
	err = excmd.Run()
	if err != nil {
		gologit.Printf("%s\n", err)
	}

	jexec_start := append(jexec, core.SplitFieldsQuoteSafe(props.GetIOC("exec_start"))...)
	excmd = exec.Command("/usr/sbin/jexec", jexec_start...)
	excmd.Stdout = f
	excmd.Stderr = f
	err = excmd.Run()
	if err != nil {
		gologit.Printf("%s\n", err)
	}

	// set last_started property
	t := time.Now()
	core.ZFSMust(
		fmt.Errorf("Error setting property"), "set",
		fmt.Sprintf(
			"org.freebsd.iocage:last_started=%s",
			t.Format("2006-01-02_15:04:05")),
		jail.Path)
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:53,代码来源:cmd_restart.go

示例8: execCmdRun

func execCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to use exec\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	if !jail.IsRunning() {
		gologit.Fatalf("Jail is not running!\n")
	}

	// get exec fib property
	lines := core.SplitOutput(core.ZFSMust(
		fmt.Errorf("Error listing jails"),
		"list", "-H",
		"-o", "org.freebsd.iocage:login_flags,org.freebsd.iocage:exec_fib",
		jail.Path))
	execFib := lines[0][1]

	jexec := []string{}
	if execFib != "0" {
		jexec = append(jexec, "/usr/sbin/setfib", execFib)
	}
	jexec = append(jexec, "/usr/sbin/jexec")
	if hostUser != "" {
		jexec = append(jexec, "-u", hostUser)
	}
	if jailUser != "" {
		jexec = append(jexec, "-U", jailUser)
	}
	jexec = append(jexec, fmt.Sprintf("ioc-%s", jail.HostUUID))
	jexec = append(jexec, args[1:]...)

	// set a default path
	environ := []string{
		"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
	}
	// set a term from caller
	environ = append(environ, fmt.Sprintf("TERM=%s", os.Getenv("TERM")))

	gologit.Debugf("%#s\n", jexec)
	execErr := syscall.Exec(jexec[0], jexec, environ)
	if execErr != nil {
		gologit.Fatal(execErr)
	}
}
开发者ID:cactus,项目名称:rollcage,代码行数:50,代码来源:cmd_exec.go

示例9: rollbackCmdRun

func rollbackCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to rollback\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	snapname := strings.TrimLeft(args[1], "@")

	// get FS's
	lines := core.SplitOutput(core.ZFSMust(
		fmt.Errorf("Error listing jails"),
		"list", "-Hr", "-o", "name", path.Join(jail.Path, "root")))
	if len(lines) < 1 {
		gologit.Fatalf("No datasets at jailpath!\n")
	}

	snapshots := []string{}
	for _, line := range lines {
		out := core.ZFSMust(
			fmt.Errorf("Error listing snapshots"),
			"list", "-Ht", "snapshot", "-o", "name", "-d1",
			fmt.Sprintf("%[email protected]%s", line[0], snapname))
		if len(out) != 0 {
			snapshots = append(snapshots, out)
		}
	}

	if len(snapshots) == 0 {
		gologit.Fatalln("Snapshot '%s' not found!", snapname)
	}

	for _, snapshot := range snapshots {
		i := strings.LastIndex(snapshot, "@")
		elemName := snapshot[:i]
		j := strings.LastIndex(snapshot, "/")
		elemName = elemName[j:]
		fmt.Printf("* Rolling back jail dataset '%s' to '@%s'\n",
			elemName, snapname)
		core.ZFSMust(
			fmt.Errorf("Error rolling back jail"),
			"rollback", "-r", snapshot)
	}
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:48,代码来源:cmd_rollback.go

示例10: runtimeCmdRun

func runtimeCmdRun(cmd *cobra.Command, args []string) {
	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	out, err := core.Jls("-n", "-j", fmt.Sprintf("ioc-%s", jail.HostUUID))
	if err != nil {
		gologit.Fatalf("Jail is not running!\n")
	}

	lines := strings.Split(out, " ")
	for _, line := range lines {
		fmt.Fprintf(os.Stdout, "%s\n", line)
	}
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:16,代码来源:cmd_runtime.go

示例11: CmdMust

func CmdMust(errmsg error, name string, arg ...string) string {
	out, err := Cmd(name, arg...)
	if err != nil {
		gologit.Fatalf("Error: %s\n", errmsg)
	}
	return out
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:7,代码来源:zfs.go

示例12: dfCmdRun

func dfCmdRun(cmd *cobra.Command, args []string) {
	propertyList := "org.freebsd.iocage:host_hostuuid," +
		"org.freebsd.iocage:tag,compressratio,reservation," +
		"quota,used,available"
	outputHeaders := []string{"uuid", "tag", "crt", "res", "qta", "use", "ava"}

	zfsArgs := []string{"list", "-H", "-o", propertyList}
	if ParsableValues {
		zfsArgs = append(zfsArgs, "-p")
	}
	if len(args) == 0 {
		zfsArgs = append(zfsArgs, "-d", "1", core.GetJailsPath())
	} else {
		jail, err := core.FindJail(args[0])
		if err != nil {
			gologit.Fatalf("No jail found by '%s'\n", args[0])
		}
		zfsArgs = append(zfsArgs, jail.Path)
	}
	out := core.ZFSMust(fmt.Errorf("Error listing jails"), zfsArgs...)
	lines := strings.Split(out, "\n")
	wf := core.NewOutputWriter(outputHeaders, MachineOutput)
	for _, line := range lines {
		if strings.HasPrefix(line, "-") {
			continue
		}
		fmt.Fprintf(wf, "%s\n", line)
	}
	wf.Flush()
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:30,代码来源:cmd_df.go

示例13: snaplistCmdRun

func snaplistCmdRun(cmd *cobra.Command, args []string) {
	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	zfsArgs := []string{"list", "-Hrt", "snapshot",
		"-o", "name,creation,used,referenced", "-d2"}
	if ParsableValues {
		zfsArgs = append(zfsArgs, "-p")
	}
	zfsArgs = append(zfsArgs, jail.Path)

	lines := core.SplitOutput(core.ZFSMust(
		fmt.Errorf("Error listing snapshots"),
		zfsArgs...))
	gologit.Debugf("%#v", lines)
	if len(lines) == 0 || len(lines[0]) == 0 || len(lines[0][0]) == 0 {
		return
	}

	var rxmatch *regexp.Regexp
	if snaplistRegex != "" {
		rxmatch, err = regexp.Compile(snaplistRegex)
		if err != nil {
			gologit.Fatalf("Bad regex: %s", err)
		}
	}

	outputHeaders := []string{"name", "created", "rsize", "used"}
	wf := core.NewOutputWriter(outputHeaders, MachineOutput)
	for _, line := range lines {
		if len(line) < 4 {
			continue
		}

		snapname := strings.SplitN(line[0], "@", 2)[1]

		if rxmatch != nil && !rxmatch.MatchString(snapname) {
			continue
		}
		fmt.Fprintf(wf, "%s\t%s\t%s\t%s\n", snapname, line[1], line[2], line[3])
	}
	wf.Flush()
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:45,代码来源:cmd_snaplist.go

示例14: rebootCmdRun

func rebootCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to stop\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}

	if !jail.IsRunning() {
		gologit.Fatalf("Jail is not running!\n")
	}

	stopCmdRun(cmd, args)
	startCmdRun(cmd, args)
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:18,代码来源:cmd_reboot.go

示例15: chrootCmdRun

func chrootCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to chroot\n")
	}

	jail, err := core.FindJail(args[0])
	if err != nil {
		gologit.Fatalf("No jail found by '%s'\n", args[0])
	}
	propertyOut := core.ZFSMust(
		fmt.Errorf("Error getting properties"),
		"get", "-H", "-o", "value", "mountpoint", jail.Path)

	chrootArgs := []string{
		"/usr/sbin/chroot",
		path.Join(propertyOut, "root"),
	}

	if len(args) > 1 {
		chrootArgs = append(chrootArgs, args[1:]...)
	} else {
		shell := os.Getenv("SHELL")
		if shell == "" {
			shell = "/bin/sh"
		}
		chrootArgs = append(chrootArgs, shell)
	}

	// set a default path
	environ := []string{
		"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
	}
	// set a term from caller
	environ = append(environ, fmt.Sprintf("TERM=%s", os.Getenv("TERM")))

	execErr := syscall.Exec(chrootArgs[0], chrootArgs, environ)
	if execErr != nil {
		gologit.Fatal(execErr)
	}
}
开发者ID:MichaelAronsen,项目名称:rollcage,代码行数:41,代码来源:cmd_chroot.go


注:本文中的github.com/cactus/gologit.Fatalf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。