update readme + script

This commit is contained in:
Heavybullets8 2022-06-10 14:32:39 -06:00
parent 6d1a9fc77b
commit 8a2ec69b75
2 changed files with 56 additions and 43 deletions

View File

@ -1,34 +1,37 @@
# heavy_script # heavy_script
Update | Backup | Restore | Mount PVC | Rollback Applications | Sync Catalog | Prune Docker Images
## Arguments
| Flag | Example | Parameter | Description | | Flag | Example | Parameter | Description |
|------ |------------------------ |----------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |----------- |------------------------ |----------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -r | -r | None | Restore HeavyScript specific 'ix-applications dataset' snapshot | | --restore | --restore | None | Restore HeavyScript specific `ix-applications dataset` snapshot |
| -m | -m | None | Initiates mounting feature<br>Choose between unmounting and mounting PVC data | | --mount | --mount | None | Initiates mounting feature Choose between unmounting and mounting PVC data |
| -b | -b 14 | int | Backup 'ix-appliactions' dataset<br>Creates backups up to the number you've chosen | | --dns | --dns | None | list all of your applications DNS names and their web ports |
| -i | -i nextcloud -i sonarr | String | Applications listed will be ignored during updating |
| -R | -R | None | Monitors applications after they update<br>If the app does not become "ACTIVE" after either:<br>The custom Timeout, or Default Timeout,<br>rollback the application. |
| -v | -v | None | Verbose output |
| -S | -S | None | Shutdown applications prior to updating |
| -t | -t 150 | int | Set a custom timeout to be used with either:<br>-m <br>- Time the script will wait for application to be "STOPPED"<br>or<br>-u/U <br>- Time the script will wait for application to be either "STOPPED" or "ACTIVE" |
| -s | -s | None | Sync Catalog before updating |
| -U | -U | None | Update applications, ignoring major version changes | | -U | -U | None | Update applications, ignoring major version changes |
| -u | -u | None | Update applications, do NOT update if there was a major version change | | -u | -u | None | Update applications, do NOT update if there was a major version change |
| -b | -b 14 | Integer | Backup `ix-appliactions` dataset Creates backups up to the number you've chosen |
| -i | -i nextcloud -i sonarr | String | Applications listed will be ignored during updating List one application after another as shown in the example |
| (-R\|-r) | -r | None | Monitors applications after they update If the app does not become "ACTIVE" after either: The custom Timeout, or Default Timeout, rollback the application. Warning: deprecating `-R` please begin using `-r` instead |
| -v | -v | None | Verbose Output Look at the bottom of this page for an example |
| -S | -S | None | Shutdown the application prior to updating it |
| -t | -t 150 | Integer | Set a custom timeout to be used with either: `-m` - Time the script will wait for application to be "STOPPED" or `-(u\|U)` - Time the script will wait for application to be either "STOPPED" or "ACTIVE" |
| -s | -s | None | Sync Catalogs prior to updating |
| -p | -p | None | Prune old/unused docker images | | -p | -p | None | Prune old/unused docker images |
<br> <br>
<br> <br>
### Examples ### Examples
#### Typical Cron Job #### Typical Cron Job
``` ```
bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -Rsup bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -rsup
``` ```
- -b is set to 14. Up to 14 snapshots of your ix-applications dataset will be saved - -b is set to 14. Up to 14 snapshots of your ix-applications dataset will be saved
- -i is set to ignore portainer, arch, sonarr, and radarr. These applications will be ignored when it comes to updates. - -i is set to ignore portainer, arch, sonarr, and radarr. These applications will be ignored when it comes to updates.
- -t I set it to 600 seconds, this means the script will wait 600 seconds for the application to become ACTIVE before timing out and continuing to a different application. - -t I set it to 600 seconds, this means the script will wait 600 seconds for the application to become ACTIVE before timing out and continuing to a different application.
- -R Will rollback applications if they fail to deploy after updating. - -r Will rollback applications if they fail to deploy after updating.
- -s will just sync the repositories, ensuring you are downloading the latest updates. - -s will just sync the repositories, ensuring you are downloading the latest updates.
- -u update applications as long as the major version has absolutely no change, if it does have a change it will ask the user to update manually. - -u update applications as long as the major version has absolutely no change, if it does have a change it will ask the user to update manually.
- -p Prune docker images. - -p Prune docker images.
@ -36,18 +39,18 @@ bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -Rsup
#### Mounting PVC Data #### Mounting PVC Data
``` ```
bash /mnt/tank/scripts/heavy_script.sh -t 300 -m bash /mnt/tank/scripts/heavy_script.sh -t 300 --mount
``` ```
#### Restoring ix-applications dataset #### Restoring ix-applications dataset
``` ```
bash /mnt/tank/scripts/heavy_script/heavy_script.sh -r bash /mnt/tank/scripts/heavy_script/heavy_script.sh --restore
``` ```
#### My personal Cron Job #### My personal Cron Job
``` ```
git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_script/heavy_script.sh -b 14 -Rsup git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_script/heavy_script.sh -b 14 -rsup
``` ```
<br> <br>
@ -106,14 +109,14 @@ Here, we will update the script prior to running it, incase there is a bugfix, o
**Cron Job Command** **Cron Job Command**
``` ```
git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_script/heavy_script.sh -b 14 -Rsup git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_script/heavy_script.sh -b 14 -rsup
``` ```
> The important command here is the `git -C /PATH/TO/HEAVY_SCRIPT_DIRECTORY pull` > The important command here is the `git -C /PATH/TO/HEAVY_SCRIPT_DIRECTORY pull`
> This command will allow you to preform a `git pull` on a remote directory, which will ensure your script is udated prior to running it > This command will allow you to preform a `git pull` on a remote directory, which will ensure your script is udated prior to running it
> `&&` Is used to run a command AFTER the previous command completed successfully > `&&` Is used to run a command AFTER the previous command completed successfully
>> So once the `git -C /PATH/TO/HEAVY_SCRIPT_DIRECTORY pull` command completes, THEN it will run the `bash /PATH/TO/HEAVY_SCRIPT_DIRECTORY/heavy_script.sh -b 14 -Rsup` command >> So once the `git -C /PATH/TO/HEAVY_SCRIPT_DIRECTORY pull` command completes, THEN it will run the `bash /PATH/TO/HEAVY_SCRIPT_DIRECTORY/heavy_script.sh -b 14 -rsup` command
<br > <br >
<br > <br >
@ -129,7 +132,7 @@ git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_scr
| Name | Value | Reason | | Name | Value | Reason |
|------------------------ |------------------------------------------------------------------------------------------------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |------------------------ |------------------------------------------------------------------------------------------------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Description` | HeavyScript git pull and Update apps | This is up to you, put whatever you think is a good description in here | | `Description` | HeavyScript git pull and Update apps | This is up to you, put whatever you think is a good description in here |
| `Command` | `git -C /PATH/TO/HEAVY_SCRIPT_DIRECTORY pull && bash /PATH/TO/HEAVY_SCRIPT_DIRECTORY/heavy_script.sh -b 14 -Rsup` | This is the command you will be running on your schedule I personally use: `git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_script/heavy_script.sh -b 14 -Rsup` | | `Command` | `git -C /PATH/TO/HEAVY_SCRIPT_DIRECTORY pull && bash /PATH/TO/HEAVY_SCRIPT_DIRECTORY/heavy_script.sh -b 14 -rsup` | This is the command you will be running on your schedule I personally use: `git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_script/heavy_script.sh -b 14 -rsup` |
| `Run As User` | `root` | Running the script as `root` is REQUIRED. You cannot access all of the kubernetes functions without this user. | | `Run As User` | `root` | Running the script as `root` is REQUIRED. You cannot access all of the kubernetes functions without this user. |
| `Schedule` | Up to you, I run mine everyday at `0400` | Again up to you | | `Schedule` | Up to you, I run mine everyday at `0400` | Again up to you |
| `Hide Standard Output` | `False` or Unticked | I like to receive an email report of how the script ran, what apps updated etc. | | `Hide Standard Output` | `False` or Unticked | I like to receive an email report of how the script ran, what apps updated etc. |
@ -144,8 +147,8 @@ git -C /mnt/speed/scripts/heavy_script pull && bash /mnt/speed/scripts/heavy_scr
### Additional Informaton ### Additional Informaton
#### Verbose vs Non-Verbose #### Verbose vs Non-Verbose
- Verbose used `bash heavy_test.sh -b 5 -SRupv` - Verbose used `bash heavy_script.sh -b 5 -Srupv`
- Non-Verbose used `bash heavy_test.sh -b 5 -SRup` - Non-Verbose used `bash heavy_script.sh -b 5 -Srup`
| Verbose | Non-Verbose | | Verbose | Non-Verbose |
|--------- |------------- | |--------- |------------- |

View File

@ -9,6 +9,32 @@ do
case $opt in case $opt in
-) -)
case "${OPTARG}" in case "${OPTARG}" in
help)
clear -x
echo "Basic Utilities"
echo "--mount | Initiates mounting feature, choose between unmounting and mounting PVC data"
echo "--restore | Opens a menu to restore a \"heavy_script\" backup that was taken on your \"ix-applications\" dataset"
echo "--dns | list all of your applications DNS names and their web ports"
echo
echo "Update Options"
echo "-U | Update all applications, ignores versions"
echo "-u | Update all applications, does not update Major releases"
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
echo "-i | Add application to ignore list, one by one, see example below."
echo "-R | THIS OPTION WILL DEPRICATE SOON, USE \"-r\" instead. Roll-back applications if they fail to update"
echo "-r | Roll-back applications if they fail to update"
echo "-S | Shutdown applications prior to updating"
echo "-v | verbose output"
echo "-t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
echo "-s | sync catalog"
echo "-p | Prune unused/old docker images"
echo
echo "Examples"
echo "bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vrsUp"
echo "bash /mnt/tank/scripts/heavy_script.sh -t 8812 -m"
echo "bash /mnt/tank/scripts/heavy_script.sh --mount"
exit
;;
dns) dns)
dns="true" dns="true"
;; ;;
@ -18,23 +44,6 @@ do
mount) mount)
mount="true" mount="true"
;; ;;
help)
echo "-m | Initiates mounting feature, choose between unmounting and mounting PVC data"
echo "-r | Opens a menu to restore a heavy_script backup that was taken on you ix-applications pool"
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
echo "-i | Add application to ignore list, one by one, see example below."
echo "-R | Roll-back applications if they fail to update"
echo "-S | Shutdown applications prior to updating"
echo "-v | verbose output"
echo "-t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
echo "-s | sync catalog"
echo "-U | Update all applications, ignores versions"
echo "-u | Update all applications, does not update Major releases"
echo "-p | Prune unused/old docker images"
echo "EX | bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vRsUp"
echo "EX | bash /mnt/tank/scripts/heavy_script.sh -t 8812 -m"
exit
;;
*) *)
echo "Invalid Option -$OPTARG, type --help for help" echo "Invalid Option -$OPTARG, type --help for help"
@ -84,6 +93,7 @@ do
;; ;;
R) R)
rollback="true" rollback="true"
echo "WARNING: -R is being transisitioned to -r, this is due to a refactor in the script. Please Make the change ASAP!"
;; ;;
v) v)
verbose="true" verbose="true"
@ -342,7 +352,6 @@ echo "Generating DNS Names.."
ignore="cron|kube-system|nvidia|svclb|NAME|memcached" ignore="cron|kube-system|nvidia|svclb|NAME|memcached"
# Pulling pod names # Pulling pod names
mapfile -t main < <(k3s kubectl get pods -A | grep -Ev "$ignore" | sort) mapfile -t main < <(k3s kubectl get pods -A | grep -Ev "$ignore" | sort)
# Pulling all ports # Pulling all ports
@ -364,6 +373,7 @@ export -f dns
#exit if incompatable functions are called #exit if incompatable functions are called
[[ "$restore" == "true" && "$mount" == "true" ]] && echo -e "The Restore Function(-r)\nand\nMount Function(-m)\nCannot both be called at the same time." && exit [[ "$restore" == "true" && "$mount" == "true" ]] && echo -e "The Restore Function(-r)\nand\nMount Function(-m)\nCannot both be called at the same time." && exit
[[ "$update_all_apps" == "true" && "$update_apps" == "true" ]] && echo -e "-U and -u cannot BOTH be called" && exit [[ "$update_all_apps" == "true" && "$update_apps" == "true" ]] && echo -e "-U and -u cannot BOTH be called" && exit
#Continue to call functions in specific order #Continue to call functions in specific order
[[ "$dns" == "true" ]] && dns && exit [[ "$dns" == "true" ]] && dns && exit
[[ "$restore" == "true" ]] && restore && exit [[ "$restore" == "true" ]] && restore && exit