-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just proof of concept, so far no alerting
- Loading branch information
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM alpine:latest | ||
|
||
ENV DOCKERIZE_VERSION v0.7.0 | ||
|
||
WORKDIR /app | ||
|
||
COPY *.sh ./ | ||
|
||
RUN apk update --no-cache \ | ||
&& apk add --no-cache bash curl jq openssl \ | ||
&& curl -s -L https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C . | ||
|
||
HEALTHCHECK \ | ||
--interval=10s \ | ||
--timeout=301s \ | ||
--retries=2 \ | ||
--start-period=300s \ | ||
CMD ./docker-healthcheck.sh | ||
|
||
CMD ["./docker-cmd.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
OK_FILE="/tmp/ok" | ||
LOGGER_USE_TS=1 | ||
SCRIPT_NAME=${0##*/} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
source ./config.sh | ||
source ./logger.sh | ||
|
||
SLEEP=${SLEEP-10s} | ||
|
||
function get_cmd() { | ||
cmd=(./dockerize -timeout 300s -wait-retry-interval 5s) | ||
while read SERVICE; do | ||
cmd+=(-wait $SERVICE) | ||
done < <(./services.sh) | ||
cmd+=(touch $OK_FILE) | ||
echo ${cmd[@]} | ||
} | ||
|
||
log_info "Entering loop with ${SLEEP} sleep ..." | ||
|
||
while true; do | ||
eval $(get_cmd) | ||
if [ -f $OK_FILE ]; then | ||
log_info OK | ||
sleep $SLEEP | ||
rm -f $OK_FILE | ||
else | ||
log_error TIMEOUT | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
LOOP_SLEEP=${LOOP_SLEEP-60s} | ||
|
||
source ./config.sh | ||
source ./logger.sh | ||
|
||
log_info "Using email: $CERTBOT_EMAIL" | ||
log_info "Initial list of domains from certbot.domain labels ..." | ||
./domains.sh | ||
|
||
LAST_DATE=$(date +"%Y-%m-%d") | ||
|
||
log_info "Entering loop with $LOOP_SLEEP sleep ..." | ||
while true; do | ||
sleep $LOOP_SLEEP | ||
|
||
NEW_DATE=$(date +"%Y-%m-%d") | ||
|
||
if [[ $LAST_DATE != $NEW_DATE ]]; then | ||
LAST_DATE=$NEW_DATE | ||
log_info "New date detected renewing ..." | ||
./renew.sh | ||
else | ||
./issue.sh | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
log() { | ||
local level color message | ||
level=$1 | ||
message=$2 | ||
|
||
case "$level" in | ||
INFO) | ||
color=$'\e[36m' | ||
;; | ||
WARNING) | ||
color=$'\e[35m' | ||
;; | ||
ERROR) | ||
color=$'\e[31m' | ||
;; | ||
*) | ||
color=$'\e[39m' | ||
;; | ||
esac | ||
|
||
reset=$'\e[39m' | ||
if [[ -n $LOGGER_USE_TS ]]; then | ||
timestamp=$(date +"%Y-%m-%d %H:%M:%S|") | ||
else | ||
timestamp="" | ||
fi | ||
|
||
if [[ -t 1 || -n $CONTENT_TYPE ]]; then | ||
echo -e "${color}-${level:0:1}|${timestamp}${message}${reset}" | ||
else | ||
echo "-${level:0:1}|${timestamp}${message}" | ||
fi | ||
|
||
logger -t $SCRIPT_NAME -p user.${level,,} "${level} - ${message}" | ||
} | ||
|
||
log_info() { | ||
log "INFO" "$1" | ||
} | ||
|
||
log_warn() { | ||
log "WARNING" "$1" | ||
} | ||
|
||
log_error() { | ||
log "ERROR" "$1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
SOCK=/var/run/docker.sock | ||
URL=http://v1.45/services | ||
|
||
LABEL="swarm-health-alerter.port" | ||
|
||
function get_services() { | ||
curl -s --unix-socket $SOCK $URL \ | ||
| jq -r '.[] | select(.Spec.Labels["com.docker.stack.namespace"] != null) | .Spec.Name' | ||
} | ||
|
||
while read service; do | ||
ports=$(curl -s --unix-socket $SOCK $URL/$service | jq -r '.Spec.Labels["'$LABEL'"]') | ||
test "$ports" != "null" || continue | ||
network_alias=$(curl -s --unix-socket $SOCK $URL/$service | jq -r '.Spec.TaskTemplate.Networks[].Aliases[]' | sort | head -1) | ||
echo $ports | sed 's/,/\n/g' | while read port; do echo "tcp://$network_alias:$port"; done | ||
done < <(get_services) |