Revision 8e19b566
share/hooks/raft/follower_cleanup | ||
---|---|---|
1 |
#!/usr/bin/env ruby |
|
2 |
|
|
3 |
VAR_LOCATION = "/var/lib/one" |
|
4 |
CONFIG_LOCATION = VAR_LOCATION + "/config" |
|
5 |
HOOKS_LOCATION = VAR_LOCATION + "/remotes/hooks" |
|
6 |
|
|
7 |
REGEXP = /^RAFT_FOLLOWER_HOOK=(?:ARGUMENTS=(.*),)?COMMAND=(.*)$/ |
|
8 |
|
|
9 |
config = File.read(CONFIG_LOCATION) |
|
10 |
|
|
11 |
groups = config.match(REGEXP) rescue nil |
|
12 |
|
|
13 |
if groups.nil? || groups[2].nil? |
|
14 |
exit 0 |
|
15 |
end |
|
16 |
|
|
17 |
cmd = groups[2] |
|
18 |
|
|
19 |
if !cmd.start_with?("/") |
|
20 |
cmd = HOOKS_LOCATION + "/" + cmd |
|
21 |
end |
|
22 |
|
|
23 |
cmd = cmd.split(" ") |
|
24 |
|
|
25 |
if groups[1] |
|
26 |
cmd += groups[1].split(" ") |
|
27 |
end |
|
28 |
|
|
29 |
exec(*cmd) |
Also available in: Unified diff