In order to test/burn-in your server, we need to keep the processor utilization at a specific percentage for a long period of time. Running a solo script to keep the system busy can lead to termination of the script randomly and thus failure of the job.
Here, we’ll create a bash script that keeps the processor busy at a specific percentage and run the script as a service which restarts whenever the service fails. This ensures that your processor will always be utilized at the given percentage, so you can test/burn-in or keep your server busy so that cloud providers do not reclaim it 🙂
Stress-ng is an amazing library which can be used to stress a number of components of a server, and is used to here keep the processor busy. If you don’t have it, you can install it using:
sudo apt install stress-ng
Here are the steps:
-
Create a bash script with the following code and save it as
busy.sh
:#!/bin/bash stress-ng --cpu 0 --cpu-load 30 -t 0
You can edit the
--cpu-load
to keep your desired CPU load percentage. We’re going with 30% here. -
Make the bash script executable by running the following command on your terminal:
chmod +x busy.sh
-
Create a new service in Systemd in this directory
/etc/systemd/system
:[Unit] Description=keep CPU busy [Service] Type=simple User=root Group=root ExecStart=/home/ubuntu/busy.sh #path to the created busy.sh Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target
-
Reload the service files to include the newly created service:
sudo systemctl daemon-reload
-
Start your keep-busy service:
sudo systemctl start busy.service
-
Check the status of your service:
sudo systemctl status busy.service
-
To start your service on every reboot:
sudo systemctl enable busy.service
-
To stop your service:
sudo systemctl stop busy.service
-
To disable starting of the service on every reboot:
sudo systemctl disable busy.service
You can use htop
command to check if stress-ng is running at the specified CPU percentage utilization.
Enjoy keeping busy and don’t let cloud providers claim your server.
Best,
Pastav