Skip to content

Commit 7f28f12

Browse files
authored
Refactor: Healthchecks
1 parent 5cc11c2 commit 7f28f12

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

install/healthchecks-install.sh

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# Copyright (c) 2021-2025 community-scripts ORG
4-
# Author: MickLesk (Canbiz)
5-
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6-
# Source: https://healthchecks.io/
7-
83
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
94
color
105
verb_ip6
@@ -16,43 +11,44 @@ update_os
1611
msg_info "Installing Dependencies"
1712
$STD apt install -y \
1813
gcc \
14+
python3 \
15+
python3-dev \
16+
python3-venv \
1917
libpq-dev \
2018
libcurl4-openssl-dev \
2119
libssl-dev \
2220
caddy
21+
22+
mkdir -p ~/.config/pip
23+
cat > ~/.config/pip/pip.conf << EOF
24+
[global]
25+
break-system-packages = true
26+
EOF
2327
msg_ok "Installed Dependencies"
2428

25-
PYTHON_VERSION="3.13" setup_uv
2629
PG_VERSION=16 setup_postgresql
30+
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
2731

28-
msg_info "Setup Database"
29-
DB_NAME=healthchecks_db
30-
DB_USER=hc_user
31-
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
32+
msg_info "Setup Keys (Admin / Secret)"
3233
SECRET_KEY="$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)"
3334
ADMIN_EMAIL="[email protected]"
3435
ADMIN_PASSWORD="$DB_PASS"
35-
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
36-
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
37-
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';"
38-
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';"
39-
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'"
4036
{
41-
echo "healthchecks-Credentials"
42-
echo "healthchecks Database User: $DB_USER"
43-
echo "healthchecks Database Password: $DB_PASS"
44-
echo "healthchecks Database Name: $DB_NAME"
4537
echo "healthchecks Admin Email: $ADMIN_EMAIL"
4638
echo "healthchecks Admin Password: $ADMIN_PASSWORD"
4739
} >>~/healthchecks.creds
48-
msg_ok "Set up Database"
40+
msg_ok "Set up Keys"
4941

5042
fetch_and_deploy_gh_release "healthchecks" "healthchecks/healthchecks"
5143

52-
msg_info "Setup healthchecks"
44+
msg_info "Installing Healthchecks (venv)"
5345
cd /opt/healthchecks
54-
mkdir -p /opt/healthchecks/static-collected/
55-
$STD uv pip install wheel gunicorn -r requirements.txt --system
46+
python3 -m venv venv
47+
source venv/bin/activate
48+
49+
$STD pip install --upgrade pip wheel
50+
$STD pip install gunicorn -r requirements.txt
51+
msg_ok "Installed Python packages"
5652

5753
LOCAL_IP=$(hostname -I | awk '{print $1}')
5854
cat <<EOF >/opt/healthchecks/hc/local_settings.py
@@ -83,18 +79,19 @@ DATABASES = {
8379
}
8480
EOF
8581

86-
$STD uv run -- python manage.py makemigrations
87-
$STD uv run -- python manage.py migrate --noinput
88-
$STD uv run -- python manage.py collectstatic --noinput
89-
$STD uv run -- python manage.py compress
82+
msg_info "Running Django setup"
83+
$STD python manage.py makemigrations
84+
$STD python manage.py migrate --noinput
85+
$STD python manage.py collectstatic --noinput
86+
$STD python manage.py compress
9087

91-
cat <<EOF | $STD uv run -- python manage.py shell
88+
python <<EOF
9289
from django.contrib.auth import get_user_model
9390
User = get_user_model()
9491
if not User.objects.filter(email="${ADMIN_EMAIL}").exists():
9592
User.objects.create_superuser("${ADMIN_EMAIL}", "${ADMIN_EMAIL}", "${ADMIN_PASSWORD}")
9693
EOF
97-
msg_ok "Installed healthchecks"
94+
msg_ok "Configured Django"
9895

9996
msg_info "Configuring Caddy"
10097
cat <<EOF >/etc/caddy/Caddyfile
@@ -108,20 +105,21 @@ ${LOCAL_IP} {
108105
EOF
109106
msg_ok "Configured Caddy"
110107

111-
msg_info "Creating Service"
108+
msg_info "Creating systemd service"
112109
cat <<EOF >/etc/systemd/system/healthchecks.service
113110
[Unit]
114111
Description=Healthchecks Service
115112
After=network.target postgresql.service
116113
117114
[Service]
118115
WorkingDirectory=/opt/healthchecks/
119-
ExecStart=/usr/local/bin/uv run -- gunicorn hc.wsgi:application --bind 127.0.0.1:8000
116+
ExecStart=/opt/healthchecks/venv/bin/gunicorn hc.wsgi:application --bind 127.0.0.1:8000
120117
Restart=always
121118
122119
[Install]
123120
WantedBy=multi-user.target
124121
EOF
122+
125123
systemctl enable -q --now healthchecks caddy
126124
systemctl reload caddy
127125
msg_ok "Created Service"

0 commit comments

Comments
 (0)