mirror of
https://github.com/containers/podman.git
synced 2025-05-17 06:59:07 +08:00
Merge pull request #26127 from martinetd/restart-hooks
podman: remember hooks-dir on restarts
This commit is contained in:
@ -285,6 +285,9 @@ func CreateExitCommandArgs(storageConfig storageTypes.StoreOptions, config *conf
|
||||
"--db-backend", config.Engine.DBBackend,
|
||||
fmt.Sprintf("--transient-store=%t", storageConfig.TransientStore),
|
||||
}
|
||||
for _, dir := range config.Engine.HooksDir.Get() {
|
||||
command = append(command, []string{"--hooks-dir", dir}...)
|
||||
}
|
||||
if storageConfig.ImageStore != "" {
|
||||
command = append(command, []string{"--imagestore", storageConfig.ImageStore}...)
|
||||
}
|
||||
|
@ -1497,6 +1497,50 @@ EOF
|
||||
done
|
||||
}
|
||||
|
||||
# bats test_tags=ci:parallel
|
||||
@test "podman run --restart preserves hooks-dir" {
|
||||
# regression test for #17935 to ensure hooks are run on successful restarts
|
||||
ctr=c_$(safename)
|
||||
hooksdir=$PODMAN_TMPDIR/hooks_$(safename)
|
||||
|
||||
skip_if_remote "--hooks-dir is not usable with remote"
|
||||
|
||||
mkdir -p "$hooksdir"
|
||||
cat > "$hooksdir/settings.json" <<EOF
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"when": { "always": true },
|
||||
"hook": {
|
||||
"path": "$hooksdir/hook.sh"
|
||||
},
|
||||
"stages": ["prestart", "poststop"]
|
||||
}
|
||||
EOF
|
||||
cat >"$hooksdir/hook.sh" <<EOF
|
||||
#!/bin/sh
|
||||
# consume stdin
|
||||
cat > /dev/null
|
||||
echo ran >> "$hooksdir/log"
|
||||
EOF
|
||||
chmod +x "$hooksdir/hook.sh"
|
||||
|
||||
run_podman run -d --restart=on-failure:2 \
|
||||
--name="$ctr" --hooks-dir="$hooksdir" $IMAGE false
|
||||
|
||||
wait_for_restart_count "$ctr" 2 "restart preserves hooks-dir"
|
||||
|
||||
# also make sure 3rd restart has finished
|
||||
# wait also waits until 'cleanup' is done, so poststop hook is
|
||||
# done running after this command
|
||||
run_podman wait "$ctr"
|
||||
run_podman rm "$ctr"
|
||||
|
||||
# check prestart and poststop ran 3 times each
|
||||
assert "$(wc -l < "$hooksdir/log")" = 6
|
||||
|
||||
rm -r "$hooksdir"
|
||||
}
|
||||
|
||||
# bats test_tags=ci:parallel
|
||||
@test "podman run - custom static_dir" {
|
||||
# regression test for #19938 to make sure the cleanup process uses the same
|
||||
|
@ -968,27 +968,6 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
function wait_for_restart_count() {
|
||||
local cname="$1"
|
||||
local count="$2"
|
||||
local tname="$3"
|
||||
|
||||
local timeout=10
|
||||
while :; do
|
||||
# Previously this would fail as the container would run out of ips after 5 restarts.
|
||||
run_podman inspect --format "{{.RestartCount}}" $cname
|
||||
if [[ "$output" == "$2" ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
timeout=$((timeout - 1))
|
||||
if [[ $timeout -eq 0 ]]; then
|
||||
die "Timed out waiting for RestartCount with $tname"
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
}
|
||||
|
||||
# Test for https://github.com/containers/podman/issues/18615
|
||||
# CANNOT BE PARALLELIZED due to strict checking of /run/netns
|
||||
@test "podman network cleanup --userns + --restart" {
|
||||
|
@ -1347,6 +1347,30 @@ function ensure_no_mountpoint() {
|
||||
fi
|
||||
}
|
||||
|
||||
###########################
|
||||
# ensure container has been restarted requested times
|
||||
###########################
|
||||
function wait_for_restart_count() {
|
||||
local cname="$1"
|
||||
local count="$2"
|
||||
local tname="$3"
|
||||
|
||||
local timeout=10
|
||||
while :; do
|
||||
# Previously this would fail as the container would run out of ips after 5 restarts.
|
||||
run_podman inspect --format "{{.RestartCount}}" $cname
|
||||
if [[ "$output" == "$2" ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
timeout=$((timeout - 1))
|
||||
if [[ $timeout -eq 0 ]]; then
|
||||
die "Timed out waiting for RestartCount with $tname"
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# END miscellaneous tools
|
||||
###############################################################################
|
||||
|
Reference in New Issue
Block a user