Skip to content

Background services

The Background tab

The Background tab adds programs that systemd keeps running for the website, such as a queue worker (php artisan queue:work), a scheduler or a small Node.js server. Use Cron for jobs that run on a schedule and then stop.

The program runs as the website’s own account, never as root. If it stops, systemd starts it again.

  1. Enter a Name for the service.
  2. Set the Memory limit: 0 for the default of this server (see Memory share), or between 32 and 4096 MB.
  3. Enter the Arguments. The first argument is the script, relative to the website’s folder. The panel adds the runtime in front: PHP, Node.js or the website’s python. For example, on a Laravel site artisan queue:work --tries=3 runs php artisan queue:work --tries=3.
  4. Leave Start it now and keep it running ticked to start it at once.
  5. Click Add.

Put quotes around an argument that contains spaces. Shell characters such as ; | & $ ` ( ) { } < > are not allowed, because the arguments go straight to the program without a shell.

Users with the Manage or Full role on the website can add and change its background services. See Users.

All background services of all websites share one systemd slice, mpn-bg.slice. By default, its combined memory limit is 40% of the server’s RAM. This is one limit across the server, not 40% per website or per service.

MariaDB/MySQL, PHP-FPM, nginx, the panel and the main Node.js/Python web processes run outside this slice. The 40% is an upper limit, not memory allocated in advance. The remaining 60% is not reserved or guaranteed for the other services. A 1 GB server can still run out of memory if the combined workload needs more than it has.

A service with Memory limit set to 0 uses the server default: one quarter of the shared limit, with a minimum of 32 MB. The tab shows this as “(default)”. An explicit per-service limit does not override the combined limit. Before the combined hard limit is reached, MemoryHigh applies memory pressure; if memory cannot be reclaimed at the hard limit, the kernel can terminate processes inside the slice. systemd may restart them according to the service’s restart policy.

Database buffer and connection settings, PHP-FPM’s on-demand workers and its maximum child count are configured separately. These settings are not a hard limit on the total memory used by the database and PHP. Telegram alerts report problems; they do not enforce a memory limit or prevent an out-of-memory event.

Over SSH, as root, show the current share:

Terminal window
mpn bg limit

For example, to lower the combined limit to 20% of the server’s RAM:

Terminal window
mpn bg limit -percent 20 -apply

The accepted range is 10–90%. The example is not a validated recommendation for every 1 GB server. Choose the limit based on the memory needed by the operating system, websites, database and other services under a representative workload; a lower limit can stop a worker that needs more memory.

After updating to 1.2.6, regenerate services written by an older version so that they join the slice and receive the applicable limits:

Terminal window
mpn bg sync -all -apply

Without -apply, the command only prints the plan and changes nothing. Services with an explicit memory limit keep that setting and are also subject to the shared limit.

From 1.2.7, per-site Redis and Memcached instances also belong to this pool. Their memory counts toward the same combined cap; PostgreSQL, like MariaDB/MySQL and PHP-FPM, is outside it.

Total visits—· GoatCounter