Skip to content

Instantly share code, notes, and snippets.

@Gustibimo
Created October 2, 2020 15:08
Show Gist options
  • Save Gustibimo/f6e8b10a41f0f80c1bb7777c9c7a2326 to your computer and use it in GitHub Desktop.
Save Gustibimo/f6e8b10a41f0f80c1bb7777c9c7a2326 to your computer and use it in GitHub Desktop.

Revisions

  1. Gustibimo created this gist Oct 2, 2020.
    18 changes: 18 additions & 0 deletions debezium_auto_restart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/usr/bin/env bash

    echo '----'
    # Set the path so cron can find jq, necessary for cron depending on your default PATH
    export PATH=$PATH:/usr/local/bin/

    date

    # List current connectors and status
    curl -s "http://localhost:8083/connectors?expand=info&expand=status" | \
    jq '. | to_entries[] | [ .value.info.type, .key, .value.status.connector.state,.value.status.tasks[].state,.value.info.config."connector.class"]|join(":|:")' | \
    column -s : -t| sed 's/\"//g'| sort

    # Restart any connector tasks that are FAILED
    curl -s "http://localhost:8083/connectors?expand=status" | \
    jq -c -M 'map({name: .status.name } + {tasks: .status.tasks}) | .[] | {task: ((.tasks[]) + {name: .name})} | select(.task.state=="FAILED") | {name: .task.name, task_id: .task.id|tostring} | ("/connectors/"+ .name + "/tasks/" + .task_id + "/restart")' | \
    xargs -I{connector_and_task} curl -v -X POST "http://localhost:8083"\{connector_and_task\}