I do not take any credit for the work, I just try and make it usable on a standard Debian/Ubuntu System. Please go check them out here
There are 3 ways how you can install this on your machine:
- curl one-line command
- download install script
- clone git-repo
just copy and paste this to your terminal everything is done for you.
Piping to bash is controversal, therefore there are other options, if you want to read the script beforehand:
wget -O install.sh https://raw.githubusercontent.com/mnul/debian-autoshutdown/master/install.sh
sudo bash install.sh
git clone https://github.com/mnul/debian-autoshutdown debian-autoshutdown
cd debian-autoshutdown
sudo bash local-install.sh
Once the setup is done, there is a config file located in /etc/autoshutdown.conf
that you can edit to your needs. Just open it with your favourite editor (eg. vim, nano, ...) and change the settings accordingly. Everything is explained nicely.
Using nano this is:
once you're done editing, save using [CTRL]+[o], press [y] to overwrite the current config and exit out with [CTRL]+[x]. Finally you need to restart the autoshutdown-service for the changes to take effect.
Below you find the original README from OMV-Autoshutdown where things are explained nicely.
If you have further questions hit me up on reddit @manukimmerle
Bugs reports: Please provide a full verbose or FAKE-Mode log with the git issue.
The Autoshutdown script checks the status of the network and the server. A set of check in the script are known as a "cycle". Between the cycles the script goes into sleep for x seconds. The checks run on the system have a different priority from 0 = highest to 6 = lowest:
- Stay up-range: UPHOURS (Server in the time range, where it should be online)
- Check for active IPs over network interfaces
- Ports (Network sockets) over network interfaces
Ports (Docker host ports)
Check for logged in user
Samba status check - UL/DL-Rate in kB/s over active network interfaces
- HDD IO rate check in kB/s
Check if S.M.A.R.T tests are running - Check for active processes
- Check for user plugins
If a check with a higher priority gives back a positive result, then no check with a lower priority is executed. The script reduces the cycles by one and goes to sleep for x seconds until the next cycle. If all cycles are 0 (zero) the server is shutdown.
Let's have a look at a simple example:
--- autoshutdown.conf ---
ENABLE=true
CYCLES=4
SLEEP=180
RANGE="5..100"
CHECKCLOCKACTIVE="true"
UPHOURS="06:00..20:00"
NSOCKETNUMBERS="21,22,80,3689,6991,9091,49152"
ULDLCHECK="true"
ULDLRATE=50
LOADAVERAGECHECK="true"
LOADAVERAGE=40
SYSLOG="true"
VERBOSE="false"
FAKE="false"
TEMPPROCNAMES="-"
It is 10:00 am. Autoshutdown does the first check:
Prio 0: UPHOURS
They are set to "06:00..20:00" which means 06:00 - 20:00 (6am to 8pm). No
further checks needed, the script sleeps until 8pm.
It is 20:01 (8:01pm) now and Autoshutdown does further checks:
Prio 1: IPs
Let's assume, that only IP 137 is online, so the check is negative, next check.
Prio 2: Ports
Let's assume, that there is no connection on any port to watch. The check is
negative, next check.
Prio 3: UL/DL-Rate
Maybe a DL is running with 238 kB/s over the last minute. The check is
positive, no more checks needed.
Autoshutdown goes to sleep for x seconds.
Prio 4 and 6:
Not needed, because a check with a higher priority is positive.
For details of what value should be set in the autoshutdown.conf, and there meaning, see autoshutdown.default
0 - Script completed successfully.
142 - Shutdown mechanism failed to run correctly.
141 - Initialisation failed for a component.
140 - Invalid configuration value where no default is available.
139 - A required configuration file was not found.
138 - No valid network interface found on system.