fix(monitor): preserve literal daemon arguments (#32)
Preserve the monitor script path in launchd arguments
This commit is contained in:
+3
-7
@@ -4,11 +4,7 @@ install_monitor_launchdaemon() {
|
|||||||
[ -n "$data_mount" ] && root="$data_mount"
|
[ -n "$data_mount" ] && root="$data_mount"
|
||||||
|
|
||||||
local unleash_src
|
local unleash_src
|
||||||
if [ -n "$SCRIPT_DIR" ]; then
|
unleash_src=$(_launchd_script_path)
|
||||||
unleash_src="$SCRIPT_DIR/unleash"
|
|
||||||
else
|
|
||||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
step "Installing monitor LaunchDaemon..."
|
step "Installing monitor LaunchDaemon..."
|
||||||
|
|
||||||
@@ -26,8 +22,8 @@ install_monitor_launchdaemon() {
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</string>
|
<string>${unleash_src}</string>
|
||||||
<string>${unleash_src} monitor</string>
|
<string>monitor</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
load '../lib/colors.sh'
|
load '../lib/colors.sh'
|
||||||
|
load '../lib/launchd.sh'
|
||||||
load '../lib/monitor.sh'
|
load '../lib/monitor.sh'
|
||||||
TEST_DIR=$(mktemp -d)
|
TEST_DIR=$(mktemp -d)
|
||||||
|
SCRIPT_PATH="$TEST_DIR/unleash"
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
@test "persistence invokes renamed scripts with spaces and XML text literally" {
|
check_daemon_path() {
|
||||||
|
local installer="$1" action="$2" label="$3"
|
||||||
local entrypoint
|
local entrypoint
|
||||||
for entrypoint in unleash unleash-standalone.sh; do
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
local folder="$BATS_TEST_TMPDIR/$entrypoint/Tool Folder & <profile> \"quoted\""
|
local folder="$BATS_TEST_TMPDIR/$entrypoint/Tool Folder & <profile> \"quoted\""
|
||||||
@@ -21,19 +22,27 @@
|
|||||||
[ "$#" -eq 2 ] && [ "$1" = -p ] && [ "$2" = "$expected" ] || return 97
|
[ "$#" -eq 2 ] && [ "$1" = -p ] && [ "$2" = "$expected" ] || return 97
|
||||||
command mkdir "$@"
|
command mkdir "$@"
|
||||||
}
|
}
|
||||||
install_persist_launchdaemon "$2"
|
"$3" "$2"
|
||||||
' "$script" "$definitions" "$target"
|
' "$script" "$definitions" "$target" "$installer"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
run python3 - "$target/Library/LaunchDaemons/com.unleash.heal.plist" "$script" <<'PY'
|
run python3 - "$target/Library/LaunchDaemons/$label.plist" "$script" "$action" <<'PY'
|
||||||
import plistlib,subprocess,sys
|
import plistlib,subprocess,sys
|
||||||
with open(sys.argv[1],'rb') as source:
|
with open(sys.argv[1],'rb') as source:
|
||||||
data=plistlib.load(source)
|
data=plistlib.load(source)
|
||||||
expected=['/bin/bash',sys.argv[2],'heal']
|
expected=['/bin/bash',sys.argv[2],sys.argv[3]]
|
||||||
assert data['ProgramArguments']==expected, data['ProgramArguments']
|
assert data['ProgramArguments']==expected, data['ProgramArguments']
|
||||||
result=subprocess.run(expected,capture_output=True,text=True,timeout=5)
|
result=subprocess.run(expected,capture_output=True,text=True,timeout=5)
|
||||||
assert result.returncode==0, result.stderr
|
assert result.returncode==0, result.stderr
|
||||||
assert result.stdout=='ACTION=heal\n', result.stdout
|
assert result.stdout=='ACTION='+sys.argv[3]+'\n', result.stdout
|
||||||
PY
|
PY
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "persistence invokes renamed scripts with spaces and XML text literally" {
|
||||||
|
check_daemon_path install_persist_launchdaemon heal com.unleash.heal
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "monitor invokes renamed scripts with spaces and XML text literally" {
|
||||||
|
check_daemon_path install_monitor_launchdaemon monitor com.unleash.monitor
|
||||||
|
}
|
||||||
|
|||||||
@@ -1552,11 +1552,7 @@ install_monitor_launchdaemon() {
|
|||||||
[ -n "$data_mount" ] && root="$data_mount"
|
[ -n "$data_mount" ] && root="$data_mount"
|
||||||
|
|
||||||
local unleash_src
|
local unleash_src
|
||||||
if [ -n "$SCRIPT_DIR" ]; then
|
unleash_src=$(_launchd_script_path)
|
||||||
unleash_src="$SCRIPT_DIR/unleash"
|
|
||||||
else
|
|
||||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
step "Installing monitor LaunchDaemon..."
|
step "Installing monitor LaunchDaemon..."
|
||||||
|
|
||||||
@@ -1574,8 +1570,8 @@ install_monitor_launchdaemon() {
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</string>
|
<string>${unleash_src}</string>
|
||||||
<string>${unleash_src} monitor</string>
|
<string>monitor</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
|||||||
Reference in New Issue
Block a user