Added autoswap.sh, autoswap.service and autoswap.conf to swap-management folder. (v1.0)

This commit is contained in:
2024-11-16 19:41:10 +02:00
parent 8872516bb7
commit 5b9cad82b3
4 changed files with 277 additions and 1 deletions

View File

@@ -26,6 +26,51 @@ sudo ./addswap.sh {size-in-gigaytes}
The script will quickly create a SWAP file, activate it and add it to /etc/fstab
## autoswap.sh
Usage:
1. Copy the file autoswap.conf to /etc/autoswap/autoswap.conf
2. Set owner and group to root and edit the contents of the file to fit your use case.
3. Copy the file autoswap.service to /etc/systemd/system/autoswap.service
4. Set owner and group to root
5. Copy autoswap.sh, addswap.sh and remswap.sh to the / folder.
6. Set owner and group to root and make executable for root only (744)
### as root
```
systemctl daemon-reload
systemctl start autoswap.service
systemctl enable autoswap.service
```
### with sudo
```
sudo systemctl daemon-reload
sudo systemctl start autoswap.service
sudo systemctl enable autoswap.service
```
The script will monitor your available memory and SWAP resources and use addswap.sh and remswap.sh to add and remove SWAP fles depending on your requirements and settings in /etc/autoswap/autoswap.conf.
If you make changes to /etc/autoswap/autoswap.conf then you need to restart the autoswap.service using:
### as root
```
systemctl restart autoswap.service
```
### with sudo
```
sudo systemctl restart autoswap.service
```
## remswap.sh
Usage:
@@ -50,6 +95,8 @@ The script will quickly deactivate a SWAP file, removed it and remove it from /e
It is important that you have addswap.sh and remswap.sh in the same folder and set the permissions to 700 and the owner and group to root. Do not try and run either script with out root or sudo privelages.
If you are using the autoswap service then all three Bash scripts must be in the the / (root) folder.
A log file can be found at /var/log/swapmanagement.log
## Why did I make these two scripts?
@@ -60,7 +107,9 @@ On my daily driver machine, I also create a lot of digital artwork. I recently f
## Plans for the future:
I am planning to make a configurable service file that can be run in the background to automatically create more SWAP files when your server/computer is under load, and remove excess SWAP files when the server/computer is no longer under load.
I am planning to make a configurable service file that can be run in the background to automatically create more SWAP files when your server/computer is under load, and remove excess SWAP files when the server/computer is no longer under load. (completed 2024/Nov/16)
I am next planning on making a binary version of this tool that can be installed using a package manager.
## Do you have a script idea?