From 2524dd1af782cce9f76f622dc04fa794b2b8013a Mon Sep 17 00:00:00 2001 From: Tobias <96661824+CrazyWolf13@users.noreply.github.com> Date: Sun, 14 Dec 2025 23:56:45 +0100 Subject: [PATCH] refactor: homarr (#9948) --- ct/homarr.sh | 145 +++++++------------------------ frontend/public/json/homarr.json | 4 +- install/homarr-install.sh | 77 ++++++---------- 3 files changed, 57 insertions(+), 169 deletions(-) diff --git a/ct/homarr.sh b/ct/homarr.sh index 7aaec51880..7196194cda 100644 --- a/ct/homarr.sh +++ b/ct/homarr.sh @@ -1,21 +1,20 @@ #!/usr/bin/env bash source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) # Copyright (c) 2021-2025 community-scripts ORG -# Author: CrazyWolf13 +# Author: MickLesk (CanbiZ) | Co-Author: CrazyWolf13 # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: https://homarr.dev/ APP="homarr" var_tags="${var_tags:-arr;dashboard}" -var_cpu="${var_cpu:-3}" -var_ram="${var_ram:-6144}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-1024}" var_disk="${var_disk:-8}" var_os="${var_os:-debian}" var_version="${var_version:-13}" var_unprivileged="${var_unprivileged:-1}" header_info "$APP" - variables color catch_errors @@ -28,69 +27,33 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi - if [[ -f /opt/homarr/database/db.sqlite ]]; then - msg_error "Old Homarr detected due to existing database file (/opt/homarr/database/db.sqlite)." - msg_error "Update not supported. Refer to:" - msg_error " - https://github.com/community-scripts/ProxmoxVE/discussions/1551" - msg_error " - https://homarr.dev/docs/getting-started/after-the-installation/#importing-a-zip-from-version-before-100" - exit - fi - if [[ ! -f /opt/run_homarr.sh ]]; then - msg_info "Detected outdated and missing service files" - msg_error "Warning - The port of homarr changed from 3000 to 7575" - $STD apt-get install -y nginx gettext openssl gpg - sed -i '/^NODE_ENV=/d' /opt/homarr/.env && echo "NODE_ENV='production'" >>/opt/homarr/.env - sed -i '/^DB_DIALECT=/d' /opt/homarr/.env && echo "DB_DIALECT='sqlite'" >>/opt/homarr/.env - cat <<'EOF' >/opt/run_homarr.sh -#!/bin/bash -set -a -source /opt/homarr/.env -set +a -export DB_DIALECT='sqlite' -export AUTH_SECRET=$(openssl rand -base64 32) -export CRON_JOB_API_KEY=$(openssl rand -base64 32) -node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT -for dir in $(find /opt/homarr_db/migrations/migrations -mindepth 1 -maxdepth 1 -type d); do - dirname=$(basename "$dir") - mkdir -p "/opt/homarr_db/migrations/$dirname" - cp -r "$dir"/* "/opt/homarr_db/migrations/$dirname/" 2>/dev/null || true -done -export HOSTNAME=$(ip route get 1.1.1.1 | grep -oP 'src \K[^ ]+') -envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf -nginx -g 'daemon off;' & -redis-server /opt/homarr/packages/redis/redis.conf & -node apps/tasks/tasks.cjs & -node apps/websocket/wssServer.cjs & -node apps/nextjs/server.js & PID=$! -wait $PID -EOF - chmod +x /opt/run_homarr.sh - rm /etc/systemd/system/homarr.service - cat </etc/systemd/system/homarr.service -[Unit] -Description=Homarr Service -After=network.target -[Service] -Type=exec -WorkingDirectory=/opt/homarr -EnvironmentFile=-/opt/homarr/.env -ExecStart=/opt/run_homarr.sh -[Install] -WantedBy=multi-user.target -EOF - msg_ok "Updated Services" - systemctl daemon-reload - fi if check_for_gh_release "homarr" "homarr-labs/homarr"; then msg_info "Stopping Services (Patience)" systemctl stop homarr + systemctl stop redis-server msg_ok "Services Stopped" - msg_info "Backup Data" - mkdir -p /opt/homarr-data-backup - cp /opt/homarr/.env /opt/homarr-data-backup/.env - msg_ok "Backup Data" + if ! { grep -q '^REDIS_IS_EXTERNAL=' /opt/homarr/.env 2>/dev/null || grep -q '^REDIS_IS_EXTERNAL=' /opt/homarr.env 2>/dev/null; }; then + msg_info "Fixing old structure" + # fix musl issues because homarr compiles on alpine not debian soure: https://github.com/alexander-akhmetov/python-telegram/issues/3 + $STD apt install -y musl-dev + ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1 + cp /opt/homarr/.env /opt/homarr.env + echo "REDIS_IS_EXTERNAL='true'" >> /opt/homarr.env + sed -i 's|^ExecStart=.*|ExecStart=/opt/homarr/run.sh|' /etc/systemd/system/homarr.service + sed -i 's|^EnvironmentFile=.*|EnvironmentFile=-/opt/homarr.env|' /etc/systemd/system/homarr.service + chown -R redis:redis /appdata/redis + chmod 744 /appdata/redis + mkdir -p /etc/systemd/system/redis-server.service.d/ + cat </etc/systemd/system/redis-server.service.d/override.conf +[Service] +ReadWritePaths=-/appdata/redis -/var/lib/redis -/var/log/redis -/var/run/redis -/etc/redis +EOF + systemctl daemon-reload + rm /opt/run_homarr.sh + msg_ok "Fixed old structure" + fi msg_info "Updating Nodejs" $STD apt update @@ -98,69 +61,21 @@ EOF msg_ok "Updated Nodejs" NODE_VERSION=$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.engines.node | split(">=")[1] | split(".")[0]') - NODE_MODULE="pnpm@$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.packageManager | split("@")[1]')" setup_nodejs + CLEAN_INSTALL=1 fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" "prebuild" "latest" "/opt/homarr" "build-amd64.tar.gz" - rm -rf /opt/homarr - fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" - - msg_info "Updating and rebuilding ${APP} (Patience)" - rm /opt/run_homarr.sh - cat <<'EOF' >/opt/run_homarr.sh -#!/bin/bash -set -a -source /opt/homarr/.env -set +a -export DB_DIALECT='sqlite' -export AUTH_SECRET=$(openssl rand -base64 32) -export CRON_JOB_API_KEY=$(openssl rand -base64 32) -node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT -for dir in $(find /opt/homarr_db/migrations/migrations -mindepth 1 -maxdepth 1 -type d); do - dirname=$(basename "$dir") - mkdir -p "/opt/homarr_db/migrations/$dirname" - cp -r "$dir"/* "/opt/homarr_db/migrations/$dirname/" 2>/dev/null || true -done -export HOSTNAME=$(ip route get 1.1.1.1 | grep -oP 'src \K[^ ]+') -envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf -nginx -g 'daemon off;' & -redis-server /opt/homarr/packages/redis/redis.conf & -node apps/tasks/tasks.cjs & -node apps/websocket/wssServer.cjs & -node apps/nextjs/server.js & PID=$! -wait $PID -EOF - chmod +x /opt/run_homarr.sh - mv /opt/homarr-data-backup/.env /opt/homarr/.env - cd /opt/homarr - $STD pnpm install --recursive --frozen-lockfile --shamefully-hoist - $STD pnpm build - cp /opt/homarr/apps/nextjs/next.config.ts . - cp /opt/homarr/apps/nextjs/package.json . - cp -r /opt/homarr/packages/db/migrations /opt/homarr_db/migrations - cp -r /opt/homarr/apps/nextjs/.next/standalone/* /opt/homarr - mkdir -p /appdata/redis - cp /opt/homarr/packages/redis/redis.conf /opt/homarr/redis.conf + msg_info "Updating Homarr" + cp /opt/homarr/redis.conf /etc/redis/redis.conf rm /etc/nginx/nginx.conf - mkdir -p /etc/nginx/templates cp /opt/homarr/nginx.conf /etc/nginx/templates/nginx.conf - - mkdir -p /opt/homarr/apps/cli - cp /opt/homarr/packages/cli/cli.cjs /opt/homarr/apps/cli/cli.cjs - echo $'#!/bin/bash\ncd /opt/homarr/apps/cli && node ./cli.cjs "$@"' >/usr/bin/homarr - chmod +x /usr/bin/homarr - - mkdir /opt/homarr/build - cp ./node_modules/better-sqlite3/build/Release/better_sqlite3.node ./build/better_sqlite3.node - msg_ok "Updated ${APP}" + msg_ok "Updated Homarr" msg_info "Starting Services" + chmod +x /opt/homarr/run.sh systemctl start homarr + systemctl start redis-server msg_ok "Started Services" msg_ok "Updated successfully!" - read -p "${TAB3}It's recommended to reboot the LXC after an update, would you like to reboot the LXC now ? (y/n): " choice - if [[ "$choice" =~ ^[Yy]$ ]]; then - reboot - fi fi exit } diff --git a/frontend/public/json/homarr.json b/frontend/public/json/homarr.json index 6893d48497..21c1e67512 100644 --- a/frontend/public/json/homarr.json +++ b/frontend/public/json/homarr.json @@ -19,8 +19,8 @@ "type": "default", "script": "ct/homarr.sh", "resources": { - "cpu": 3, - "ram": 6144, + "cpu": 2, + "ram": 1024, "hdd": 8, "os": "debian", "version": "13" diff --git a/install/homarr-install.sh b/install/homarr-install.sh index 195c78cf72..c759081e93 100644 --- a/install/homarr-install.sh +++ b/install/homarr-install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Copyright (c) 2021-2025 community-scripts ORG -# Author: MickLesk (Canbiz) +# Author: MickLesk (CanbiZ) | Co-Author: CrazyWolf13 # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # Source: https://github.com/homarr-labs/homarr @@ -16,28 +16,24 @@ update_os msg_info "Installing Dependencies" $STD apt install -y \ redis-server \ - ca-certificates \ - make \ - g++ \ - build-essential \ nginx \ gettext \ - jq \ - openssl + openssl \ + musl-dev msg_ok "Installed Dependencies" NODE_VERSION=$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.engines.node | split(">=")[1] | split(".")[0]') -NODE_MODULE="pnpm@$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.packageManager | split("@")[1]')" setup_nodejs -fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" +fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" "prebuild" "latest" "/opt/homarr" "build-amd64.tar.gz" -msg_info "Installing Homarr (Patience)" -cd /opt +msg_info "Installing Homarr" +# fix musl issues because homarr compiles on alpine not debian soure: https://github.com/alexander-akhmetov/python-telegram/issues/3 +ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1 mkdir -p /opt/homarr_db touch /opt/homarr_db/db.sqlite SECRET_ENCRYPTION_KEY="$(openssl rand -hex 32)" cd /opt/homarr -cat </opt/homarr/.env +cat </opt/homarr.env DB_DRIVER='better-sqlite3' DB_DIALECT='sqlite' SECRET_ENCRYPTION_KEY='${SECRET_ENCRYPTION_KEY}' @@ -45,54 +41,28 @@ DB_URL='/opt/homarr_db/db.sqlite' TURBO_TELEMETRY_DISABLED=1 AUTH_PROVIDERS='credentials' NODE_ENV='production' +REDIS_IS_EXTERNAL='true' EOF -$STD pnpm install --recursive --frozen-lockfile --shamefully-hoist -$STD pnpm build msg_ok "Installed Homarr" -msg_info "Copying build and config files" -cp /opt/homarr/apps/nextjs/next.config.ts . -cp /opt/homarr/apps/nextjs/package.json . -cp -r /opt/homarr/packages/db/migrations /opt/homarr_db/migrations -cp -r /opt/homarr/apps/nextjs/.next/standalone/* /opt/homarr +msg_info "Copying config files" mkdir -p /appdata/redis -cp /opt/homarr/packages/redis/redis.conf /opt/homarr/redis.conf -mkdir -p /etc/nginx/templates +chown -R redis:redis /appdata/redis +chmod 744 /appdata/redis +cp /opt/homarr/redis.conf /etc/redis/redis.conf rm /etc/nginx/nginx.conf +mkdir -p /etc/nginx/templates cp /opt/homarr/nginx.conf /etc/nginx/templates/nginx.conf -mkdir -p /opt/homarr/apps/cli -cp /opt/homarr/packages/cli/cli.cjs /opt/homarr/apps/cli/cli.cjs echo $'#!/bin/bash\ncd /opt/homarr/apps/cli && node ./cli.cjs "$@"' >/usr/bin/homarr chmod +x /usr/bin/homarr -mkdir /opt/homarr/build -cp ./node_modules/better-sqlite3/build/Release/better_sqlite3.node ./build/better_sqlite3.node -msg_ok "Finished copying" +msg_ok "Copied config files" msg_info "Creating Services" -cat <<'EOF' >/opt/run_homarr.sh -#!/bin/bash -set -a -source /opt/homarr/.env -set +a -export DB_DIALECT='sqlite' -export AUTH_SECRET=$(openssl rand -base64 32) -export CRON_JOB_API_KEY=$(openssl rand -base64 32) -node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT -for dir in $(find /opt/homarr_db/migrations/migrations -mindepth 1 -maxdepth 1 -type d); do - dirname=$(basename "$dir") - mkdir -p "/opt/homarr_db/migrations/$dirname" - cp -r "$dir"/* "/opt/homarr_db/migrations/$dirname/" 2>/dev/null || true -done -export HOSTNAME=$(ip route get 1.1.1.1 | grep -oP 'src \K[^ ]+') -envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf -nginx -g 'daemon off;' & -redis-server /opt/homarr/packages/redis/redis.conf & -node apps/tasks/tasks.cjs & -node apps/websocket/wssServer.cjs & -node apps/nextjs/server.js & PID=$! -wait $PID +mkdir -p /etc/systemd/system/redis-server.service.d/ +cat </etc/systemd/system/redis-server.service.d/override.conf +[Service] +ReadWritePaths=-/appdata/redis -/var/lib/redis -/var/log/redis -/var/run/redis -/etc/redis EOF -chmod +x /opt/run_homarr.sh cat </etc/systemd/system/homarr.service [Unit] Description=Homarr Service @@ -101,14 +71,17 @@ After=network.target [Service] Type=exec WorkingDirectory=/opt/homarr -EnvironmentFile=-/opt/homarr/.env -ExecStart=/opt/run_homarr.sh +EnvironmentFile=-/opt/homarr.env +ExecStart=/opt/homarr/run.sh [Install] WantedBy=multi-user.target EOF +chmod +x /opt/homarr/run.sh +systemctl daemon-reload +systemctl enable -q --now redis-server && sleep 5 systemctl enable -q --now homarr -msg_ok "Created Service" +msg_ok "Created Services" motd_ssh customize