mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 10:52:22 +00:00
feat(post-install): rebuild Log2RAM with the journal and task logs kept on disk
This commit is contained in:
@@ -53,6 +53,9 @@ fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/global/pmx_journal.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/global/pmx_journal.sh"
|
||||
fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/global/log2ram_setup.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/global/log2ram_setup.sh"
|
||||
fi
|
||||
|
||||
load_language
|
||||
initialize_cache
|
||||
@@ -959,148 +962,18 @@ EOF
|
||||
|
||||
_update_existing_log2ram_auto() {
|
||||
local func_version="$1"
|
||||
local log2ram_bin=""
|
||||
local candidate resolved tmp_file
|
||||
pmx_journal_context "_update_existing_log2ram_auto" "$func_version"
|
||||
|
||||
msg_ok "$(translate "Log2RAM already registered — updating to latest configuration")"
|
||||
|
||||
for candidate in \
|
||||
"$(command -v log2ram 2>/dev/null)" \
|
||||
/usr/local/bin/log2ram \
|
||||
/usr/sbin/log2ram \
|
||||
/usr/bin/log2ram
|
||||
do
|
||||
[[ -n "$candidate" && -f "$candidate" ]] || continue
|
||||
resolved="$(readlink -f "$candidate" 2>/dev/null || printf '%s' "$candidate")"
|
||||
[[ -f "$resolved" ]] || continue
|
||||
log2ram_bin="$resolved"
|
||||
break
|
||||
done
|
||||
|
||||
if [[ -z "$log2ram_bin" || ! -f /etc/log2ram.conf ]]; then
|
||||
msg_error "$(translate "Log2RAM installation verification failed. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if grep -q 'rsync -aAXv ' "$log2ram_bin" 2>/dev/null; then
|
||||
[[ -e "${log2ram_bin}.proxmenux.bak" ]] || cp -a "$log2ram_bin" "${log2ram_bin}.proxmenux.bak"
|
||||
sed 's/rsync -aAXv /rsync -aXv --no-acls /g' "$log2ram_bin" | pmx_write_file "$log2ram_bin"
|
||||
fi
|
||||
|
||||
if pmx_log2ram_drop_stale_journal "$log2ram_bin"; then
|
||||
NECESSARY_REBOOT=1
|
||||
msg_ok "$(translate "Log2RAM keeps the journal in order from the next reboot")"
|
||||
fi
|
||||
|
||||
if dpkg-query -W -f='${Status}' proxmox-backup-server 2>/dev/null \
|
||||
| grep -q 'install ok installed'; then
|
||||
tmp_file="$(mktemp /etc/logrotate.d/.proxmox-backup-api.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
/var/log/proxmox-backup/api/access.log /var/log/proxmox-backup/api/auth.log {
|
||||
size 20M
|
||||
rotate 3
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
chmod 0644 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
pmx_write_file /etc/logrotate.d/proxmox-backup-api < "$tmp_file"
|
||||
rm -f "$tmp_file"
|
||||
|
||||
tmp_file="$(mktemp /etc/cron.hourly/.proxmox-backup-logrotate.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
#!/bin/sh
|
||||
/usr/sbin/logrotate /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0755 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
pmx_write_file /etc/cron.hourly/proxmox-backup-logrotate < "$tmp_file"
|
||||
chmod 0755 /etc/cron.hourly/proxmox-backup-logrotate
|
||||
chown root:root /etc/cron.hourly/proxmox-backup-logrotate
|
||||
rm -f "$tmp_file"
|
||||
msg_ok "$(translate "PBS API log rotation configured (hourly, size-based)")"
|
||||
fi
|
||||
|
||||
tmp_file="$(mktemp /usr/local/bin/.log2ram-check.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
# Watch /var/log usage on Log2RAM's tmpfs and act at two thresholds:
|
||||
# > 80% → vacuum journald down to ~30% of SIZE, then log2ram write
|
||||
# > 92% → aggressive: journal to ~5%, rotate PBS API logs if present,
|
||||
# truncate existing pveproxy/pveam logs, then log2ram write
|
||||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
|
||||
CONF_FILE="/etc/log2ram.conf"
|
||||
L2R_BIN="$(command -v log2ram || true)"
|
||||
[[ -z "$L2R_BIN" && -x /usr/sbin/log2ram ]] && L2R_BIN="/usr/sbin/log2ram"
|
||||
[[ -z "$L2R_BIN" ]] && exit 0
|
||||
|
||||
SIZE_MiB="$(grep -E '^SIZE=' "$CONF_FILE" 2>/dev/null | cut -d'=' -f2 | tr -dc '0-9')"
|
||||
[[ -z "$SIZE_MiB" ]] && SIZE_MiB=128
|
||||
LIMIT_BYTES=$(( SIZE_MiB * 1024 * 1024 ))
|
||||
WARN_BYTES=$(( LIMIT_BYTES * 80 / 100 ))
|
||||
EMERGENCY_BYTES=$(( LIMIT_BYTES * 92 / 100 ))
|
||||
|
||||
USED_BYTES="$(df -B1 --output=used /var/log 2>/dev/null | tail -1 | tr -dc '0-9')"
|
||||
[[ -z "$USED_BYTES" ]] && exit 0
|
||||
|
||||
LOCK="/run/log2ram-check.lock"
|
||||
exec 9>"$LOCK" 2>/dev/null || exit 0
|
||||
flock -n 9 || exit 0
|
||||
|
||||
if (( USED_BYTES > EMERGENCY_BYTES )); then
|
||||
SAFE_JOURNAL_MB=$(( SIZE_MiB * 5 / 100 ))
|
||||
[[ "$SAFE_JOURNAL_MB" -lt 16 ]] && SAFE_JOURNAL_MB=16
|
||||
journalctl --vacuum-size="${SAFE_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
if [[ -x /usr/sbin/logrotate && -f /etc/logrotate.d/proxmox-backup-api ]]; then
|
||||
/usr/sbin/logrotate -f /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1 || true
|
||||
fi
|
||||
[ -e /var/log/pveproxy/access.log ] && : > /var/log/pveproxy/access.log 2>/dev/null || true
|
||||
[ -e /var/log/pveproxy/error.log ] && : > /var/log/pveproxy/error.log 2>/dev/null || true
|
||||
[ -e /var/log/pveam.log ] && : > /var/log/pveam.log 2>/dev/null || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
elif (( USED_BYTES > WARN_BYTES )); then
|
||||
SOFT_JOURNAL_MB=$(( SIZE_MiB * 30 / 100 ))
|
||||
[[ "$SOFT_JOURNAL_MB" -lt 32 ]] && SOFT_JOURNAL_MB=32
|
||||
journalctl --vacuum-size="${SOFT_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
fi
|
||||
EOF
|
||||
chmod 0755 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
bash -n "$tmp_file" || return 1
|
||||
pmx_write_file /usr/local/bin/log2ram-check.sh < "$tmp_file"
|
||||
chmod 0755 /usr/local/bin/log2ram-check.sh
|
||||
chown root:root /usr/local/bin/log2ram-check.sh
|
||||
rm -f "$tmp_file"
|
||||
|
||||
tmp_file="$(mktemp /etc/cron.d/.log2ram-auto-sync.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
# Log2RAM auto-sync based on /var/log usage - Created by ProxMenux
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MAILTO=""
|
||||
# nice/ionice keep the check off the priority queue for scheduled tasks.
|
||||
3-59/10 * * * * root nice -n 19 ionice -c 3 /usr/local/bin/log2ram-check.sh >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
pmx_write_file /etc/cron.d/log2ram-auto-sync < "$tmp_file"
|
||||
chmod 0644 /etc/cron.d/log2ram-auto-sync
|
||||
chown root:root /etc/cron.d/log2ram-auto-sync
|
||||
rm -f "$tmp_file"
|
||||
|
||||
pmx_log2ram_setup "$(pmx_log2ram_current_size)" "$(pmx_log2ram_current_hours)" true || return 1
|
||||
NECESSARY_REBOOT=1
|
||||
register_tool "log2ram" true "$func_version"
|
||||
msg_success "$(translate "Log2RAM installation and configuration completed successfully.")"
|
||||
}
|
||||
|
||||
|
||||
install_log2ram_auto() {
|
||||
local FUNC_VERSION="1.8"
|
||||
local FUNC_VERSION="2.0"
|
||||
local existing_log2ram_bin=""
|
||||
pmx_journal_context "install_log2ram_auto" "$FUNC_VERSION"
|
||||
|
||||
@@ -1156,270 +1029,8 @@ install_log2ram_auto() {
|
||||
|
||||
fi # end first-time install block
|
||||
|
||||
msg_info "$(translate "Cleaning previous Log2RAM installation...")"
|
||||
|
||||
pmx_disable_service log2ram || true
|
||||
pmx_disable_service log2ram-daily.timer || true
|
||||
|
||||
local obsolete_path
|
||||
for obsolete_path in \
|
||||
/etc/cron.d/log2ram /etc/cron.d/log2ram-auto-sync \
|
||||
/etc/cron.hourly/log2ram /etc/cron.daily/log2ram \
|
||||
/etc/cron.weekly/log2ram /etc/cron.monthly/log2ram \
|
||||
/usr/local/bin/log2ram-check.sh /usr/local/bin/log2ram /usr/sbin/log2ram \
|
||||
/etc/systemd/system/log2ram.service \
|
||||
/etc/systemd/system/log2ram-daily.timer \
|
||||
/etc/systemd/system/log2ram-daily.service \
|
||||
/etc/systemd/system/sysinit.target.wants/log2ram.service \
|
||||
/etc/log2ram.conf /etc/log2ram.conf.* /etc/logrotate.d/log2ram
|
||||
do
|
||||
pmx_remove_file "$obsolete_path" 2>/dev/null || true
|
||||
done
|
||||
rm -rf /etc/systemd/system/log2ram.service.d 2>/dev/null || true
|
||||
rm -rf /var/log.hdd /tmp/log2ram 2>/dev/null || true
|
||||
|
||||
systemctl daemon-reexec >/dev/null 2>&1 || true
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
systemctl restart cron >/dev/null 2>&1 || true
|
||||
|
||||
msg_ok "$(translate "Previous installation cleaned")"
|
||||
msg_info "$(translate "Installing Log2RAM from source...")"
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
apt-get update -qq >/dev/null 2>&1
|
||||
pmx_install_pkg git
|
||||
fi
|
||||
|
||||
rm -rf /tmp/log2ram 2>/dev/null || true
|
||||
if ! git clone --depth 1 https://github.com/azlux/log2ram.git /tmp/log2ram >/dev/null 2>>/tmp/log2ram_install.log; then
|
||||
msg_error "$(translate "Failed to clone log2ram repository. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd /tmp/log2ram || { msg_error "$(translate "Failed to access log2ram directory")"; return 1; }
|
||||
|
||||
if ! bash install.sh >>/tmp/log2ram_install.log 2>&1; then
|
||||
msg_error "$(translate "Failed to run log2ram installer. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Drop ACL preservation from the upstream rsync call: some
|
||||
# /var/log.hdd filesystems reject POSIX ACLs and log2ram write
|
||||
# exits 23 with `set_acl: Operation not supported`. xattrs stay.
|
||||
local _l2r_bin
|
||||
for _l2r_bin in \
|
||||
"$(command -v log2ram 2>/dev/null)" \
|
||||
/usr/local/bin/log2ram \
|
||||
/usr/sbin/log2ram \
|
||||
/usr/bin/log2ram
|
||||
do
|
||||
[[ -n "$_l2r_bin" && -f "$_l2r_bin" ]] || continue
|
||||
if grep -q 'rsync -aAXv ' "$_l2r_bin" 2>/dev/null; then
|
||||
cp -a "$_l2r_bin" "${_l2r_bin}.proxmenux.bak"
|
||||
pmx_edit_file "$_l2r_bin" 's/rsync -aAXv /rsync -aXv --no-acls /g'
|
||||
fi
|
||||
pmx_log2ram_drop_stale_journal "$_l2r_bin" || true
|
||||
break
|
||||
done
|
||||
|
||||
# Size-based rotation for the PBS API logs — the upstream package
|
||||
# ships no logrotate rule and pvestatd's local-datastore poll fills
|
||||
# them fast enough to saturate a tmpfs /var/log.
|
||||
if dpkg-query -W -f='${Status}' proxmox-backup-server 2>/dev/null \
|
||||
| grep -q 'install ok installed'; then
|
||||
mkdir -p /var/log/proxmox-backup/api 2>/dev/null || true
|
||||
pmx_write_file /etc/logrotate.d/proxmox-backup-api <<'EOF'
|
||||
/var/log/proxmox-backup/api/access.log /var/log/proxmox-backup/api/auth.log {
|
||||
size 20M
|
||||
rotate 3
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
chmod 0644 /etc/logrotate.d/proxmox-backup-api
|
||||
chown root:root /etc/logrotate.d/proxmox-backup-api
|
||||
pmx_write_file /etc/cron.hourly/proxmox-backup-logrotate <<'EOF'
|
||||
#!/bin/sh
|
||||
/usr/sbin/logrotate /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0755 /etc/cron.hourly/proxmox-backup-logrotate
|
||||
chown root:root /etc/cron.hourly/proxmox-backup-logrotate
|
||||
msg_ok "$(translate "PBS API log rotation configured (hourly, size-based)")"
|
||||
fi
|
||||
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
|
||||
if [[ -f /etc/log2ram.conf ]] && command -v log2ram >/dev/null 2>&1; then
|
||||
msg_ok "$(translate "Log2RAM installed successfully")"
|
||||
else
|
||||
msg_error "$(translate "Log2RAM installation verification failed. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
RAM_SIZE_GB=$(awk '/^MemTotal:/{print int($2/1024/1024)}' /proc/meminfo)
|
||||
[[ -z "$RAM_SIZE_GB" || "$RAM_SIZE_GB" -eq 0 ]] && RAM_SIZE_GB=4
|
||||
|
||||
if (( RAM_SIZE_GB <= 8 )); then
|
||||
LOG2RAM_SIZE="128M"; CRON_HOURS=1
|
||||
elif (( RAM_SIZE_GB <= 16 )); then
|
||||
LOG2RAM_SIZE="256M"; CRON_HOURS=3
|
||||
else
|
||||
LOG2RAM_SIZE="512M"; CRON_HOURS=6
|
||||
fi
|
||||
|
||||
msg_ok "$(translate "Detected RAM:") $RAM_SIZE_GB GB — $(translate "Log2RAM size set to:") $LOG2RAM_SIZE"
|
||||
pmx_edit_file /etc/log2ram.conf "s/^SIZE=.*/SIZE=$LOG2RAM_SIZE/"
|
||||
|
||||
LOG2RAM_BIN="$(command -v log2ram || echo /usr/sbin/log2ram)"
|
||||
|
||||
pmx_write_file /etc/cron.d/log2ram <<EOF
|
||||
# Log2RAM periodic sync - Created by ProxMenux
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MAILTO=""
|
||||
0 */$CRON_HOURS * * * root $LOG2RAM_BIN write >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 /etc/cron.d/log2ram
|
||||
chown root:root /etc/cron.d/log2ram
|
||||
msg_ok "$(translate "Log2RAM write scheduled every") $CRON_HOURS $(translate "hour(s)")"
|
||||
|
||||
pmx_write_file /usr/local/bin/log2ram-check.sh <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
# Watch /var/log usage on Log2RAM's tmpfs and act at two thresholds:
|
||||
# > 80% → vacuum journald down to ~30% of SIZE, then log2ram write
|
||||
# > 92% → aggressive: journal to ~5%, rotate PBS API logs if present,
|
||||
# truncate pveproxy/pveam, then log2ram write
|
||||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
|
||||
CONF_FILE="/etc/log2ram.conf"
|
||||
L2R_BIN="$(command -v log2ram || true)"
|
||||
[[ -z "$L2R_BIN" && -x /usr/sbin/log2ram ]] && L2R_BIN="/usr/sbin/log2ram"
|
||||
[[ -z "$L2R_BIN" ]] && exit 0
|
||||
|
||||
SIZE_MiB="$(grep -E '^SIZE=' "$CONF_FILE" 2>/dev/null | cut -d'=' -f2 | tr -dc '0-9')"
|
||||
[[ -z "$SIZE_MiB" ]] && SIZE_MiB=128
|
||||
LIMIT_BYTES=$(( SIZE_MiB * 1024 * 1024 ))
|
||||
WARN_BYTES=$(( LIMIT_BYTES * 80 / 100 ))
|
||||
EMERGENCY_BYTES=$(( LIMIT_BYTES * 92 / 100 ))
|
||||
|
||||
USED_BYTES="$(df -B1 --output=used /var/log 2>/dev/null | tail -1 | tr -dc '0-9')"
|
||||
[[ -z "$USED_BYTES" ]] && exit 0
|
||||
|
||||
LOCK="/run/log2ram-check.lock"
|
||||
exec 9>"$LOCK" 2>/dev/null || exit 0
|
||||
flock -n 9 || exit 0
|
||||
|
||||
if (( USED_BYTES > EMERGENCY_BYTES )); then
|
||||
SAFE_JOURNAL_MB=$(( SIZE_MiB * 5 / 100 ))
|
||||
[[ "$SAFE_JOURNAL_MB" -lt 16 ]] && SAFE_JOURNAL_MB=16
|
||||
journalctl --vacuum-size="${SAFE_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
if [[ -x /usr/sbin/logrotate && -f /etc/logrotate.d/proxmox-backup-api ]]; then
|
||||
/usr/sbin/logrotate -f /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1 || true
|
||||
fi
|
||||
# Only truncate if the file already exists. Creating one from
|
||||
# this cron path (running as root, default umask) would leave
|
||||
# it as root:root 644 — pveproxy runs as www-data and would then
|
||||
# fail to reopen it on the next restart, taking :8006 down.
|
||||
[ -e /var/log/pveproxy/access.log ] && : > /var/log/pveproxy/access.log 2>/dev/null || true
|
||||
[ -e /var/log/pveproxy/error.log ] && : > /var/log/pveproxy/error.log 2>/dev/null || true
|
||||
[ -e /var/log/pveam.log ] && : > /var/log/pveam.log 2>/dev/null || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
elif (( USED_BYTES > WARN_BYTES )); then
|
||||
SOFT_JOURNAL_MB=$(( SIZE_MiB * 30 / 100 ))
|
||||
[[ "$SOFT_JOURNAL_MB" -lt 32 ]] && SOFT_JOURNAL_MB=32
|
||||
journalctl --vacuum-size="${SOFT_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
fi
|
||||
EOF
|
||||
chmod +x /usr/local/bin/log2ram-check.sh
|
||||
|
||||
pmx_write_file /etc/cron.d/log2ram-auto-sync <<'EOF'
|
||||
# Log2RAM auto-sync based on /var/log usage - Created by ProxMenux
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MAILTO=""
|
||||
# nice/ionice keep the check off the priority queue for scheduled tasks.
|
||||
3-59/10 * * * * root nice -n 19 ionice -c 3 /usr/local/bin/log2ram-check.sh >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 /etc/cron.d/log2ram-auto-sync
|
||||
chown root:root /etc/cron.d/log2ram-auto-sync
|
||||
|
||||
systemctl restart cron >/dev/null 2>&1 || true
|
||||
msg_ok "$(translate "Auto-sync enabled when /var/log exceeds 80% of") $LOG2RAM_SIZE"
|
||||
|
||||
|
||||
msg_info "$(translate "Adjusting systemd-journald limits to match Log2RAM size...")"
|
||||
|
||||
|
||||
if [[ -f /etc/systemd/journald.conf ]]; then
|
||||
cp -n /etc/systemd/journald.conf /etc/systemd/journald.conf.bak.$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
fi
|
||||
|
||||
SIZE_MB=$(echo "$LOG2RAM_SIZE" | tr -dc '0-9')
|
||||
|
||||
|
||||
USE_MB=$(( SIZE_MB * 55 / 100 ))
|
||||
KEEP_MB=$(( SIZE_MB * 10 / 100 ))
|
||||
RUNTIME_MB=$(( SIZE_MB * 25 / 100 ))
|
||||
|
||||
|
||||
[ "$USE_MB" -lt 80 ] && USE_MB=80
|
||||
[ "$RUNTIME_MB" -lt 32 ] && RUNTIME_MB=32
|
||||
[ "$KEEP_MB" -lt 8 ] && KEEP_MB=8
|
||||
|
||||
|
||||
# Compose the final file and write it once: keep everything above the
|
||||
# existing [Journal] section, then our block. Editing then appending
|
||||
# produced two journal entries for one file, each with half the diff;
|
||||
# one write shows the whole before/after a sysadmin should read.
|
||||
{
|
||||
sed '/^\[Journal\]/,$d' /etc/systemd/journald.conf 2>/dev/null
|
||||
cat <<EOF
|
||||
[Journal]
|
||||
Storage=persistent
|
||||
SplitMode=none
|
||||
RateLimitIntervalSec=30s
|
||||
RateLimitBurst=1000
|
||||
ForwardToSyslog=no
|
||||
ForwardToWall=no
|
||||
Seal=no
|
||||
Compress=yes
|
||||
SystemMaxUse=${USE_MB}M
|
||||
SystemKeepFree=${KEEP_MB}M
|
||||
RuntimeMaxUse=${RUNTIME_MB}M
|
||||
# MaxLevelStore=info: required for ProxMenux Monitor log display and Fail2Ban detection.
|
||||
# Using "warning" silently discards most system logs making date filters useless.
|
||||
MaxLevelStore=info
|
||||
MaxLevelSyslog=info
|
||||
MaxLevelKMsg=warning
|
||||
MaxLevelConsole=notice
|
||||
MaxLevelWall=crit
|
||||
EOF
|
||||
} | pmx_write_file /etc/systemd/journald.conf
|
||||
|
||||
|
||||
mkdir -p /var/log/pveproxy
|
||||
chown -R www-data:www-data /var/log/pveproxy
|
||||
chmod 0750 /var/log/pveproxy
|
||||
|
||||
mkdir -p /var/log.hdd/pveproxy
|
||||
chown -R www-data:www-data /var/log.hdd/pveproxy
|
||||
chmod 0750 /var/log.hdd/pveproxy
|
||||
|
||||
#msg_ok "$(translate "Backup created:") /etc/systemd/journald.conf.bak.$(date +%Y%m%d-%H%M%S)"
|
||||
msg_ok "$(translate "Journald configuration adjusted to") ${USE_MB}M (Log2RAM ${LOG2RAM_SIZE})"
|
||||
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
if ! pmx_apply_setting "service-enabled:log2ram" "systemctl is-enabled log2ram" \
|
||||
systemctl enable log2ram; then
|
||||
msg_error "$(translate "Log2RAM installation verification failed. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
pmx_log2ram_setup "$(pmx_log2ram_default_size)" "$(pmx_log2ram_default_hours)" true || return 1
|
||||
NECESSARY_REBOOT=1
|
||||
|
||||
register_tool "log2ram" true "$FUNC_VERSION"
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/global/pmx_journal.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/global/pmx_journal.sh"
|
||||
fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/global/log2ram_setup.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/global/log2ram_setup.sh"
|
||||
fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/post_install/zram_profile_helpers.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/post_install/zram_profile_helpers.sh"
|
||||
fi
|
||||
@@ -3287,134 +3290,22 @@ update_pve_appliance_manager() {
|
||||
|
||||
_update_existing_log2ram_custom() {
|
||||
local func_version="$1"
|
||||
local log2ram_bin=""
|
||||
local candidate resolved tmp_file
|
||||
local watch=false
|
||||
pmx_journal_context "_update_existing_log2ram_custom" "$func_version"
|
||||
|
||||
msg_ok "$(translate "Log2RAM already registered — updating to latest configuration")"
|
||||
|
||||
for candidate in \
|
||||
"$(command -v log2ram 2>/dev/null)" \
|
||||
/usr/local/bin/log2ram \
|
||||
/usr/sbin/log2ram \
|
||||
/usr/bin/log2ram
|
||||
do
|
||||
[[ -n "$candidate" && -f "$candidate" ]] || continue
|
||||
resolved="$(readlink -f "$candidate" 2>/dev/null || printf '%s' "$candidate")"
|
||||
[[ -f "$resolved" ]] || continue
|
||||
log2ram_bin="$resolved"
|
||||
break
|
||||
done
|
||||
|
||||
if [[ -z "$log2ram_bin" || ! -f /etc/log2ram.conf ]]; then
|
||||
msg_error "$(translate "Log2RAM installation verification failed. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if grep -q 'rsync -aAXv ' "$log2ram_bin" 2>/dev/null; then
|
||||
[[ -e "${log2ram_bin}.proxmenux.bak" ]] || cp -a "$log2ram_bin" "${log2ram_bin}.proxmenux.bak"
|
||||
sed 's/rsync -aAXv /rsync -aXv --no-acls /g' "$log2ram_bin" | pmx_write_file "$log2ram_bin"
|
||||
fi
|
||||
|
||||
if pmx_log2ram_drop_stale_journal "$log2ram_bin"; then
|
||||
NECESSARY_REBOOT=1
|
||||
msg_ok "$(translate "Log2RAM keeps the journal in order from the next reboot")"
|
||||
fi
|
||||
|
||||
if dpkg-query -W -f='${Status}' proxmox-backup-server 2>/dev/null \
|
||||
| grep -q 'install ok installed'; then
|
||||
tmp_file="$(mktemp /etc/logrotate.d/.proxmox-backup-api.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
/var/log/proxmox-backup/api/access.log /var/log/proxmox-backup/api/auth.log {
|
||||
size 20M
|
||||
rotate 3
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
chmod 0644 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
pmx_write_file /etc/logrotate.d/proxmox-backup-api < "$tmp_file"
|
||||
rm -f "$tmp_file"
|
||||
|
||||
tmp_file="$(mktemp /etc/cron.hourly/.proxmox-backup-logrotate.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
#!/bin/sh
|
||||
/usr/sbin/logrotate /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0755 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
pmx_write_file /etc/cron.hourly/proxmox-backup-logrotate < "$tmp_file"
|
||||
chmod 0755 /etc/cron.hourly/proxmox-backup-logrotate
|
||||
chown root:root /etc/cron.hourly/proxmox-backup-logrotate
|
||||
rm -f "$tmp_file"
|
||||
msg_ok "$(translate "PBS API log rotation configured (hourly, size-based)")"
|
||||
fi
|
||||
|
||||
if [[ -f /usr/local/bin/log2ram-check.sh ]]; then
|
||||
tmp_file="$(mktemp /usr/local/bin/.log2ram-check.XXXXXX)" || return 1
|
||||
cat > "$tmp_file" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
# Watch /var/log usage on Log2RAM's tmpfs and act at two thresholds:
|
||||
# > 80% → vacuum journald down to ~30% of SIZE, then log2ram write
|
||||
# > 92% → aggressive: journal to ~5%, rotate PBS API logs if present,
|
||||
# truncate existing pveproxy/pveam logs, then log2ram write
|
||||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
CONF_FILE="/etc/log2ram.conf"
|
||||
L2R_BIN="$(command -v log2ram || true)"
|
||||
[[ -z "$L2R_BIN" && -x /usr/sbin/log2ram ]] && L2R_BIN="/usr/sbin/log2ram"
|
||||
[[ -z "$L2R_BIN" ]] && exit 0
|
||||
|
||||
SIZE_MiB="$(grep -E '^SIZE=' "$CONF_FILE" 2>/dev/null | cut -d'=' -f2 | tr -dc '0-9')"
|
||||
[[ -z "$SIZE_MiB" ]] && SIZE_MiB=128
|
||||
LIMIT_BYTES=$(( SIZE_MiB * 1024 * 1024 ))
|
||||
WARN_BYTES=$(( LIMIT_BYTES * 80 / 100 ))
|
||||
EMERGENCY_BYTES=$(( LIMIT_BYTES * 92 / 100 ))
|
||||
|
||||
USED_BYTES="$(df -B1 --output=used /var/log 2>/dev/null | tail -1 | tr -dc '0-9')"
|
||||
[[ -z "$USED_BYTES" ]] && exit 0
|
||||
|
||||
LOCK="/run/log2ram-check.lock"
|
||||
exec 9>"$LOCK" 2>/dev/null || exit 0
|
||||
flock -n 9 || exit 0
|
||||
|
||||
if (( USED_BYTES > EMERGENCY_BYTES )); then
|
||||
SAFE_JOURNAL_MB=$(( SIZE_MiB * 5 / 100 ))
|
||||
[[ "$SAFE_JOURNAL_MB" -lt 16 ]] && SAFE_JOURNAL_MB=16
|
||||
journalctl --vacuum-size="${SAFE_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
if [[ -x /usr/sbin/logrotate && -f /etc/logrotate.d/proxmox-backup-api ]]; then
|
||||
/usr/sbin/logrotate -f /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1 || true
|
||||
fi
|
||||
[ -e /var/log/pveproxy/access.log ] && : > /var/log/pveproxy/access.log 2>/dev/null || true
|
||||
[ -e /var/log/pveproxy/error.log ] && : > /var/log/pveproxy/error.log 2>/dev/null || true
|
||||
[ -e /var/log/pveam.log ] && : > /var/log/pveam.log 2>/dev/null || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
elif (( USED_BYTES > WARN_BYTES )); then
|
||||
SOFT_JOURNAL_MB=$(( SIZE_MiB * 30 / 100 ))
|
||||
[[ "$SOFT_JOURNAL_MB" -lt 32 ]] && SOFT_JOURNAL_MB=32
|
||||
journalctl --vacuum-size="${SOFT_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
fi
|
||||
EOF
|
||||
chmod 0755 "$tmp_file"
|
||||
chown root:root "$tmp_file"
|
||||
bash -n "$tmp_file" || return 1
|
||||
pmx_write_file /usr/local/bin/log2ram-check.sh < "$tmp_file"
|
||||
chmod 0755 /usr/local/bin/log2ram-check.sh
|
||||
chown root:root /usr/local/bin/log2ram-check.sh
|
||||
rm -f "$tmp_file"
|
||||
fi
|
||||
|
||||
[[ -f /etc/cron.d/log2ram-auto-sync ]] && watch=true
|
||||
pmx_log2ram_setup "$(pmx_log2ram_current_size)" "$(pmx_log2ram_current_hours)" "$watch" || return 1
|
||||
NECESSARY_REBOOT=1
|
||||
register_tool "log2ram" true "$func_version"
|
||||
msg_success "$(translate "Log2RAM installation and configuration completed successfully.")"
|
||||
}
|
||||
|
||||
|
||||
configure_log2ram() {
|
||||
local FUNC_VERSION="1.8"
|
||||
local FUNC_VERSION="2.0"
|
||||
local existing_log2ram_bin=""
|
||||
local watch=false
|
||||
pmx_journal_context "configure_log2ram" "$FUNC_VERSION"
|
||||
# description: Install Log2RAM with a chosen size, sync interval and optional autosync. Updates preserve the size and autosync choice.
|
||||
|
||||
@@ -3429,7 +3320,6 @@ configure_log2ram() {
|
||||
msg_info2 "$(translate "Preparing Log2RAM configuration")"
|
||||
sleep 1
|
||||
|
||||
|
||||
RAM_SIZE_GB=$(awk '/^MemTotal:/{print int($2/1024/1024)}' /proc/meminfo)
|
||||
[[ -z "$RAM_SIZE_GB" || "$RAM_SIZE_GB" -eq 0 ]] && RAM_SIZE_GB=4
|
||||
|
||||
@@ -3467,254 +3357,12 @@ configure_log2ram() {
|
||||
"12" "$(translate "Every 12 hours")" OFF \
|
||||
3>&1 1>&2 2>&3) || return 0
|
||||
|
||||
|
||||
if whiptail --title "Log2RAM" --yesno "$(translate "Enable auto-sync if /var/log exceeds 90% of its size?")" 10 60; then
|
||||
ENABLE_AUTOSYNC=true
|
||||
else
|
||||
ENABLE_AUTOSYNC=false
|
||||
if whiptail --title "Log2RAM" --yesno "$(translate "Rotate and write /var/log to disk when it passes 85% of its size?")" 10 60; then
|
||||
watch=true
|
||||
fi
|
||||
|
||||
|
||||
msg_info "$(translate "Cleaning previous Log2RAM installation...")"
|
||||
pmx_disable_service log2ram || true
|
||||
pmx_disable_service log2ram-daily.timer || true
|
||||
|
||||
local obsolete_path
|
||||
for obsolete_path in \
|
||||
/etc/cron.d/log2ram /etc/cron.d/log2ram-auto-sync \
|
||||
/etc/cron.hourly/log2ram /etc/cron.daily/log2ram \
|
||||
/etc/cron.weekly/log2ram /etc/cron.monthly/log2ram \
|
||||
/usr/local/bin/log2ram-check.sh /usr/local/bin/log2ram /usr/sbin/log2ram \
|
||||
/etc/systemd/system/log2ram.service \
|
||||
/etc/systemd/system/log2ram-daily.timer \
|
||||
/etc/systemd/system/log2ram-daily.service \
|
||||
/etc/systemd/system/sysinit.target.wants/log2ram.service \
|
||||
/etc/log2ram.conf /etc/log2ram.conf.* /etc/logrotate.d/log2ram
|
||||
do
|
||||
pmx_remove_file "$obsolete_path" 2>/dev/null || true
|
||||
done
|
||||
rm -rf /etc/systemd/system/log2ram.service.d 2>/dev/null || true
|
||||
rm -rf /var/log.hdd /tmp/log2ram 2>/dev/null || true
|
||||
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
systemctl restart cron >/dev/null 2>&1 || true
|
||||
msg_ok "$(translate "Previous installation cleaned")"
|
||||
|
||||
|
||||
msg_info "$(translate "Installing Log2RAM from GitHub...")"
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
msg_info "$(translate "Installing required package: git")"
|
||||
apt-get update -qq >/dev/null 2>&1
|
||||
pmx_install_pkg git
|
||||
fi
|
||||
|
||||
rm -rf /tmp/log2ram 2>/dev/null || true
|
||||
if ! git clone --depth 1 https://github.com/azlux/log2ram.git /tmp/log2ram \
|
||||
>/dev/null 2>>/tmp/log2ram_install.log; then
|
||||
msg_error "$(translate "Failed to clone log2ram repository. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd /tmp/log2ram || { msg_error "$(translate "Failed to access log2ram directory")"; return 1; }
|
||||
if ! bash install.sh >>/tmp/log2ram_install.log 2>&1; then
|
||||
msg_error "$(translate "Failed to run log2ram installer. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Drop ACL preservation from the upstream rsync call: some
|
||||
# /var/log.hdd filesystems reject POSIX ACLs and log2ram write
|
||||
# exits 23 with `set_acl: Operation not supported`. xattrs stay.
|
||||
local _l2r_bin
|
||||
for _l2r_bin in \
|
||||
"$(command -v log2ram 2>/dev/null)" \
|
||||
/usr/local/bin/log2ram \
|
||||
/usr/sbin/log2ram \
|
||||
/usr/bin/log2ram
|
||||
do
|
||||
[[ -n "$_l2r_bin" && -f "$_l2r_bin" ]] || continue
|
||||
if grep -q 'rsync -aAXv ' "$_l2r_bin" 2>/dev/null; then
|
||||
cp -a "$_l2r_bin" "${_l2r_bin}.proxmenux.bak"
|
||||
pmx_edit_file "$_l2r_bin" 's/rsync -aAXv /rsync -aXv --no-acls /g'
|
||||
fi
|
||||
pmx_log2ram_drop_stale_journal "$_l2r_bin" || true
|
||||
break
|
||||
done
|
||||
|
||||
# Size-based rotation for the PBS API logs — the upstream package
|
||||
# ships no logrotate rule and pvestatd's local-datastore poll fills
|
||||
# them fast enough to saturate a tmpfs /var/log.
|
||||
if dpkg-query -W -f='${Status}' proxmox-backup-server 2>/dev/null \
|
||||
| grep -q 'install ok installed'; then
|
||||
mkdir -p /var/log/proxmox-backup/api 2>/dev/null || true
|
||||
pmx_write_file /etc/logrotate.d/proxmox-backup-api <<'EOF'
|
||||
/var/log/proxmox-backup/api/access.log /var/log/proxmox-backup/api/auth.log {
|
||||
size 20M
|
||||
rotate 3
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
chmod 0644 /etc/logrotate.d/proxmox-backup-api
|
||||
chown root:root /etc/logrotate.d/proxmox-backup-api
|
||||
pmx_write_file /etc/cron.hourly/proxmox-backup-logrotate <<'EOF'
|
||||
#!/bin/sh
|
||||
/usr/sbin/logrotate /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0755 /etc/cron.hourly/proxmox-backup-logrotate
|
||||
chown root:root /etc/cron.hourly/proxmox-backup-logrotate
|
||||
msg_ok "$(translate "PBS API log rotation configured (hourly, size-based)")"
|
||||
fi
|
||||
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
|
||||
if [[ -f /etc/log2ram.conf ]] && command -v log2ram >/dev/null 2>&1; then
|
||||
msg_ok "$(translate "Log2RAM installed successfully")"
|
||||
else
|
||||
msg_error "$(translate "Log2RAM installation verification failed. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
pmx_edit_file /etc/log2ram.conf "s/^SIZE=.*/SIZE=$LOG2RAM_SIZE/"
|
||||
LOG2RAM_BIN="$(command -v log2ram || echo /usr/sbin/log2ram)"
|
||||
|
||||
pmx_write_file /etc/cron.d/log2ram <<EOF
|
||||
# Log2RAM periodic sync - Created by ProxMenux
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MAILTO=""
|
||||
0 */$CRON_HOURS * * * root $LOG2RAM_BIN write >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 /etc/cron.d/log2ram
|
||||
chown root:root /etc/cron.d/log2ram
|
||||
msg_ok "$(translate "Log2RAM write scheduled every") $CRON_HOURS $(translate "hour(s)")"
|
||||
|
||||
|
||||
if [[ "$ENABLE_AUTOSYNC" == true ]]; then
|
||||
pmx_write_file /usr/local/bin/log2ram-check.sh <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
# Watch /var/log usage on Log2RAM's tmpfs and act at two thresholds:
|
||||
# > 80% → vacuum journald down to ~30% of SIZE, then log2ram write
|
||||
# > 92% → aggressive: journal to ~5%, rotate PBS API logs if present,
|
||||
# truncate existing pveproxy/pveam logs, then log2ram write
|
||||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
CONF_FILE="/etc/log2ram.conf"
|
||||
L2R_BIN="$(command -v log2ram || true)"
|
||||
[[ -z "$L2R_BIN" && -x /usr/sbin/log2ram ]] && L2R_BIN="/usr/sbin/log2ram"
|
||||
[[ -z "$L2R_BIN" ]] && exit 0
|
||||
|
||||
SIZE_MiB="$(grep -E '^SIZE=' "$CONF_FILE" 2>/dev/null | cut -d'=' -f2 | tr -dc '0-9')"
|
||||
[[ -z "$SIZE_MiB" ]] && SIZE_MiB=128
|
||||
LIMIT_BYTES=$(( SIZE_MiB * 1024 * 1024 ))
|
||||
WARN_BYTES=$(( LIMIT_BYTES * 80 / 100 ))
|
||||
EMERGENCY_BYTES=$(( LIMIT_BYTES * 92 / 100 ))
|
||||
|
||||
USED_BYTES="$(df -B1 --output=used /var/log 2>/dev/null | tail -1 | tr -dc '0-9')"
|
||||
[[ -z "$USED_BYTES" ]] && exit 0
|
||||
|
||||
LOCK="/run/log2ram-check.lock"
|
||||
exec 9>"$LOCK" 2>/dev/null || exit 0
|
||||
flock -n 9 || exit 0
|
||||
|
||||
if (( USED_BYTES > EMERGENCY_BYTES )); then
|
||||
SAFE_JOURNAL_MB=$(( SIZE_MiB * 5 / 100 ))
|
||||
[[ "$SAFE_JOURNAL_MB" -lt 16 ]] && SAFE_JOURNAL_MB=16
|
||||
journalctl --vacuum-size="${SAFE_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
if [[ -x /usr/sbin/logrotate && -f /etc/logrotate.d/proxmox-backup-api ]]; then
|
||||
/usr/sbin/logrotate -f /etc/logrotate.d/proxmox-backup-api >/dev/null 2>&1 || true
|
||||
fi
|
||||
[ -e /var/log/pveproxy/access.log ] && : > /var/log/pveproxy/access.log 2>/dev/null || true
|
||||
[ -e /var/log/pveproxy/error.log ] && : > /var/log/pveproxy/error.log 2>/dev/null || true
|
||||
[ -e /var/log/pveam.log ] && : > /var/log/pveam.log 2>/dev/null || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
elif (( USED_BYTES > WARN_BYTES )); then
|
||||
SOFT_JOURNAL_MB=$(( SIZE_MiB * 30 / 100 ))
|
||||
[[ "$SOFT_JOURNAL_MB" -lt 32 ]] && SOFT_JOURNAL_MB=32
|
||||
journalctl --vacuum-size="${SOFT_JOURNAL_MB}M" >/dev/null 2>&1 || true
|
||||
"$L2R_BIN" write 2>/dev/null || true
|
||||
fi
|
||||
EOF
|
||||
chmod +x /usr/local/bin/log2ram-check.sh
|
||||
|
||||
pmx_write_file /etc/cron.d/log2ram-auto-sync <<'EOF'
|
||||
# Log2RAM auto-sync based on /var/log usage - Created by ProxMenux
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
MAILTO=""
|
||||
# nice/ionice keep the check off the priority queue for scheduled tasks.
|
||||
3-59/10 * * * * root nice -n 19 ionice -c 3 /usr/local/bin/log2ram-check.sh >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 /etc/cron.d/log2ram-auto-sync
|
||||
chown root:root /etc/cron.d/log2ram-auto-sync
|
||||
msg_ok "$(translate "Auto-sync enabled when /var/log exceeds 80% of") $LOG2RAM_SIZE"
|
||||
else
|
||||
pmx_remove_file /usr/local/bin/log2ram-check.sh 2>/dev/null || true
|
||||
pmx_remove_file /etc/cron.d/log2ram-auto-sync 2>/dev/null || true
|
||||
msg_info2 "$(translate "Auto-sync was not enabled")"
|
||||
fi
|
||||
|
||||
# --- Ajuste de systemd-journald proporcional al tamaño de Log2RAM ---
|
||||
msg_info "$(translate "Adjusting systemd-journald limits to match Log2RAM size...")"
|
||||
|
||||
if [[ -f /etc/systemd/journald.conf ]]; then
|
||||
cp -n /etc/systemd/journald.conf "/etc/systemd/journald.conf.bak.$(date +%Y%m%d-%H%M%S)"
|
||||
BAK_OK=$?
|
||||
fi
|
||||
|
||||
SIZE_MB=$(echo "$LOG2RAM_SIZE" | tr -dc '0-9')
|
||||
# Repartos: 55% persistente / 10% libre / 25% runtime (pisos mínimos)
|
||||
USE_MB=$(( SIZE_MB * 55 / 100 ))
|
||||
KEEP_MB=$(( SIZE_MB * 10 / 100 ))
|
||||
RUNTIME_MB=$(( SIZE_MB * 25 / 100 ))
|
||||
[ "$USE_MB" -lt 80 ] && USE_MB=80
|
||||
[ "$RUNTIME_MB" -lt 32 ] && RUNTIME_MB=32
|
||||
[ "$KEEP_MB" -lt 8 ] && KEEP_MB=8
|
||||
|
||||
# Reescribir bloque [Journal] de forma segura
|
||||
pmx_edit_file /etc/systemd/journald.conf '/^\[Journal\]/,$d' 2>/dev/null || true
|
||||
pmx_append_file /etc/systemd/journald.conf <<EOF
|
||||
[Journal]
|
||||
Storage=persistent
|
||||
SplitMode=none
|
||||
RateLimitIntervalSec=30s
|
||||
RateLimitBurst=1000
|
||||
ForwardToSyslog=no
|
||||
ForwardToWall=no
|
||||
Seal=no
|
||||
Compress=yes
|
||||
SystemMaxUse=${USE_MB}M
|
||||
SystemKeepFree=${KEEP_MB}M
|
||||
RuntimeMaxUse=${RUNTIME_MB}M
|
||||
# MaxLevelStore=info: required for ProxMenux Monitor log display and Fail2Ban detection.
|
||||
# Using "warning" silently discards most system logs making date filters useless.
|
||||
MaxLevelStore=info
|
||||
MaxLevelSyslog=info
|
||||
MaxLevelKMsg=warning
|
||||
MaxLevelConsole=notice
|
||||
MaxLevelWall=crit
|
||||
EOF
|
||||
|
||||
[[ "$BAK_OK" = "0" ]] && msg_ok "$(translate "Backup created:") /etc/systemd/journald.conf.bak.$(date +%Y%m%d-%H%M%S)"
|
||||
msg_ok "$(translate "Journald configuration adjusted to") ${USE_MB}M (Log2RAM ${LOG2RAM_SIZE})"
|
||||
|
||||
mkdir -p /var/log/pveproxy
|
||||
chown -R www-data:www-data /var/log/pveproxy
|
||||
chmod 0750 /var/log/pveproxy
|
||||
|
||||
mkdir -p /var/log.hdd/pveproxy
|
||||
chown -R www-data:www-data /var/log.hdd/pveproxy
|
||||
chmod 0750 /var/log.hdd/pveproxy
|
||||
|
||||
systemctl restart cron >/dev/null 2>&1 || true
|
||||
if ! pmx_apply_setting "service-enabled:log2ram" "systemctl is-enabled log2ram" \
|
||||
systemctl enable log2ram; then
|
||||
msg_error "$(translate "Log2RAM installation verification failed. Check /tmp/log2ram_install.log")"
|
||||
return 1
|
||||
fi
|
||||
pmx_log2ram_setup "$USER_SIZE" "$CRON_HOURS" "$watch" || return 1
|
||||
NECESSARY_REBOOT=1
|
||||
|
||||
msg_success "$(translate "Log2RAM installation and configuration completed successfully.")"
|
||||
register_tool "log2ram" true "$FUNC_VERSION"
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/global/pmx_journal.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/global/pmx_journal.sh"
|
||||
fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/global/log2ram_setup.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/global/log2ram_setup.sh"
|
||||
fi
|
||||
if [[ -f "$LOCAL_SCRIPTS/post_install/zram_profile_helpers.sh" ]]; then
|
||||
source "$LOCAL_SCRIPTS/post_install/zram_profile_helpers.sh"
|
||||
fi
|
||||
@@ -735,74 +738,9 @@ uninstall_bashrc_custom() {
|
||||
################################################################
|
||||
|
||||
uninstall_log2ram() {
|
||||
msg_info "$(translate "Uninstalling log2ram (all versions)...")"
|
||||
|
||||
systemctl stop log2ram log2ram-daily.timer log2ram-daily.service >/dev/null 2>&1 || true
|
||||
systemctl disable log2ram log2ram-daily.timer log2ram-daily.service >/dev/null 2>&1 || true
|
||||
|
||||
rm -f /etc/cron.d/log2ram \
|
||||
/etc/cron.d/log2ram-auto-sync \
|
||||
/etc/cron.d/log2ram-sync \
|
||||
/etc/cron.hourly/log2ram \
|
||||
/etc/cron.daily/log2ram \
|
||||
/etc/cron.weekly/log2ram \
|
||||
/etc/cron.monthly/log2ram 2>/dev/null || true
|
||||
|
||||
rm -f /usr/local/bin/log2ram-check.sh \
|
||||
/usr/local/bin/log2ram \
|
||||
/usr/local/bin/log2ram-sync \
|
||||
/usr/sbin/log2ram \
|
||||
/usr/bin/log2ram 2>/dev/null || true
|
||||
|
||||
rm -f /etc/systemd/system/log2ram.service \
|
||||
/etc/systemd/system/log2ram-daily.timer \
|
||||
/etc/systemd/system/log2ram-daily.service \
|
||||
/etc/systemd/system/sysinit.target.wants/log2ram.service \
|
||||
/etc/systemd/system/timers.target.wants/log2ram-daily.timer \
|
||||
/lib/systemd/system/log2ram.service \
|
||||
/lib/systemd/system/log2ram-daily.timer \
|
||||
/lib/systemd/system/log2ram-daily.service 2>/dev/null || true
|
||||
rm -rf /etc/systemd/system/log2ram.service.d 2>/dev/null || true
|
||||
|
||||
rm -f /etc/log2ram.conf \
|
||||
/etc/log2ram.conf.dpkg-old \
|
||||
/etc/log2ram.conf.bak \
|
||||
/etc/log2ram.conf.save 2>/dev/null || true
|
||||
|
||||
rm -rf /etc/logrotate.d/log2ram 2>/dev/null || true
|
||||
|
||||
if mountpoint -q /var/log 2>/dev/null; then
|
||||
if [[ -d /var/log.hdd ]]; then
|
||||
msg_info "$(translate "Preserving logs to /var/log.hdd before unmounting...")"
|
||||
rsync -a /var/log/ /var/log.hdd/ >/dev/null 2>&1 || true
|
||||
fi
|
||||
umount /var/log >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
[[ -d /var/log.hdd ]] && rm -rf /var/log.hdd
|
||||
[[ -d /tmp/log2ram ]] && rm -rf /tmp/log2ram
|
||||
[[ -d /var/hdd.log ]] && rm -rf /var/hdd.log
|
||||
[[ -f /tmp/log2ram_install.log ]] && rm -f /tmp/log2ram_install.log
|
||||
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
systemctl reset-failed >/dev/null 2>&1 || true
|
||||
systemctl restart cron >/dev/null 2>&1 || true
|
||||
|
||||
if dpkg -l 2>/dev/null | grep -q '^ii log2ram'; then
|
||||
msg_info "$(translate "Purging log2ram apt package...")"
|
||||
apt-get purge -y log2ram >/dev/null 2>&1 || true
|
||||
apt-get autoremove -y >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if [[ -f /etc/log2ram.conf ]] || \
|
||||
command -v log2ram >/dev/null 2>&1 || \
|
||||
systemctl list-units --all 2>/dev/null | grep -q log2ram || \
|
||||
[[ -f /etc/cron.d/log2ram-auto-sync ]]; then
|
||||
msg_warn "$(translate "Some log2ram files may still exist. Manual cleanup may be required.")"
|
||||
else
|
||||
msg_ok "$(translate "log2ram completely removed from system")"
|
||||
fi
|
||||
|
||||
msg_info "$(translate "Uninstalling Log2RAM...")"
|
||||
pmx_log2ram_remove
|
||||
msg_ok "$(translate "Log2RAM is removed at the next reboot, after writing /var/log to disk")"
|
||||
register_tool "log2ram" false
|
||||
NECESSARY_REBOOT=1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user