Skip to content

Commit

Permalink
Unify script bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
brablc committed Jun 3, 2024
1 parent fbf14df commit 4b6d603
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 48 deletions.
11 changes: 11 additions & 0 deletions checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mkdir -p "$DATA_DIR"

if [[ ! -S /var/run/docker.sock ]]; then
log_error "Mount to /var/run/docker.sock missing?"
exit 1
fi

if [[ -z $ALERT_SCRIPT ]]; then
log_error "Alert script not defined, alerting to console."
export ALERT_SCRIPT="jq ."
fi
27 changes: 7 additions & 20 deletions config.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
SCRIPT_NAME=${0##*/}
SCRIPT_PATH=$(readlink -f $0)
SCRIPT_DIR=${SCRIPT_PATH%/*}
cd "$SCRIPT_DIR"

export LOOP_SLEEP=${LOOP_SLEEP:-10}
export ALERTER_URL=${ALERTER_URL:-http://alerter:80}
export SWARM_NAME=${SWARM_NAME:-Swarm}
export LOGGER_USE_TS=1
export LABEL="swarm-health-alerter.port"
export LOGGER_USE_SYSLOG=0
export LOGGER_USE_TS=1
export LOOP_SLEEP=${LOOP_SLEEP:-10}
export SWARM_NAME=${SWARM_NAME:-Swarm}

export DATA_DIR=${DATA_DIR:-$script_dir/data}
mkdir -p $DATA_DIR

if [[ ! -S /var/run/docker.sock ]]; then
log_error "Mount to /var/run/docker.sock missing?"
exit 1
fi

if [[ -z $ALERT_SCRIPT ]]; then
log_error "Alert script not defined!"
export ALERT_SCRIPT="jq ."
fi

if [[ ! -f $ALERT_SCRIPT ]]; then
|| ! -f $ALERT_SCRIPT ]]; then
log_error "Alert script not accessible on $ALERT_SCRIPT path!"
export ALERT_SCRIPT="jq ."
fi
18 changes: 1 addition & 17 deletions docker-cmd.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
#!/usr/bin/env bash

script_path=$(readlink -f $0)
script_dir=${script_path%/*}
cd "$script_dir"
source "./config.sh"
source "./logger.sh"

export LOOP_SLEEP=${LOOP_SLEEP:-10}
export ALERTER_URL=${ALERTER_URL:-http://alerter:80}
export SWARM_NAME=${SWARM_NAME:-Swarm}

if [[ ! -S /var/run/docker.sock ]]; then
log_error "Mount to /var/run/docker.sock missing?"
exit 1
fi

if [[ -z $ALERT_SCRIPT || ! -f $ALERT_SCRIPT ]]; then
log_error "Alert script not defined or not accessible on \"$ALERT_SCRIPT\" path!"
export ALERT_SCRIPT="jq ."
fi
source "./checks.sh"

log_info "Starting event alerter ..."
./event-alerter.py &
Expand Down
8 changes: 4 additions & 4 deletions integrations/zenduty.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

script_path=$(readlink -f $0)
script_dir=${script_path%/*}
source "$script_dir/../logger.sh"
SCRIPT_PATH=$(readlink -f $0)
SCRIPT_DIR=${SCRIPT_PATH%/*}
source "$SCRIPT_DIR/../logger.sh"

DATA_DIR=${DATA_DIR:-$script_dir/../data}
DATA_DIR=${DATA_DIR:-$SCRIPT_DIR/../data}

input_file=$(mktemp $DATA_DIR/zenduty-input.XXXXXX)
trap "rm -f $input_file" EXIT
Expand Down
4 changes: 1 addition & 3 deletions port-alerter.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env bash

script_path=$(readlink -f $0)
script_dir=${script_path%/*}
cd "$script_dir"
source "./config.sh"
source "./logger.sh"
source "./checks.sh"

function check_services() {
local swarm_name=$SWARM_NAME
Expand Down
7 changes: 3 additions & 4 deletions services.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash

source ./config.sh
source ./logger.sh

LABEL="swarm-health-alerter.port"
source "./config.sh"
source "./logger.sh"
source "./checks.sh"

./docker-api.sh /services > /tmp/services
if [ $? -ne 0 ]; then
Expand Down

0 comments on commit 4b6d603

Please sign in to comment.