-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·33 lines (27 loc) · 897 Bytes
/
run.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
#!/bin/sh
set -e
QUERY=".${RESOLVER}.Certificates[] | select(.domain.main==\"${DOMAIN}\")"
CERT=$(cat $INPUT_PATH | jq -r "$QUERY | .certificate" | base64 -d)
KEY=$(cat $INPUT_PATH | jq -r "$QUERY | .key" | base64 -d)
if [ "$CERT" == "" ] ;then
echo "certificate for $DOMAIN was not found in $INPUT_PATH"
else
PEM="$CERT
$KEY"
if [ "$PEM" == "$(cat $OUTPUT_PATH)" ] ;then
echo "certificate for $DOMAIN did not change, keeping $OUTPUT_PATH"
else
echo "certificate for $DOMAIN changed, updating $OUTPUT_PATH"
echo "$PEM" > $OUTPUT_PATH
echo "Restarting postfix"
docker service scale fcat_postfix=0
docker service scale fcat_postfix=1
echo "Restarting dovecot"
docker service scale fcat_dovecot=0
docker service scale fcat_dovecot=1
fi
fi
if [ "$1" == "" ] ;then
echo "Watching $INPUT_PATH for changes"
exec inotifyd /run.sh "$INPUT_PATH:c"
fi