From 0b30cac8ff7c6e97f12c6d32b71088bea1fc5534 Mon Sep 17 00:00:00 2001 From: David Gomes <10091092+davidgomesdev@users.noreply.github.com> Date: Sat, 6 Jul 2024 10:31:41 +0100 Subject: [PATCH] ci: add flag to run compose and launch plugins if not running --- server/scripts/launch-all.sh | 58 ++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/server/scripts/launch-all.sh b/server/scripts/launch-all.sh index 2b829ec..ebb0596 100755 --- a/server/scripts/launch-all.sh +++ b/server/scripts/launch-all.sh @@ -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 @@ -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