GoAdmio

slice

Apply the CPU and memory limits saved in GoAdmio to every user's login sessions, using a systemd user-.slice drop-in

On this page: Overview · Quick start · Syntax · Limit values · Output · Examples · Troubleshooting · Details · See also


Overview

/go/slice limits how much CPU and memory a single user can use through login sessions on the server, such as SSH sessions. It reads two numbers from GoAdmio's configuration, CPULimit and MemoryLimit, and writes them as a systemd configuration for user-.slice. Use it to stop one user from using up the whole server.

The command takes no arguments. Change the limits in GoAdmio, then run /go/slice to apply them.

Things to know first:


Quick start

# Apply the saved limits
/go/slice

Syntax

/go/slice

Anything you type after the command is ignored and is only written to /var/log/go/slice.log with a timestamp. Run the command as root.


Limit values

The limits come from the Config table in /var/lib/sqlite/config.db.

Setting Meaning in the written file
CPULimit CPUQuota: a percentage of one CPU core. 100 is one core, 200 is two cores.
MemoryLimit MemoryHigh and MemoryMax: a percentage of the server's total memory.

What the command does with the two values:

Saved values Result
Both are 100 Limits are removed. The drop-in folder is deleted.
Both are 5 or more, and not both 100 Limits are written and applied.
Either is below 5 Nothing changes. There is no message, and any limits already set stay as they are.
Either is empty, or not a whole number Prints Error: Invalid CPU or Memory limit values and stops with status 1.

[!WARNING] 100 does not mean "unlimited" unless both values are 100. If CPULimit is 100 and MemoryLimit is 50, each user is limited to one CPU core, because the CPU value is a percentage of a single core.

Example

With CPULimit set to 200 and MemoryLimit set to 50, the command writes:

[Slice]
CPUQuota=200%
MemoryHigh=50%
MemoryMax=50%

Each user can then use up to two cores and half of the server's memory. If a user goes over the memory limit, their processes are slowed down and can be killed.


Output

When the limits are valid, the command prints nothing. Check the result with the commands under Examples.

When a limit is empty or not a number, it prints:

Error: Invalid CPU or Memory limit values

and ends with exit status 1. Nothing is changed.


Examples

# Apply the saved limits
/go/slice
# See the file that was written
cat /etc/systemd/system/user-.slice.d/all.conf
# Check the limits for one user (replace 1000 with the user's numeric ID)
systemctl show user-1000.slice -p CPUQuotaPerSecUSec -p MemoryHigh -p MemoryMax
# Review recent calls
tail /var/log/go/slice.log

Troubleshooting

Symptom Likely cause Fix
Error: Invalid CPU or Memory limit values CPULimit or MemoryLimit is empty or not a whole number. Set both limits in GoAdmio, then run the command again.
The command ran, but nothing changed A saved value is below 5, or both are 100 and no limits were set before. Use values of 5 or more. Use 100 for both to remove the limits.
Permission denied when writing all.conf The command was not run as root. Run it as root.
Users are limited to one CPU core CPULimit is 100, which is one core. Use 200 for two cores, 400 for four, and so on.
SSH sessions are killed or very slow The memory limit is too low. This includes root sessions. Raise MemoryLimit, then run the command again.
A user who is already logged in is not limited Open sessions may keep their old limits. Ask the user to log in again.
Websites are not limited Sites run as system services, not in a user slice. These limits are not meant for sites.
A custom file in user-.slice.d disappeared The folder is emptied or removed on every run. Keep your own settings in a different file name and folder.
MariaDB limits are not applied three minutes later The script calls /go/mariadbqouta, spelled with qo instead of quo. Check that this command exists. The documented command is mariadbquota.

Details

What it does

  1. Records the call in /var/log/go/slice.log.
  2. Reads MemoryLimit and CPULimit from /var/lib/sqlite/config.db.
  3. If either is not a whole number, prints the error and stops.
  4. If both are 100, deletes /etc/systemd/system/user-.slice.d.
  5. Otherwise, if both are 5 or more, empties /etc/systemd/system/user-.slice.d and writes all.conf in it.
  6. Runs systemctl daemon-reload, in every case.
  7. Schedules a MariaDB limits command to run in 3 minutes, unless one is already waiting in the at queue.
flowchart TD
    A["slice"] --> B["Read CPULimit and MemoryLimit"]
    B --> C{"Both whole numbers?"}
    C -- "No" --> X["Print error, exit 1"]
    C -- "Yes" --> D{"Both 100?"}
    D -- "Yes" --> E["Delete user-.slice.d"]
    D -- "No" --> F{"Both 5 or more?"}
    F -- "Yes" --> G["Write all.conf"]
    F -- "No" --> H["Change nothing"]
    E --> I["systemctl daemon-reload"]
    G --> I
    H --> I
    I --> J["Schedule MariaDB limits in 3 minutes"]

Where the limits apply

Item Detail
File written /etc/systemd/system/user-.slice.d/all.conf
Applies to Every user-<UID>.slice, one for each user with a login session, including root
Counted per User, not for all users together
MemoryHigh and MemoryMax Both are set to the same value

See also

Command Description
mariadbquota Apply per-user connection and query limits to all MariaDB users
shell Enable or disable SSH shell access for an account
jailedshell Enable or disable a chrooted SSH shell for a domain
cpu Show the server's CPU load and its top CPU-consuming processes
mem Check the top ten memory-consuming commands or services
top Show the top CPU-consuming processes and their parent command
swap Create a swap file sized to RAM and set vm.swappiness
heal Monitor key services, memory, load, and disk, and automatically fix problems