Skip to content

Commit f7ad02d

Browse files
authored
Merge pull request #133 from jp39/run-on-zfs-host
Add ability to run the provisioner directly on the ZFS host.
2 parents 5884d5b + f5f9732 commit f7ad02d

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

docker/update-permissions.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ set -eo pipefail
55
zfs_mod="${ZFS_MOD:-g+w}"
66
chmod_bin=${ZFS_CHOWN_BIN:-sudo -H chmod}
77

8-
zfs_host="${1}"
9-
zfs_mountpoint="${2}"
8+
zfs_mountpoint="${1}"
9+
10+
# Do not try to manually modify these Env vars, they will be updated by the provisioner just before invoking the script.
11+
zfs_host="${ZFS_HOST}"
1012

1113
ssh "${zfs_host}" "${chmod_bin} ${zfs_mod} ${zfs_mountpoint}"

pkg/zfs/zfs.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8+
"path/filepath"
89
"sync"
910

1011
gozfs "github.com/mistifyio/go-zfs/v3"
@@ -114,11 +115,32 @@ func (z *zfsImpl) SetPermissions(dataset *Dataset) error {
114115
if dataset.Mountpoint == "" {
115116
return fmt.Errorf("undefined mountpoint for dataset: %s", dataset.Name)
116117
}
117-
cmd := exec.Command("update-permissions", dataset.Hostname, dataset.Mountpoint)
118-
out, err := cmd.CombinedOutput()
118+
119+
globalLock.Lock()
120+
defer globalLock.Unlock()
121+
if err := setEnvironmentVars(dataset.Hostname); err != nil {
122+
return err
123+
}
124+
cmd := exec.Command("update-permissions", dataset.Mountpoint)
125+
if filepath.IsAbs(cmd.Path) {
126+
out, err := cmd.CombinedOutput()
127+
if err != nil {
128+
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
129+
}
130+
return nil
131+
}
132+
133+
// update-permissions executable not found in PATH
134+
st, err := os.Lstat(dataset.Mountpoint)
119135
if err != nil {
120-
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
136+
return err
121137
}
138+
139+
// Add group write bit
140+
if err := os.Chmod(dataset.Mountpoint, st.Mode()|0o020); err != nil {
141+
return err
142+
}
143+
122144
return nil
123145
}
124146

test/update-permissions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ set -eo pipefail
55
zfs_mod="${ZFS_MOD:-g+w}"
66
chmod_bin=${ZFS_CHOWN_BIN:-chmod}
77

8-
zfs_mountpoint="${2}"
8+
zfs_mountpoint="${1}"
99

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

0 commit comments

Comments
 (0)