Beispiel #1
0
func runDeviceinit(cmd *Command, args []string) {
	// verify flags
	if len(*deviceinitNodebase) == 0 {
		fmt.Fprintf(os.Stderr, "Invalid params.\n")
		os.Exit(1)
	}

	if len(*deviceinitDevice) == 0 {
		fmt.Fprintf(os.Stderr, "Invalid params.\n")
		os.Exit(1)
	}

	// verify deviceinitNodebase
	devicePath := path.Join(*deviceinitNodebase, swarm.DEVICES_DIR, *deviceinitDevice)
	if !swarm.ExistPath(devicePath) {
		fmt.Fprintf(os.Stderr, "Error: device path %s not exists\n", devicePath)
		os.Exit(1)
	}
	uuidPath := path.Join(devicePath, swarm.UUID_FILE)
	if swarm.ExistPath(uuidPath) {
		fmt.Fprintf(os.Stderr, "Error: uuid file %s exists already\n", uuidPath)
		os.Exit(1)
	}

	// prepare dirs
	blocksPath := path.Join(devicePath, swarm.BLOCKS_DIR)
	err := os.MkdirAll(blocksPath, 0755)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed make dir %s, error: %s.\n", blocksPath, err)
		os.Exit(1)
	}

	// prepare uuid
	f, err := swarm.CreateFile(uuidPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed create file %s, error: %s.\n", uuidPath, err)
		os.Exit(1)
	}
	defer f.Close()
	f.Write([]byte(swarm.Uuid()))
}
Beispiel #2
0
func runServe(cmd *Command, args []string) {
	// verify flags
	if len(*serveNodebase) == 0 {
		fmt.Fprintf(os.Stderr, "Invalid params.\n")
		os.Exit(1)
	}

	// verify serveNodebase
	if !swarm.ExistPath(*serveNodebase) {
		fmt.Fprintf(os.Stderr, "Path %s not exists.\n", *serveNodebase)
		os.Exit(1)
	}

	// set NODE_BASE_PATH
	swarm.NODE_BASE_PATH = *serveNodebase

	swarm.Start()

}