Skip to content

Commit

Permalink
pass in the path to zpool as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
glessard committed Mar 23, 2021
1 parent b28476b commit fb1ce99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Sources/zfs-pool-importer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@ formatter.timeStyle = .long

let stdout = FileHandle.standardOutput

stdout.print("+zfs-pool-importer")
let command = ProcessInfo.processInfo.arguments.first?.split(separator: "/").last ?? "zfs_pool_importer"
let arguments = ProcessInfo.processInfo.arguments.dropFirst()
let sbin = arguments.first.flatMap {
arg in // elementary (and inflexible) parsing of a single possible command line option
var dir = ObjCBool(false)
guard arg.hasPrefix("--sbindir"),
let rawPath = arg.split(separator: "=").last.map(String.init),
FileManager.default.fileExists(atPath: rawPath, isDirectory: &dir),
dir.boolValue == true
else { return nil }
return URL(fileURLWithPath: rawPath, isDirectory: true).path.appending("/")
} ?? "/usr/local/zfs/bin/"

let zpool = sbin + "zpool"

stdout.print("+\(command)")
stdout.print(formatter.string(from: Date()))

formatter.dateStyle = .none
Expand Down Expand Up @@ -42,8 +57,7 @@ stdout.print("\(invariantDisksCookie) was\(found ? "" : "n't") found in \(String
Thread.sleep(forTimeInterval: 10)
stdout.print("\(formatter.string(from: Date())): running zpool import -a")

let code = launch(command: "/usr/local/zfs/bin/zpool",
arguments: ["import", "-a", "-d", "/var/run/disk/by-id"])
let code = launch(command: zpool, arguments: ["import", "-a", "-d", "/var/run/disk/by-id"])

stdout.print("\(formatter.string(from: Date())): zpool import returned with exit code \(code)")

Expand All @@ -62,6 +76,6 @@ catch {
formatter.dateStyle = .medium
formatter.timeStyle = .long
stdout.print(formatter.string(from: Date()))
stdout.print("-zfs-pool-importer")
stdout.print("-\(command)")

exit(code)
1 change: 1 addition & 0 deletions org.openzfsonosx.zfs-pool-importer.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<key>ProgramArguments</key>
<array>
<string>/usr/local/zfs/libexec/zfs/launchd.d/zfs-pool-importer</string>
<string>--sbindir=/usr/local/zfs/bin/</string>
</array>
<key>RunAtLoad</key>
<true/>
Expand Down

0 comments on commit fb1ce99

Please sign in to comment.