當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。