diff options
Diffstat (limited to 'tests/respawn')
-rwxr-xr-x | tests/respawn | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/respawn b/tests/respawn new file mode 100755 index 0000000..11d59f6 --- /dev/null +++ b/tests/respawn | |||
@@ -0,0 +1,63 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | # usage: respawn [-append] [-stderr FILE] [-stdout FILE] [-sleep TIME] | ||
4 | # [-pid FILE] [-tag STRING] [-exit CODE] | ||
5 | |||
6 | append=0 | ||
7 | unset name | ||
8 | time=10 | ||
9 | tag=$0 | ||
10 | code=0 | ||
11 | |||
12 | while [ $# -ne 0 ] | ||
13 | do | ||
14 | arg=$1 | ||
15 | shift | ||
16 | case $arg in | ||
17 | -append) | ||
18 | append=1;; | ||
19 | -stderr) | ||
20 | name=${1:?missing argument for -stderr} | ||
21 | shift | ||
22 | if [ $append -eq 1 ]; then | ||
23 | exec 2>>$name | ||
24 | append=0 | ||
25 | else | ||
26 | exec 2>$name | ||
27 | fi;; | ||
28 | -stdout) | ||
29 | name=${1:?missing argument for -stdout} | ||
30 | shift | ||
31 | if [ $append -eq 1 ]; then | ||
32 | exec >>$name | ||
33 | append=0 | ||
34 | else | ||
35 | exec >$name | ||
36 | fi;; | ||
37 | -sleep) | ||
38 | time=${1:?missing argument for -sleep} | ||
39 | shift;; | ||
40 | -pid) | ||
41 | name=${1:?missing argument for -pid} | ||
42 | shift | ||
43 | if [ $append -eq 1 ]; then | ||
44 | echo $$ >>$name | ||
45 | append=0 | ||
46 | else | ||
47 | echo $$ >$name | ||
48 | fi;; | ||
49 | -tag) | ||
50 | tag=${1:?missing argument for -tag} | ||
51 | shift;; | ||
52 | -exit) | ||
53 | code=${1:?missing argument for -exit} | ||
54 | shift;; | ||
55 | *) echo >&2 "$tag: invalid argument: $arg" | ||
56 | exit 1 | ||
57 | esac | ||
58 | done | ||
59 | |||
60 | echo "$tag: start" | ||
61 | sleep $time | ||
62 | echo "$tag: stop" | ||
63 | exit $code | ||