From 7f28f12989f56ba809c3c035b26561af2408600b Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Sun, 16 Nov 2025 09:51:27 +0100 Subject: [PATCH 1/3] Refactor: Healthchecks --- install/healthchecks-install.sh | 60 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/install/healthchecks-install.sh b/install/healthchecks-install.sh index 7e2d472cddc..bdd8d397c10 100644 --- a/install/healthchecks-install.sh +++ b/install/healthchecks-install.sh @@ -1,10 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2021-2025 community-scripts ORG -# Author: MickLesk (Canbiz) -# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE -# Source: https://healthchecks.io/ - source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" color verb_ip6 @@ -16,43 +11,44 @@ update_os msg_info "Installing Dependencies" $STD apt install -y \ gcc \ + python3 \ + python3-dev \ + python3-venv \ libpq-dev \ libcurl4-openssl-dev \ libssl-dev \ caddy + +mkdir -p ~/.config/pip +cat > ~/.config/pip/pip.conf << EOF +[global] +break-system-packages = true +EOF msg_ok "Installed Dependencies" -PYTHON_VERSION="3.13" setup_uv PG_VERSION=16 setup_postgresql +PG_DB_NAME="healthchecks_db" PG_DB_USER="hc_user" PG_DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) setup_postgresql_db -msg_info "Setup Database" -DB_NAME=healthchecks_db -DB_USER=hc_user -DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) +msg_info "Setup Keys (Admin / Secret)" SECRET_KEY="$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)" ADMIN_EMAIL="admin@helper-scripts.local" ADMIN_PASSWORD="$DB_PASS" -$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" -$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;" -$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';" -$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';" -$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'" { - echo "healthchecks-Credentials" - echo "healthchecks Database User: $DB_USER" - echo "healthchecks Database Password: $DB_PASS" - echo "healthchecks Database Name: $DB_NAME" echo "healthchecks Admin Email: $ADMIN_EMAIL" echo "healthchecks Admin Password: $ADMIN_PASSWORD" } >>~/healthchecks.creds -msg_ok "Set up Database" +msg_ok "Set up Keys" fetch_and_deploy_gh_release "healthchecks" "healthchecks/healthchecks" -msg_info "Setup healthchecks" +msg_info "Installing Healthchecks (venv)" cd /opt/healthchecks -mkdir -p /opt/healthchecks/static-collected/ -$STD uv pip install wheel gunicorn -r requirements.txt --system +python3 -m venv venv +source venv/bin/activate + +$STD pip install --upgrade pip wheel +$STD pip install gunicorn -r requirements.txt +msg_ok "Installed Python packages" LOCAL_IP=$(hostname -I | awk '{print $1}') cat </opt/healthchecks/hc/local_settings.py @@ -83,18 +79,19 @@ DATABASES = { } EOF -$STD uv run -- python manage.py makemigrations -$STD uv run -- python manage.py migrate --noinput -$STD uv run -- python manage.py collectstatic --noinput -$STD uv run -- python manage.py compress +msg_info "Running Django setup" +$STD python manage.py makemigrations +$STD python manage.py migrate --noinput +$STD python manage.py collectstatic --noinput +$STD python manage.py compress -cat </etc/caddy/Caddyfile @@ -108,7 +105,7 @@ ${LOCAL_IP} { EOF msg_ok "Configured Caddy" -msg_info "Creating Service" +msg_info "Creating systemd service" cat </etc/systemd/system/healthchecks.service [Unit] Description=Healthchecks Service @@ -116,12 +113,13 @@ After=network.target postgresql.service [Service] WorkingDirectory=/opt/healthchecks/ -ExecStart=/usr/local/bin/uv run -- gunicorn hc.wsgi:application --bind 127.0.0.1:8000 +ExecStart=/opt/healthchecks/venv/bin/gunicorn hc.wsgi:application --bind 127.0.0.1:8000 Restart=always [Install] WantedBy=multi-user.target EOF + systemctl enable -q --now healthchecks caddy systemctl reload caddy msg_ok "Created Service" From 47cbdec2520e88d0759c70ac86898e956e7bfe90 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Sun, 16 Nov 2025 09:54:03 +0100 Subject: [PATCH 2/3] Enhance healthchecks update process with backup and venv Added backup creation for existing healthchecks installation before updating. Enhanced the update process by recreating the Python virtual environment and installing requirements. --- ct/healthchecks.sh | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/ct/healthchecks.sh b/ct/healthchecks.sh index a1912422b66..7955c8ad1e8 100644 --- a/ct/healthchecks.sh +++ b/ct/healthchecks.sh @@ -28,26 +28,42 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi + if check_for_gh_release "healthchecks" "healthchecks/healthchecks"; then msg_info "Stopping Services" systemctl stop healthchecks msg_ok "Stopped Services" - PYTHON_VERSION="3.13" setup_uv + msg_info "Backing up existing installation" + BACKUP="/opt/healthchecks-backup-$(date +%F-%H%M)" + cp -a /opt/healthchecks "$BACKUP" + msg_ok "Backup created at $BACKUP" + fetch_and_deploy_gh_release "healthchecks" "healthchecks/healthchecks" - msg_info "Updating healthchecks" cd /opt/healthchecks - mkdir -p /opt/healthchecks/static-collected/ - $STD uv pip install wheel gunicorn -r requirements.txt --system - $STD uv run -- python manage.py makemigrations - $STD uv run -- python manage.py migrate --noinput - $STD uv run -- python manage.py collectstatic --noinput - $STD uv run -- python manage.py compress - msg_ok "Updated healthchecks" + if [[ -d venv ]]; then + rm -rf venv + fi + msg_info "Recreating Python venv" + $STD python3 -m venv venv + $STD source venv/bin/activate + $STD pip install --upgrade pip wheel + msg_ok "Created venv" + + msg_info "Installing requirements" + $STD pip install gunicorn -r requirements.txt + msg_ok "Installed requirements" + + msg_info "Running Django migrations" + $STD python manage.py migrate --noinput + $STD python manage.py collectstatic --noinput + $STD python manage.py compress + msg_ok "Completed Django migrations and static build" + msg_info "Starting Services" systemctl start healthchecks - systemctl restart caddy + systemctl reload caddy msg_ok "Started Services" msg_ok "Updated successfully!" fi From d2f61af1298a999bdddc981131057169710a5f9c Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Sun, 16 Nov 2025 09:54:57 +0100 Subject: [PATCH 3/3] - Added copyright, author, and license information. --- install/healthchecks-install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/install/healthchecks-install.sh b/install/healthchecks-install.sh index bdd8d397c10..f2784979732 100644 --- a/install/healthchecks-install.sh +++ b/install/healthchecks-install.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +# Copyright (c) 2021-2025 community-scripts ORG +# Author: MickLesk (Canbiz) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://healthchecks.io/ source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" color