Skip to content

Commit

Permalink
Merge pull request #133 from jp39/run-on-zfs-host
Browse files Browse the repository at this point in the history
Add ability to run the provisioner directly on the ZFS host.
  • Loading branch information
ccremer authored Sep 11, 2024
2 parents 5884d5b + f5f9732 commit f7ad02d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docker/update-permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set -eo pipefail
zfs_mod="${ZFS_MOD:-g+w}"
chmod_bin=${ZFS_CHOWN_BIN:-sudo -H chmod}

zfs_host="${1}"
zfs_mountpoint="${2}"
zfs_mountpoint="${1}"

# Do not try to manually modify these Env vars, they will be updated by the provisioner just before invoking the script.
zfs_host="${ZFS_HOST}"

ssh "${zfs_host}" "${chmod_bin} ${zfs_mod} ${zfs_mountpoint}"
28 changes: 25 additions & 3 deletions pkg/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"

gozfs "github.com/mistifyio/go-zfs/v3"
Expand Down Expand Up @@ -114,11 +115,32 @@ func (z *zfsImpl) SetPermissions(dataset *Dataset) error {
if dataset.Mountpoint == "" {
return fmt.Errorf("undefined mountpoint for dataset: %s", dataset.Name)
}
cmd := exec.Command("update-permissions", dataset.Hostname, dataset.Mountpoint)
out, err := cmd.CombinedOutput()

globalLock.Lock()
defer globalLock.Unlock()
if err := setEnvironmentVars(dataset.Hostname); err != nil {
return err
}
cmd := exec.Command("update-permissions", dataset.Mountpoint)
if filepath.IsAbs(cmd.Path) {
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
}
return nil
}

// update-permissions executable not found in PATH
st, err := os.Lstat(dataset.Mountpoint)
if err != nil {
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
return err
}

// Add group write bit
if err := os.Chmod(dataset.Mountpoint, st.Mode()|0o020); err != nil {
return err
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/update-permissions
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -eo pipefail
zfs_mod="${ZFS_MOD:-g+w}"
chmod_bin=${ZFS_CHOWN_BIN:-chmod}

zfs_mountpoint="${2}"
zfs_mountpoint="${1}"

${chmod_bin} ${zfs_mod} ${zfs_mountpoint}

0 comments on commit f7ad02d

Please sign in to comment.