Skip to content

Instantly share code, notes, and snippets.

@scottschreckengaust
Created November 26, 2024 23:30
Show Gist options
  • Save scottschreckengaust/ac37fdecc691d87c85000c6ffe4a6f2f to your computer and use it in GitHub Desktop.
Save scottschreckengaust/ac37fdecc691d87c85000c6ffe4a6f2f to your computer and use it in GitHub Desktop.
This gets the full command from PID 1 and checks for the process running
#!/bin/sh
set -e
# Get the process
FULL_COMMAND="$(sed -n l "/proc/1/cmdline" | sed -e 's/\\$//g' | tr -d '\n' | sed -e 's/\$$//g' | sed -e 's/\\000/ /g' | sed -e 's/ *$//g' | head -1)"
# Look for the process
pgrep --full "$FULL_COMMAND" 2> /dev/null > /dev/null;
exit ${?};
@scottschreckengaust
Copy link
Author

This is "a way" to put in a generalized HEALTHCHECK within a Dockerfile:

COPY healthcheck.sh /app/healthcheck.sh
RUN chmod a+x /app/healthcheck.sh

USER nobody
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/app/healthcheck.sh" ]
ENTRYPOINT ["executable", "to", "run"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment