Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell exit traps for EXIT cleanup #503

Merged
merged 4 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion bin/pubber
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

ROOT_DIR=$(realpath $(dirname $0)/..)

function cleanup {
if [[ -n $PUB_PID ]]; then
echo Killing pubber runner $PUB_PID
kill $PUB_PID
fi
}
trap cleanup EXIT

if (( $# < 4 )); then
echo $0 SITE_PATH PROJECT_ID DEVICE_ID SERIAL_NO [options] ...
false
Expand Down Expand Up @@ -56,4 +64,7 @@ cat <<EOF > /tmp/pubber_config.json
}
EOF

$ROOT_DIR/pubber/bin/run /tmp/pubber_config.json
# Run in the background to force new process group and get PID
$ROOT_DIR/pubber/bin/run /tmp/pubber_config.json &
PUB_PID=$!
wait
8 changes: 8 additions & 0 deletions pubber/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

ROOT_DIR=$(realpath $(dirname $0)/../..)

function cleanup {
if [[ -n $PUB_PID ]]; then
echo Killing pubber instance $PUB_PID
kill $PUB_PID
fi
}
trap cleanup EXIT

result=192 # Exit code used to indicate intentional system restart.

while [[ $result -eq 192 ]]; do
Expand Down