Example #1
0
func (fs *FS) CreateFile(anchor string, owner circuit.Addr) error {
	// Probably should save addr using durable-like techniques
	var w bytes.Buffer
	if err := gob.NewEncoder(&w).Encode(&ZFile{owner}); err != nil {
		panic(err)
	}

	parts, _, err := anchorfs.Sanitize(anchor)
	if err != nil {
		return err
	}
	_anchor := path.Join(append([]string{fs.root}, parts...)...)
	println(_anchor)
	if err = zutil.CreateRecursive(fs.zookeeper, _anchor, zutil.PermitAll); err != nil {
		return err
	}

	_, err = fs.zookeeper.Create(
		path.Join(_anchor, owner.WorkerID().String()),
		string(w.Bytes()),
		zookeeper.EPHEMERAL,
		zutil.PermitAll,
	)
	if err != nil {
		return err
	}

	fs.Lock()
	defer fs.Unlock()
	fs.created[anchor] = struct{}{}

	return nil
}
Example #2
0
func tailViaSSH(addr circuit.Addr, jailpath string) {

	abs := path.Join(config.Config.Install.JailDir(), addr.WorkerID().String(), jailpath)

	cmd := exec.Command("ssh", addr.Host(), "tail -f "+abs)

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		println("Pipe problem:", err.Error())
		os.Exit(1)
	}

	if err = cmd.Start(); err != nil {
		println("Exec problem:", err.Error())
		os.Exit(1)
	}

	io.Copy(os.Stdout, stdout)
}