The server space reserver. Intended for Linux systems. Tested on Ubuntu 20.04, 21.10 and Fedora Workstation 35.
A very mild contingency plan for servers that run out of space. Based on this great article by Brian Schrader: Why All My Servers Have An 8gb Empty File.
Just like Schrader does in the article, this script will reserve space on a server, so, you can delete it later.
Specifically, when your server runs out of space, you can remove the reservation file this script produces so that the server will hopefully have enough space to function again while you try to fix whatever caused the issue.
You should always use monitoring software and or SaaS offerings such as Datadog to monitor disk usage on your servers. That is the tool that will really help you mitigate this potential problem. Think of reserver
as a sidekick. It's simple to use and is there if your primary tools somehow fail. It is a mild contingency plan if you can spare the disk space.
Run the following in the terminal of your server:
sh -c "$(curl -sL https://ceiphr.io/reserver/install)"
The installation script uses curl
or wget
to get reserver.sh
from this repository and makes it executable with chmod x reserver.sh
. It then moves the script to /usr/local/bin/reserver
to make it available in your $PATH
. This operation does require root access.
Simply running the command will produce a 5GB reservation file located at $HOME/.reservation
:
$ reserver
Reserving 5GB of space...
Reservation complete!
Rerunning the script will ask if you'd like to delete the reservation:
$ reserver
Reservation file already exists. Delete? [y/N]: y
Reservation removed. Good luck!
You can provide a custom directory, file name or size:
$ reserver -d /tmp -f foo -s 10
Reservation size set to 10GB.
Reserving 10GB of space...
Reservation complete!
The above command will create a reservation file foo
in /tmp
that is 10GB in size.
Note: The largest reservation size allowed is 50% of the unallocated space on the disk.
When supplying custom arguments, reserver
will create $HOME/.reserver.conf
that contains the configured directory and file name. Do not edit this file. It is for the script to keep track of your reservation.
When running the command again without arguments:
$ reserver
Reservation file already exists. Delete? [y/N]: y
Reservation removed. Good luck!
reserver
will read .reserver.conf
to find where your reservation is. The script will ask if you'd like to delete the reservation, just like with the default configuration.
reserver
ensures that only one reservation exists on a system anytime the script is executed. To prevent multiple instances of the script from causing a race condition, /tmp/reserver.lock
is created when the script is running. Other instances of the script will be blocked from running.
Distributed under the MIT License. See LICENSE for more information.
This project both leveraged and took inspiration from the following products and projects: