//Web Panel

Automate CloudLinux LVE Upgrades for Over‑Limit Clients

Automate LVE package upgrades on AlmaLinux 8 to promote users exceeding CPU, memory, I/O or process limits, ensuring balanced resources without manual effort.

5 min read
Automate CloudLinux LVE Upgrades for Over‑Limit Clients

Running several clients on a single VPS is common for many Indian hosting providers. CloudLinux’s LVE (Lightweight Virtual Environment) isolates each user’s CPU, memory, I/O and entry processes, preventing a noisy neighbour from affecting the entire server. As sites grow, the default LVE limits often become insufficient. Manually adjusting every package is tedious and can lead to mistakes.

This article explains how to automate the upgrade of LVE packages when a user consistently exceeds their allocated resources. The example uses an AlmaLinux 8 server, the usual base for CloudLinux installations. The steps are written for dnf, the package manager used by AlmaLinux, Rocky Linux, and RHEL 8/9.

Prerequisites

  • Root or sudo privileges on the server.
  • CloudLinux installed with the cagefs, lve and cpanel (or plesk) integrations configured.
  • Basic Bash scripting knowledge.
  • Access to the lve command‑line tools (lvectl, lveinfo).

Understanding LVE Packages and Limits

Every client is assigned an LVE package—such as starter, standard or premium. A package defines four limits:

  1. CPU limit – percentage of a single core.
  2. Memory limit – megabytes of RAM.
  3. I/O limit – percentage of total disk throughput.
  4. Entry processes – maximum simultaneous PHP/CGI processes.

If a user’s usage repeatedly exceeds a chosen threshold (for example, 90 % of the memory limit for three consecutive checks), the script will promote them to the next higher package.

Detection Logic

The script performs the following steps:

  1. List all LVE users.
  2. Retrieve each user’s current package and real‑time usage.
  3. Compare usage against the defined thresholds.
  4. Upgrade users that exceed the thresholds to a pre‑defined “next‑level” package.

Below is a concise Bash function that implements this logic on AlmaLinux 8 with CloudLinux 8.x.

# /usr/local/sbin/lve_auto_upgrade.sh
#!/bin/bash

# Thresholds (adjust as needed)
CPU_THRESHOLD=90
MEM_THRESHOLD=90
IO_THRESHOLD=90
EP_THRESHOLD=90

# Mapping of current package → next package
declare -A NEXT_PKG=(
  ["starter"]="standard"
  ["standard"]="premium"
  ["premium"]="enterprise"
)

log() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"; }

# Iterate over all LVE users
while read -r user; do
  pkg=$(lvectl list --user "$user" | awk '/Package/ {print $2}')
  [[ -z "$pkg" ]] && continue

  stats=$(lveinfo -u "$user" -p)
  cpu=$(echo "$stats" | awk '/CPU/ {print $2}' | tr -d '%')
  mem=$(echo "$stats" | awk '/Memory/ {print $2}' | tr -d '%')
  io=$(echo "$stats" | awk '/IO/ {print $2}' | tr -d '%')
  ep=$(echo "$stats" | awk '/Entry processes/ {print $3}' | tr -d '%')

  if (( cpu >= CPU_THRESHOLD || mem >= MEM_THRESHOLD || io >= IO_THRESHOLD || ep >= EP_THRESHOLD )); then
    next_pkg=${NEXT_PKG[$pkg]}
    if [[ -n "$next_pkg" ]]; then
      log "User $user exceeds limits (CPU:$cpu% MEM:$mem% IO:$io% EP:$ep%). Upgrading from $pkg to $next_pkg."
      lvectl set --user "$user" --package "$next_pkg"
    else
      log "User $user exceeds limits but no higher package defined."
    fi
  fi
done < <(lveinfo -l | awk 'NR>1 {print $1}')

Command explanations:

  • lveinfo -l – lists all LVE users.
  • lvectl list --user "$user" – shows the current LVE package.
  • lveinfo -u "$user" -p – prints real‑time usage percentages.
  • lvectl set --user "$user" --package "$next_pkg" – assigns the new package.

Creating the Packages

Before the script can promote users, the target packages must exist. Use lvectl to create them. Adjust the numeric values to match your hosting plans. The --cpu value is a percentage of a single core; --mem is in megabytes; --io is a percentage of total I/O bandwidth; --ep is the maximum number of entry processes.

AlmaLinux 8 commands

# Starter package
lvectl create --name starter --cpu 20 --mem 512 --io 20 --ep 30

# Standard package
lvectl create --name standard --cpu 40 --mem 1024 --io 40 --ep 60

# Premium package
lvectl create --name premium --cpu 70 --mem 2048 --io 70 --ep 100

# Enterprise package
lvectl create --name enterprise --cpu 100 --mem 4096 --io 100 --ep 200

Scheduling the Automation

Run the script regularly (e.g., every 15 minutes) so upgrades happen promptly.

# Make the script executable
chmod +x /usr/local/sbin/lve_auto_upgrade.sh

# Add a cron job as root
crontab -l | { cat; echo "*/15 * * * * /usr/local/sbin/lve_auto_upgrade.sh >> /var/log/lve_auto_upgrade.log 2>&1"; } | crontab -

Explanation:

  • chmod +x – grants execute permission.
  • The cron line runs the script every 15 minutes and appends output to /var/log/lve_auto_upgrade.log.

Optional Enhancements

  • Maximum package guard – stop upgrades once a user reaches the “enterprise” tier.
  • Email alerts – send a brief summary when a user is upgraded (requires mailx).
  • Rollback script – revert a user to the previous package if a promotion causes instability.

Example email snippet:

if [[ -n "$next_pkg" ]]; then
  echo "User $user upgraded from $pkg to $next_pkg on $(hostname)" \
    | mail -s "LVE Upgrade Notification" admin@example.com
fi

Conclusion

Automating LVE package upgrades removes a repetitive task and ensures that growing clients receive the resources they need without manual intervention. By using CloudLinux’s lveinfo and lvectl tools, a simple Bash script, and a cron schedule, you can keep your hosting environment balanced and responsive. Tailor thresholds, package definitions, and notifications to fit your business model, and the server will adjust itself as usage patterns evolve.

cloudlinuxlvealma linuxvpsserver automationbash scriptingresource managementcron

Try it on your own server

Follow along on a Cloud VPS with full root access, or read the step-by-step knowledge base guides.