2019-02-27 21:48:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
TIMEOUT=${1}
|
|
|
|
shift
|
|
|
|
PGREP_OPTS=${@}
|
2019-02-27 21:48:37 +00:00
|
|
|
SLEEP_SEC=5
|
|
|
|
STEPS=$((TIMEOUT / SLEEP_SEC))
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
if [[ -z ${PGREP_OPTS} ]]; then
|
|
|
|
echo "No pgrep options name specified!" >&2
|
2019-02-27 21:48:37 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
echo "Checking for process: '${PGREP_OPTS}'"
|
2019-02-27 21:48:37 +00:00
|
|
|
for ((i = 0; i < ${STEPS}; i += 1)); do
|
2019-08-20 19:45:41 +00:00
|
|
|
if pgrep ${PGREP_OPTS} > /dev/null; then
|
2019-02-27 21:48:37 +00:00
|
|
|
echo "Process found. Sleeping ${SLEEP_SEC}..." >&2
|
|
|
|
sleep ${SLEEP_SEC}
|
|
|
|
else
|
2019-08-20 19:45:41 +00:00
|
|
|
echo "Process '${PGREP_OPTS}' gone." >&2
|
2019-02-27 21:48:37 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
echo "Timeout reached! (${TIMEOUT}s) Process still up: ${PGREP_OPTS}" >&2
|
2019-02-27 21:48:37 +00:00
|
|
|
exit 1
|