0
0
mirror of https://github.com/thegeeklab/retry.git synced 2024-11-21 13:10:39 +00:00
Retry any shell command
Go to file
renovate[bot] a8f5be0745
chore(docker): update alpine:3.18 docker digest to eece025 (#27)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-10-02 11:06:47 +02:00
.chglog fork 2022-11-02 21:34:28 +01:00
.github fix ci deps in gh settings 2023-10-02 08:38:15 +02:00
.woodpecker fix pipeline deps 2023-08-22 09:29:50 +02:00
.dictionary fix spellcheck 2023-08-22 09:31:35 +02:00
.gitignore fork 2022-11-02 21:34:28 +01:00
.markdownlint.yml unify ci config 2023-08-22 09:19:02 +02:00
.prettierignore ci: migrate from drone to woodpecker (#23) 2023-07-25 22:32:49 +02:00
Containerfile.multiarch chore(docker): update alpine:3.18 docker digest to eece025 (#27) 2023-10-02 11:06:47 +02:00
CONTRIBUTING.md fix bare url in contribution file (#20) 2023-05-03 09:24:21 +02:00
LICENSE fork 2022-11-02 21:34:28 +01:00
README.md unify ci config 2023-08-22 09:19:02 +02:00
renovate.json fix ci and renovate config 2023-07-25 22:39:31 +02:00
retry chore: fix shellcheck SC2323 (#11) 2023-01-14 23:47:20 +01:00
retry.bats add renovate config (#2) 2022-11-02 21:58:50 +01:00

retry

Retry any shell command

Build Status Docker Hub Quay.io GitHub contributors Source: GitHub License: MIT

Retry any shell command with exponential backoff or constant delay.

Instructions

Install:

retry is a shell script, so drop it somewhere and make sure it's added to your $PATH. Or you can use the following one-liner:

curl -SsfL -o /usr/local/bin/retry https://raw.githubusercontent.com/thegeeklab/retry/main/retry && chmod +x /usr/local/bin/retry

Usage

Help:

retry -?

Usage: retry [options] -- execute command
    -h, -?, --help
    -v, --verbose                    Verbose output
    -t, --tries=#                    Set max retries: Default 10
    -s, --sleep=secs                 Constant sleep amount (seconds)
    -m, --min=secs                   Exponential Backoff: minimum sleep amount (seconds): Default 0.3
    -x, --max=secs                   Exponential Backoff: maximum sleep amount (seconds): Default 60
    -f, --fail="script +cmds"        Fail Script: run in case of final failure

Examples

No problem:

retry echo u work good

u work good

Test functionality:

retry 'echo "y u no work"; false'

y u no work
Before retry #1: sleeping 0.3 seconds
y u no work
Before retry #2: sleeping 0.6 seconds
y u no work
Before retry #3: sleeping 1.2 seconds
y u no work
Before retry #4: sleeping 2.4 seconds
y u no work
Before retry #5: sleeping 4.8 seconds
y u no work
Before retry #6: sleeping 9.6 seconds
y u no work
Before retry #7: sleeping 19.2 seconds
y u no work
Before retry #8: sleeping 38.4 seconds
y u no work
Before retry #9: sleeping 60.0 seconds
y u no work
Before retry #10: sleeping 60.0 seconds
y u no work
etc..

Limit retries:

retry -t 4 'echo "y u no work"; false'

y u no work
Before retry #1: sleeping 0.3 seconds
y u no work
Before retry #2: sleeping 0.6 seconds
y u no work
Before retry #3: sleeping 1.2 seconds
y u no work
Before retry #4: sleeping 2.4 seconds
y u no work
Retries exhausted

Bad command:

retry poop

bash: poop: command not found

Fail command:

retry -t 3 -f 'echo "oh poopsickles"' 'echo "y u no work"; false'

y u no work
Before retry #1: sleeping 0.3 seconds
y u no work
Before retry #2: sleeping 0.6 seconds
y u no work
Before retry #3: sleeping 1.2 seconds
y u no work
Retries exhausted, running fail script
oh poopsickles

Last attempt passed:

retry -t 3 -- 'if [ $RETRY_ATTEMPT -eq 3 ]; then echo Passed at attempt $RETRY_ATTEMPT; true; else echo Failed at attempt $RETRY_ATTEMPT; false; fi;'

Failed at attempt 0
Before retry #1: sleeping 0.3 seconds
Failed at attempt 1
Before retry #2: sleeping 0.6 seconds
Failed at attempt 2
Before retry #3: sleeping 1.2 seconds
Passed at attempt 3

Contributors

Special thanks to all contributors. If you would like to contribute, please see the instructions.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.