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

Feature/Question Notify Webhook also when container is restarting #125

Open
alex-bronze-vision opened this issue Jan 25, 2024 · 0 comments

Comments

@alex-bronze-vision
Copy link

Hi,

As I can see from:

  if [ "$CONTAINER_NAME" = "null" ]
  then
    echo "$DATE Container name of (${CONTAINER_SHORT_ID}) is null, which implies container does not exist - don't restart" >&2
  elif [ "$CONTAINER_STATE" = "restarting" ]
  then
    echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be restarting - don't restart"
  else
    echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be unhealthy - Restarting container now with ${TIMEOUT}s timeout"
    if ! restart_container "$CONTAINER_ID" "$TIMEOUT"
    then
      echo "$DATE Restarting container $CONTAINER_SHORT_ID failed" >&2
      notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" &
    else
      notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
    fi
    notify_post_restart_script "$CONTAINER_NAME" "$CONTAINER_SHORT_ID" "$CONTAINER_STATE" "$TIMEOUT" &

Webhooks are only triggered when containers are unhealthy and being restarted, but not when they are restarting by its own, maybe due to an internal error in the container.
I would be really nice to also notify that. I am opening this issue just to confirm that the modifycation that should be made is to add a notify_webhook when restarting:

  if [ "$CONTAINER_NAME" = "null" ]
  then
    echo "$DATE Container name of (${CONTAINER_SHORT_ID}) is null, which implies container does not exist - don't restart" >&2
  elif [ "$CONTAINER_STATE" = "restarting" ]
  then
    echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be restarting - don't restart"
    notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be restarting - don't restart"
  else
    echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be unhealthy - Restarting container now with ${TIMEOUT}s timeout"
    if ! restart_container "$CONTAINER_ID" "$TIMEOUT"
    then
      echo "$DATE Restarting container $CONTAINER_SHORT_ID failed" >&2
      notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" &
    else
      notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
    fi
    notify_post_restart_script "$CONTAINER_NAME" "$CONTAINER_SHORT_ID" "$CONTAINER_STATE" "$TIMEOUT" &

If that is correct and the idea seems to be logical I can make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant