2021-05-17 11:40:25 +00:00
|
|
|
# retry
|
|
|
|
|
2021-06-15 14:03:25 +00:00
|
|
|
[![Build Status](https://img.shields.io/drone/build/owncloud-ci/retry?logo=drone&server=https%3A%2F%2Fdrone.owncloud.com)](https://drone.owncloud.com/owncloud-ci/retry)
|
|
|
|
[![GitHub contributors](https://img.shields.io/github/contributors/owncloud-ci/retry)](https://github.com/owncloud-ci/retry/graphs/contributors)
|
2021-05-17 11:40:25 +00:00
|
|
|
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/owncloud-ci/retry)
|
2021-06-15 14:03:25 +00:00
|
|
|
[![License: Apache-2.0](https://img.shields.io/github/license/owncloud-ci/retry)](https://github.com/owncloud-ci/retry/blob/master/LICENSE)
|
2015-03-26 19:06:47 +00:00
|
|
|
|
|
|
|
Retry any shell command with exponential backoff or constant delay.
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
## Instructions
|
2015-03-26 19:06:47 +00:00
|
|
|
|
|
|
|
Install:
|
|
|
|
|
2021-06-15 14:03:25 +00:00
|
|
|
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:
|
2018-01-23 18:27:06 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
2022-06-21 13:58:32 +00:00
|
|
|
curl -SsfL -o /usr/local/bin/retry https://raw.githubusercontent.com/owncloud-ops/retry/master/retry && chmod +x /usr/local/bin/retry"
|
2018-01-23 20:34:43 +00:00
|
|
|
```
|
2018-01-23 18:27:06 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
## Usage
|
2015-03-26 19:06:47 +00:00
|
|
|
|
|
|
|
Help:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
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
|
|
|
|
```
|
2019-08-14 07:45:29 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
## Examples
|
2015-03-26 19:06:47 +00:00
|
|
|
|
2015-03-26 19:24:45 +00:00
|
|
|
No problem:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
retry echo u work good
|
2015-03-26 19:24:45 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
u work good
|
|
|
|
```
|
2015-03-26 19:24:45 +00:00
|
|
|
|
2015-03-26 19:06:47 +00:00
|
|
|
Test functionality:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
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..
|
|
|
|
```
|
2015-03-26 19:06:47 +00:00
|
|
|
|
|
|
|
Limit retries:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
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
|
|
|
|
```
|
2015-03-26 19:06:47 +00:00
|
|
|
|
|
|
|
Bad command:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
retry poop
|
2015-03-26 19:06:47 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
bash: poop: command not found
|
|
|
|
```
|
2015-03-26 19:06:47 +00:00
|
|
|
|
2015-06-23 16:06:02 +00:00
|
|
|
Fail command:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
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
|
|
|
|
```
|
2015-06-23 16:06:02 +00:00
|
|
|
|
2018-01-23 18:27:06 +00:00
|
|
|
Last attempt passed:
|
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
```Shell
|
|
|
|
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;'
|
2018-01-23 18:27:06 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
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
|
|
|
|
```
|
2018-01-23 18:27:06 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
## License
|
2015-03-26 19:06:47 +00:00
|
|
|
|
2021-05-17 11:40:25 +00:00
|
|
|
This project is licensed under the Apache 2.0 License - see the [LICENSE](https://github.com/owncloud-ci/retry/blob/master/LICENSE) file for details.
|
2021-06-15 14:03:25 +00:00
|
|
|
|
|
|
|
## Copyright
|
|
|
|
|
|
|
|
```Text
|
2021-12-21 11:06:04 +00:00
|
|
|
Copyright (c) 2022 ownCloud GmbH
|
2021-06-15 14:03:25 +00:00
|
|
|
```
|