Skip to content

Commit

Permalink
Exit with 0 when receiving SIGTERM
Browse files Browse the repository at this point in the history
* systemctl stop podman.service will now return exit code 0
* Update test framework to support JSON boolean and numeric values

Signed-off-by: Jhon Honce <[email protected]>
  • Loading branch information
jwhonce committed Mar 15, 2022
1 parent fa0d3c5 commit ca7376b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
4 changes: 4 additions & 0 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
}

if err := shutdown.Register("libpod", func(sig os.Signal) error {
// For `systemctl stop podman.service` support, exit code should be 0
if sig == syscall.SIGTERM {
os.Exit(0)
}
os.Exit(1)
return nil
}); err != nil && errors.Cause(err) != shutdown.ErrHandlerExists {
Expand Down
2 changes: 1 addition & 1 deletion test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ t DELETE containers/$cid_top 204
t POST containers/create \
Image=$ENV_WORKDIR_IMG \
WorkingDir=/dataDir \
StopSignal=9 \
StopSignal=\"9\" \
201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
Expand Down
44 changes: 28 additions & 16 deletions test/apiv2/test-apiv2
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,16 @@ function jsonify() {
local rhs
IFS='=' read lhs rhs <<<"$i"

# If right-hand side already includes double quotes, do nothing
if [[ ! $rhs =~ \" ]]; then
if [[ $rhs =~ \" || $rhs == true || $rhs == false || $rhs =~ ^-?[0-9]+$ ]]; then
# rhs has been pre-formatted for JSON or a non-string, do not change it
:
elif [[ $rhs == False ]]; then
# JSON boolean is lowercase only
rhs=false
elif [[ $rhs == True ]]; then
# JSON boolean is lowercase only
rhs=true
else
rhs="\"${rhs}\""
fi
settings_out+=("\"${lhs}\":${rhs}")
Expand Down Expand Up @@ -241,26 +249,30 @@ function t() {
# entrypoint path can include a descriptive comment; strip it off
path=${path%% *}

# path may include JSONish params that curl will barf on; url-encode them
path="${path//'['/%5B}"
path="${path//']'/%5D}"
path="${path//'{'/%7B}"
path="${path//'}'/%7D}"
path="${path//':'/%3A}"
local url=$path
if ! [[ $path =~ ^'http://' ]]; then
# path may include JSONish params that curl will barf on; url-encode them
path="${path//'['/%5B}"
path="${path//']'/%5D}"
path="${path//'{'/%7B}"
path="${path//'}'/%7D}"
path="${path//':'/%3A}"

# If given path begins with /, use it as-is; otherwise prepend /version/
url=http://$HOST:$PORT
case "$path" in
/*) url="$url$path" ;;
libpod/*) url="$url/v4.0.0/$path" ;;
*) url="$url/v1.41/$path" ;;
esac
fi

# curl -X HEAD but without --head seems to wait for output anyway
if [[ $method == "HEAD" ]]; then
curl_args="--head"
fi
local expected_code=$1; shift

# If given path begins with /, use it as-is; otherwise prepend /version/
local url=http://$HOST:$PORT
case "$path" in
/*) url="$url$path" ;;
libpod/*) url="$url/v4.0.0/$path" ;;
*) url="$url/v1.41/$path" ;;
esac
local expected_code=$1; shift

# Log every action we do
echo "-------------------------------------------------------------" >>$LOG
Expand Down

0 comments on commit ca7376b

Please sign in to comment.