mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-10-10 11:56:17 +00:00
Update customizable_post_install.sh
This commit is contained in:
@@ -3515,7 +3515,7 @@ update_pve_appliance_manager() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
configure_log2ram() {
|
configure_log2ram_() {
|
||||||
|
|
||||||
msg_info2 "$(translate "Preparing Log2RAM configuration")"
|
msg_info2 "$(translate "Preparing Log2RAM configuration")"
|
||||||
sleep 2
|
sleep 2
|
||||||
@@ -3637,6 +3637,163 @@ EOF
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
configure_log2ram() {
|
||||||
|
msg_info2 "$(translate "Preparing Log2RAM configuration")"
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
RAM_SIZE_GB=$(free -g | awk '/^Mem:/{print $2}')
|
||||||
|
[[ -z "$RAM_SIZE_GB" || "$RAM_SIZE_GB" -eq 0 ]] && RAM_SIZE_GB=4
|
||||||
|
|
||||||
|
if (( RAM_SIZE_GB <= 8 )); then
|
||||||
|
DEFAULT_SIZE="128"
|
||||||
|
DEFAULT_HOURS="1"
|
||||||
|
elif (( RAM_SIZE_GB <= 16 )); then
|
||||||
|
DEFAULT_SIZE="256"
|
||||||
|
DEFAULT_HOURS="3"
|
||||||
|
else
|
||||||
|
DEFAULT_SIZE="512"
|
||||||
|
DEFAULT_HOURS="6"
|
||||||
|
fi
|
||||||
|
|
||||||
|
USER_SIZE=$(whiptail --title "Log2RAM" --inputbox "$(translate "Enter the maximum size (in MB) to allocate for /var/log in RAM (e.g. 128, 256, 512):")\n\n$(translate "Recommended for $RAM_SIZE_GB GB RAM:") ${DEFAULT_SIZE}M" 12 70 "$DEFAULT_SIZE" 3>&1 1>&2 2>&3) || return 0
|
||||||
|
LOG2RAM_SIZE="${USER_SIZE}M"
|
||||||
|
|
||||||
|
CRON_HOURS=$(whiptail --title "Log2RAM" --radiolist "$(translate "Select the sync interval (in hours):")\n\n$(translate "Suggested interval: every $DEFAULT_HOURS hour(s)")" 15 70 5 \
|
||||||
|
"1" "$(translate "Every hour")" OFF \
|
||||||
|
"3" "$(translate "Every 3 hours")" OFF \
|
||||||
|
"6" "$(translate "Every 6 hours")" OFF \
|
||||||
|
"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
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg_info "$(translate "Cleaning previous Log2RAM installation...")"
|
||||||
|
|
||||||
|
systemctl stop log2ram log2ram-daily.timer >/dev/null 2>&1 || true
|
||||||
|
systemctl disable log2ram log2ram-daily.timer >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
rm -f /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 2>/dev/null || true
|
||||||
|
rm -f /usr/local/bin/log2ram-check.sh /usr/local/bin/log2ram /usr/sbin/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 2>/dev/null || true
|
||||||
|
rm -rf /etc/systemd/system/log2ram.service.d 2>/dev/null || true
|
||||||
|
rm -f /etc/log2ram.conf* 2>/dev/null || true
|
||||||
|
rm -rf /etc/logrotate.d/log2ram /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
|
||||||
|
apt-get install -y git >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf /tmp/log2ram 2>/dev/null || true
|
||||||
|
if ! git clone 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
|
||||||
|
|
||||||
|
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||||
|
systemctl enable --now log2ram >/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
|
||||||
|
|
||||||
|
sed -i "s/^SIZE=.*/SIZE=$LOG2RAM_SIZE/" /etc/log2ram.conf
|
||||||
|
LOG2RAM_BIN="$(command -v log2ram || echo /usr/sbin/log2ram)"
|
||||||
|
|
||||||
|
cat > /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
|
||||||
|
cat > /usr/local/bin/log2ram-check.sh <<'EOF'
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
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 ))
|
||||||
|
THRESHOLD_BYTES=$(( LIMIT_BYTES * 90 / 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 > THRESHOLD_BYTES )); then
|
||||||
|
"$L2R_BIN" write 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
chmod +x /usr/local/bin/log2ram-check.sh
|
||||||
|
|
||||||
|
cat > /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=""
|
||||||
|
*/5 * * * * root /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 90% of") $LOG2RAM_SIZE"
|
||||||
|
else
|
||||||
|
rm -f /usr/local/bin/log2ram-check.sh /etc/cron.d/log2ram-auto-sync 2>/dev/null || true
|
||||||
|
msg_info2 "$(translate "Auto-sync was not enabled")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
systemctl restart cron >/dev/null 2>&1 || true
|
||||||
|
systemctl restart log2ram >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
msg_success "$(translate "Log2RAM installation and configuration completed successfully.")"
|
||||||
|
register_tool "log2ram" true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ==========================================================
|
# ==========================================================
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user