Skip to content

Commit

Permalink
ci: add flag to run compose and launch plugins if not running
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgomesdev committed Jul 6, 2024
1 parent c5b3038 commit 0b30cac
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions server/scripts/launch-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,52 @@
# Colors

START=$(tput setaf 4)
INFO=$(tput setaf 6)
SECTION=$(tput setaf 5)
WARNING=$(tput setaf 3)
SUCCESS=$(tput setaf 2)
RESET=$(tput sgr0)

# Get params

show_usage () {
echo "Parameters:"
echo "-g: launch Grafana stack"
echo "-b: build binary (instead of downloading the latest release)"
echo "-l: always launch (even if already up-to-date; useful on reboot)"
}

while getopts "blh" opt; do
case ${opt} in
g)
LAUNCH_GRAFANA="y"
;;
h)
show_usage
exit 0
;;
?)
echo "Invalid option: -${OPTARG}."
show_usage
exit 1
;;
esac
done

printf "$START* Running at $(date)$RESET\n"

set -e

GRAFANA_COMPOSE_OVERRIDE=${GRAFANA_COMPOSE_OVERRIDE:-base}

# Start Grafana stack

printf "${SECTION}* Launching Grafana stack...$RESET\n\n"
if [[ "$LAUNCH_GRAFANA" == "y" ]]; then
GRAFANA_COMPOSE_OVERRIDE=${GRAFANA_COMPOSE_OVERRIDE:-base}

printf "${SECTION}* Launching Grafana stack...$RESET\n\n"

# Here we only care about stderr
(cd server/docker && docker compose -f grafana.yaml -f "grafana.$GRAFANA_COMPOSE_OVERRIDE.yaml" up --wait -d) > /dev/null
# Here we only care about stderr
(cd server/docker && docker compose -f grafana.yaml -f "grafana.$GRAFANA_COMPOSE_OVERRIDE.yaml" up --wait -d) > /dev/null
fi

# Update and launch server

Expand All @@ -34,8 +63,25 @@ printf "\n${SECTION}* Updating and launching plugins...$RESET\n\n"

PLUGINS_PATH=${PLUGINS_PATH:-../RustyController-plugins}

mkdir -p /var/log/rusty-controller/plugins/ && cd "$PLUGINS_PATH"

# Run plugins only if outdated
mkdir -p /var/log/rusty-controller/plugins/ && cd "$PLUGINS_PATH" && git remote update && git status -uno | grep -q 'Your branch is behind' && git pull && bash run-all.sh
ARE_PLUGINS_UPDATED=$(git remote update && git status -uno | grep -q 'Your branch is behind' && git pull)

if [[ ! $ARE_PLUGINS_UPDATED ]]; then
printf "\n${INFO}Plugins are outdated...$RESET\n\n"
bash run-all.sh
else
tmux has-session -t "RustyController plugins" 2>/dev/null
if [ $? != 0 ]; then
printf "\n${INFO}Plugins are not running, running...$RESET\n\n"
bash run-all.sh
else
printf "\n${INFO}Plugins are up-to-date$RESET\n\n"
fi
fi

echo -e "\n${SUCCESS}* Finished! (at $(date))$RESET"
echo

cd ../RustyController

0 comments on commit 0b30cac

Please sign in to comment.