-
Notifications
You must be signed in to change notification settings - Fork 9
/
wait-for-safety.sh
executable file
·37 lines (34 loc) · 1.08 KB
/
wait-for-safety.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
#!/usr/bin/env bash
# Wait until the network is secured, and start a program.
#
# The "secured network" is detected by a firewall rules
# that block all traffic by default. If the network becomes
# unsecured later, the wrapped program is not stopped.
#
# The script is intended to be used as an entrypoint or
# a wrapper script for the containers running in parallel
# to the VPN and firewall containers: since they all start
# at the same time, the applications should not be started
# before the network is secured.
#
# Usage (as a wrapper):
# ADD wait-for-safety.sh /
# CMD /wait-for-safety.sh some-app
#
# Usage (as an entry point):
# ADD wait-for-safety.sh /
# ENTRYPOINT ["/wait-for-safety.sh"]
# CMD some-app
#
#set -x # for debugging
set -euo pipefail
while ! iptables -n -L | egrep "Chain INPUT \(policy DROP\)" >/dev/null; do
echo "Waiting for the firewall..."
sleep 1
done
while ! iptables -n -L | egrep "Chain OUTPUT \(policy DROP\)" >/dev/null; do
echo "Waiting for the firewall..."
sleep 1
done
echo "The firewall's block-rule is found, the firewall is ready."
exec "$@"