This repository was archived by the owner on Jul 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
set -e
4
4
5
+ function __cleanup ()
6
+ {
7
+ __delete_lock
8
+ }
9
+
10
+ function __create_lock ()
11
+ {
12
+ if [[ -n ${lock_file} ]]
13
+ then
14
+ touch " ${lock_file} "
15
+ fi
16
+ }
17
+
5
18
function __create_state ()
6
19
{
7
20
if [[ -n ${state_file} ]]
@@ -14,6 +27,14 @@ function __create_state ()
14
27
fi
15
28
}
16
29
30
+ function __delete_lock ()
31
+ {
32
+ if [[ -e ${lock_file} ]]
33
+ then
34
+ rm -f " ${lock_file} "
35
+ fi
36
+ }
37
+
17
38
function __get_reaper_timeout ()
18
39
{
19
40
local -r default_value=" ${1:- 3600} "
@@ -51,10 +72,13 @@ function __reap ()
51
72
kill \
52
73
-s " ${signal:- TERM} " \
53
74
" ${pid:- 1} "
75
+
76
+ __cleanup
54
77
}
55
78
56
79
function main ()
57
80
{
81
+ local -r lock_file=" /var/lock/subsys/reaper"
58
82
local -r state_file=" /var/lib/misc/reaper"
59
83
local -r timeout=" $(
60
84
__get_reaper_timeout
@@ -93,6 +117,18 @@ function main ()
93
117
esac
94
118
done
95
119
120
+ if [[ -e ${lock_file} ]]
121
+ then
122
+ >&2 printf -- \
123
+ ' ERROR: %s lock detected - aborting\n' \
124
+ " ${0##*/ } "
125
+ exit 1
126
+ fi
127
+
128
+ trap __cleanup \
129
+ EXIT INT TERM
130
+ __create_lock
131
+
96
132
if (( timeout > 0 ))
97
133
then
98
134
trap __reap \
You can’t perform that action at this time.
0 commit comments