-
Notifications
You must be signed in to change notification settings - Fork 0
/
unseal.sh
executable file
·43 lines (38 loc) · 900 Bytes
/
unseal.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
log() {
if [[ "$2" == "error" ]]; then
echo `date` - ERROR - $1
exit 1
else
echo `date` - INFO - $1
fi
}
if [[ -z "$VAULT_ADDR" || -z "$VAULT_UNSEAL_TOKENS" ]]; then
log "Environment variables VAULT_ADDR and VAULT_UNSEAL_TOKENS are required" "error"
fi
if [[ -z "$TIMEOUT" ]]; then
TIMEOUT=300
fi
log VAULT_ADDR=$VAULT_ADDR
log TIMEOUT=$TIMEOUT
while true
do
log "Sleeping for $TIMEOUT seconds"
seal_status=`vault status|grep -i sealed|awk '{print $2}'`
if [[ $seal_status == 'true' ]]; then
log "Unsealing vault at $VAULT_ADDR"
tokens=($VAULT_UNSEAL_TOKENS)
for token in "${tokens[@]}"; do
vault operator unseal $token
done
exit_code=$?
if [[ $exit_code -gt 0 ]]; then
exit $exit_code
else
log "Successfully unseal vault at $VAULT_ADDR"
fi
else
log "Vault is unsealed"
fi
sleep "$TIMEOUT"
done