Lots of updates
This commit is contained in:
parent
60dc72b46d
commit
242edc9dcb
37 changed files with 999 additions and 100 deletions
9
etc/systemd/system/checkupdates.service
Normal file
9
etc/systemd/system/checkupdates.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run checkupdates
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=checkupdates
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/system/checkupdates.timer
Normal file
9
etc/systemd/system/checkupdates.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run checkupdates
|
||||
|
||||
[Timer]
|
||||
OnCalendar=Mon *-*-* 05:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/system/disk_space_alert.service
Normal file
9
etc/systemd/system/disk_space_alert.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run disk_space_alert
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=disk-space-alert
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/system/disk_space_alert.timer
Normal file
9
etc/systemd/system/disk_space_alert.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run disk_space_alert
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/system/docker_housekeeping.service
Normal file
9
etc/systemd/system/docker_housekeeping.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run docker_housekeeping
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=docker_housekeeping
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/system/docker_housekeeping.timer
Normal file
9
etc/systemd/system/docker_housekeeping.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run docker_housekeeping
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=false
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/system/memory_usage_alert.service
Normal file
9
etc/systemd/system/memory_usage_alert.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run memory_usage_alert
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=memory_usage_alert
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/system/memory_usage_alert.timer
Normal file
9
etc/systemd/system/memory_usage_alert.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run memory_usage_alert
|
||||
|
||||
[Timer]
|
||||
OnCalendar=hourly
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/system/pkgfile.service
Normal file
9
etc/systemd/system/pkgfile.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run pkgfile
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/pkgfile --update
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/system/pkgfile.timer
Normal file
9
etc/systemd/system/pkgfile.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run pkgfile
|
||||
|
||||
[Timer]
|
||||
OnCalendar=Mon *-*-* 05:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/system/smartctl_tests_long.service
Normal file
9
etc/systemd/system/smartctl_tests_long.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run smart_ctl_tests_long
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=smart_ctl_tests_long
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/system/smartctl_tests_long.timer
Normal file
9
etc/systemd/system/smartctl_tests_long.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run smart_ctl_tests_long
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-01 03:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
12
etc/systemd/user/borgwrapper.service
Normal file
12
etc/systemd/user/borgwrapper.service
Normal file
|
@ -0,0 +1,12 @@
|
|||
[Unit]
|
||||
Description=Run borgwrapper
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
#ExecStart=borgwrapper /home/myUser/borgwrapper-custom.conf
|
||||
ExecStart=borgwrapper
|
||||
#Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/myUser/.customBinaryPathWithBorgSymlinkForVirtualenv"
|
||||
#Environment="SSH_AUTH_SOCK=/run/user/myUserId/keyring/ssh"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/user/borgwrapper.timer
Normal file
9
etc/systemd/user/borgwrapper.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run borgwrapper
|
||||
|
||||
[Timer]
|
||||
OnCalendar=20:00
|
||||
Persistent=false
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/user/docker_check.service
Normal file
9
etc/systemd/user/docker_check.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run docker_check
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=docker_check
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/user/docker_check.timer
Normal file
9
etc/systemd/user/docker_check.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run docker_check
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:30:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
9
etc/systemd/user/systemd_check.service
Normal file
9
etc/systemd/user/systemd_check.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run systemd_check
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=systemd_check
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
etc/systemd/user/systemd_check.timer
Normal file
9
etc/systemd/user/systemd_check.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run systemd_check
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:15:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
113
sync
Executable file
113
sync
Executable file
|
@ -0,0 +1,113 @@
|
|||
# !/usr/bin/env bash
|
||||
#
|
||||
# Be careful what you are doing with this script. You may overwrite files.
|
||||
# cd into the repository before executing the script!
|
||||
set -e;
|
||||
|
||||
usage() {
|
||||
echo "Script to synchronize dotfiles or common scripts";
|
||||
echo "---";
|
||||
echo "- Press 1 to sync the git folder's '/etc' with system's '/etc'";
|
||||
echo "";
|
||||
echo "- Press 2 to sync the git folder's '/etc' with all command line users with a certain shell";
|
||||
echo "";
|
||||
echo "- Press 3 to sync the git folder's '/etc' ('/etc/skel') with a specific user's home folder"
|
||||
echo "";
|
||||
echo "- Press 4 to list command line users for sync";
|
||||
echo "";
|
||||
echo "- Press 5 to sync the git folder's '/usr/local/bin' with system's '/usr/local/bin'";
|
||||
echo "---";
|
||||
echo "Press 0 or [CTRL+C] to exit";
|
||||
}
|
||||
|
||||
menu() {
|
||||
usage;
|
||||
read -n 1 -e -p ">" menuInput
|
||||
echo "";
|
||||
|
||||
if [ "$menuInput" = "1" ]; then
|
||||
sudo rsync -r -t -v --chown=root:root --progress $(pwd)/etc/ /etc/
|
||||
echo "";
|
||||
elif [ "$menuInput" = "2" ]; then
|
||||
# require root
|
||||
[[ $UID -eq 0 ]] || (>&2 echo "ERROR: need to be root!" && exit 1)
|
||||
|
||||
# determine shell
|
||||
echo "Which shell (shortname, e.g. zsh)?";
|
||||
read -e -p ">" shellInput
|
||||
echo "";
|
||||
|
||||
# shell users
|
||||
users=$(cat /etc/passwd|grep $shellInput| awk -F':' '{ print $1 }');
|
||||
|
||||
# stage
|
||||
tmpDir=/tmp/dotfiles-system-sync/;
|
||||
mkdir -p $tmpDir;
|
||||
srcDir=$(pwd)/etc/skel/.
|
||||
cp -R $srcDir $tmpDir;
|
||||
|
||||
# copy
|
||||
for user in $users; do
|
||||
exists=$(id -u $user);
|
||||
primaryGroup=$(id -gn $user);
|
||||
chown -R $user:$primaryGroup $tmpDir;
|
||||
trgDir=$(eval echo ~$user/);
|
||||
echo "Copy from $tmpDir to $trgDir";
|
||||
cp -Rp $tmpDir/. $trgDir/;
|
||||
done
|
||||
|
||||
# remove stage
|
||||
rm -rf $tmpDir;
|
||||
elif [ "$menuInput" = "3" ]; then
|
||||
# determine shell
|
||||
echo "Which user?";
|
||||
read -e -p ">" user
|
||||
echo "";
|
||||
|
||||
# stage
|
||||
tmpDir=/tmp/dotfiles-system-sync/;
|
||||
mkdir -p $tmpDir;
|
||||
srcDir=$(pwd)/etc/skel/.
|
||||
cp -R $srcDir $tmpDir;
|
||||
|
||||
# copy
|
||||
exists=$(id -u $user);
|
||||
|
||||
if [ $UID -ne $exists ] && [ $UID -ne 0 ]; then
|
||||
echo "ERROR: need to be $user or root!";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
primaryGroup=$(id -gn $user);
|
||||
chown -R $user:$primaryGroup $tmpDir;
|
||||
trgDir=$(eval echo ~$user/);
|
||||
echo "Copy from $tmpDir to $trgDir";
|
||||
cp -Rp $tmpDir/. $trgDir/;
|
||||
|
||||
# remove stage
|
||||
rm -rf $tmpDir;
|
||||
|
||||
elif [ "$menuInput" = "4" ]; then
|
||||
echo "Which shell (shortname, e.g. zsh)?";
|
||||
read -e -p ">" shellInput
|
||||
echo "";
|
||||
|
||||
# shell users
|
||||
users=$(cat /etc/passwd|grep $shellInput| awk -F':' '{ print $1 }');
|
||||
echo "Users with shell $shellInput"
|
||||
|
||||
for u in $users; do
|
||||
echo $u;
|
||||
done
|
||||
elif [ "$menuInput" = "5" ]; then
|
||||
echo "Yes";
|
||||
elif [ "$menuInput" = "0" ]; then
|
||||
sudo rsync -r -t -v --chown=root:root --progress $(pwd)/usr/local/bin/ /usr/local/bin/
|
||||
echo "";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
menu;
|
||||
}
|
||||
|
||||
menu;
|
100
sync.sh
100
sync.sh
|
@ -1,100 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Be careful what you are doing with this script. You may overwrite dotfiles.
|
||||
# cd into the repository before executing the script!
|
||||
set -e;
|
||||
|
||||
usage() {
|
||||
echo "Press 1 to sync git folder to '/etc'";
|
||||
echo "Press 2 to sync git repository folder 'etc/skel' with all command line users";
|
||||
echo "Press 3 to sync git repository folder 'etc/skel' with a specific user's home folder"
|
||||
echo "Press 4 to list command line users for sync";
|
||||
echo "---";
|
||||
echo "Hit CTRL+C to exit";
|
||||
}
|
||||
|
||||
menu() {
|
||||
usage;
|
||||
read -n 1 -e -p ">" menuInput
|
||||
echo "";
|
||||
|
||||
if [ "$menuInput" = "1" ]; then
|
||||
sudo rsync -r -t -v --chown=root:root --progress $(pwd)/etc/ /etc/
|
||||
echo "";
|
||||
elif [ "$menuInput" = "2" ]; then
|
||||
# require root
|
||||
[[ $UID -eq 0 ]] || (>&2 echo "ERROR: need to be root!" && exit 1)
|
||||
|
||||
# determine shell
|
||||
echo "Which shell (shortname, e.g. zsh)?";
|
||||
read -e -p ">" shellInput
|
||||
echo "";
|
||||
|
||||
# shell users
|
||||
users=$(cat /etc/passwd|grep $shellInput| awk -F':' '{ print $1 }');
|
||||
|
||||
# stage
|
||||
tmpDir=/tmp/dotfiles-system-sync/;
|
||||
mkdir -p $tmpDir;
|
||||
srcDir=$(pwd)/etc/skel/.
|
||||
cp -R $srcDir $tmpDir;
|
||||
|
||||
# copy
|
||||
for user in $users; do
|
||||
exists=$(id -u $user);
|
||||
primaryGroup=$(id -gn $user);
|
||||
chown -R $user:$primaryGroup $tmpDir;
|
||||
trgDir=$(eval echo ~$user/);
|
||||
echo "Copy from $tmpDir to $trgDir";
|
||||
cp -Rp $tmpDir/. $trgDir/;
|
||||
done
|
||||
|
||||
# remove stage
|
||||
rm -rf $tmpDir;
|
||||
elif [ "$menuInput" = "3" ]; then
|
||||
# determine shell
|
||||
echo "Which user?";
|
||||
read -e -p ">" user
|
||||
echo "";
|
||||
|
||||
# stage
|
||||
tmpDir=/tmp/dotfiles-system-sync/;
|
||||
mkdir -p $tmpDir;
|
||||
srcDir=$(pwd)/etc/skel/.
|
||||
cp -R $srcDir $tmpDir;
|
||||
|
||||
# copy
|
||||
exists=$(id -u $user);
|
||||
|
||||
if [ $UID -ne $exists ] && [ $UID -ne 0 ]; then
|
||||
echo "ERROR: need to be $user or root!";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
primaryGroup=$(id -gn $user);
|
||||
chown -R $user:$primaryGroup $tmpDir;
|
||||
trgDir=$(eval echo ~$user/);
|
||||
echo "Copy from $tmpDir to $trgDir";
|
||||
cp -Rp $tmpDir/. $trgDir/;
|
||||
|
||||
# remove stage
|
||||
rm -rf $tmpDir;
|
||||
|
||||
elif [ "$menuInput" = "4" ]; then
|
||||
echo "Which shell (shortname, e.g. zsh)?";
|
||||
read -e -p ">" shellInput
|
||||
echo "";
|
||||
|
||||
# shell users
|
||||
users=$(cat /etc/passwd|grep $shellInput| awk -F':' '{ print $1 }');
|
||||
echo "Users with shell $shellInput"
|
||||
|
||||
for u in $users; do
|
||||
echo $u;
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
menu;
|
||||
}
|
||||
|
||||
menu;
|
185
usr/local/bin/borgwrapper
Executable file
185
usr/local/bin/borgwrapper
Executable file
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# called before backup
|
||||
borgwrapper_pre_backup() {
|
||||
return;
|
||||
}
|
||||
|
||||
# called after backup
|
||||
borgwrapper_post_backup() {
|
||||
return;
|
||||
}
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
USAGE=$(cat <<EOF
|
||||
Usage: borgwrapper [CONFIG_FILE (absolute path)]
|
||||
|
||||
A script which wraps commonly used functions for borg.
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.borgwrapper.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are at least required for the script to work:
|
||||
- BORGWRAPPER_BACKUP_NAME // [a-z09], should be unique for multiple backups (with the same remote user)
|
||||
- BORGWRAPPER_BACKUP_FILES // an array of files and directories to backup, e.g. =('/home', '/root')
|
||||
- BORGWRAPPER_BACKUP_REPOSITORY // trailing slash, add "user@host:/dir/" if remote
|
||||
|
||||
The following are optional or have reasonable defaults:
|
||||
- BORGWRAPPER_BACKUP_PASSWORD='' // the password
|
||||
- BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT=$(date "+%s")
|
||||
- BORGWRAPPER_BACKUP_PRUNE=true // prune the repository (cleans old backups; uses BORGWRAPPER_BACKUP_KEEP_IN_DAYS)? false|true
|
||||
- BORGWRAPPER_BACKUP_KEEP_IN_DAYS=60 // in days, integer only (used for prune)
|
||||
- BORGWRAPPER_BACKUP_CHECK=true // checks entire repository, this is slow! false|true
|
||||
- BORGWRAPPER_BACKUP_CHECK_MAX_AGE_IN_SECONDS=604800 // determine when "borg check" has to run by comparing current time with latest run check (determined by last mod time of $BORGWRAPPER_BACKUP_CHECK_FILE). default is 7 days, 0 will always run the check
|
||||
- BORGWRAPPER_BACKUP_CHECK_FILE="~/.borg-backup-BORGWRAPPER_BACKUP_NAME.check" // used for time comparison
|
||||
- BORGWRAPPER_BACKUP_LOG=true // log? false|true
|
||||
- BORGWRAPPER_BACKUP_LOG_PRUNE=true // overwrite old log for each execution? false|true
|
||||
- BORGWRAPPER_BACKUP_LOG_FILE="~/.borg-backup-BORGWRAPPER_BACKUP_NAME.log" // log file to save output to to
|
||||
- BORGWRAPPER_BACKUP_NOTIFY_VIA_MAIL=false // send email (BORGWRAPPER_BACKUP_LOG has to be set to true)? false|true
|
||||
- BORGWRAPPER_BACKUP_NOTIFY_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
- BORGWRAPPER_BACKUP_NOTIFY_UI=false // use notify-send for UI notification? false|true
|
||||
|
||||
Borg specific values can also be overwritten and have reasonable defaults:
|
||||
- BORGWRAPPER_BORG_BINARY=borg; // defaults to /usr/bin/borg (determined by 'which borg'), adjust to a virtualenv if needed
|
||||
- BORGWRAPPER_BORG_INIT_PARAMS="--encryption=none"; // encryption=none|repokey-blake2|...
|
||||
- BORGWRAPPER_BORG_CREATE_PARAMS="-v -s -p -C lz4";
|
||||
- BORGWRAPPER_BORG_CHECK_PARAMS="-v";
|
||||
- BORGWRAPPER_BORG_PRUNE_PARAMS="-v -s -d BORGWRAPPER_BACKUP_KEEP_IN_DAYS";
|
||||
|
||||
More information can be found in the docs: https://borgbackup.readthedocs.io
|
||||
|
||||
The following functions are executed before and after the backup and can also be overwritten in the config file by redefining them:
|
||||
- borgwrapper_pre_backup
|
||||
- borgwrapper_post_backup
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
# vars and defaults
|
||||
BORGWRAPPER_BACKUP_PASSWORD=''
|
||||
BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT=$(date "+%s")
|
||||
BORGWRAPPER_BACKUP_PRUNE=true
|
||||
BORGWRAPPER_BACKUP_KEEP_IN_DAYS=60
|
||||
BORGWRAPPER_BACKUP_CHECK=true
|
||||
BORGWRAPPER_BACKUP_CHECK_MAX_AGE_IN_SECONDS=604800
|
||||
BORGWRAPPER_BACKUP_CHECK_FILE="$HOME/.borg-backup-$BORGWRAPPER_BACKUP_NAME.check"
|
||||
BORGWRAPPER_BACKUP_LOG=true
|
||||
BORGWRAPPER_BACKUP_LOG_PRUNE=true
|
||||
BORGWRAPPER_BACKUP_LOG_FILE="$HOME/.borg-backup-$BORGWRAPPER_BACKUP_NAME.log"
|
||||
BORGWRAPPER_BACKUP_NOTIFY_VIA_MAIL=false
|
||||
BORGWRAPPER_BACKUP_NOTIFY_MAIL_ADDRESS=""
|
||||
BORGWRAPPER_BACKUP_NOTIFY_UI=false
|
||||
|
||||
BORGWRAPPER_BORG_BINARY=$(which borg);
|
||||
BORGWRAPPER_BORG_INIT_PARAMS="--encryption=none";
|
||||
BORGWRAPPER_BORG_CREATE_PARAMS="-v -s -p -C lz4";
|
||||
BORGWRAPPER_BORG_CHECK_PARAMS="-v";
|
||||
BORGWRAPPER_BORG_PRUNE_PARAMS="-v -s -d $BORGWRAPPER_BACKUP_KEEP_IN_DAYS";
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$backupConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.borgwrapper.conf"
|
||||
|
||||
# start and info
|
||||
echo "Using $BORGWRAPPER_BORG_BINARY as binary"
|
||||
|
||||
borgwrapper_pre_backup;
|
||||
|
||||
# export passphrase if not blank
|
||||
if [ ! -z "$BORGWRAPPER_BACKUP_PASSWORD" ]; then
|
||||
export BORG_PASSPHRASE=$BORGWRAPPER_BACKUP_PASSWORD
|
||||
fi
|
||||
|
||||
# init hint
|
||||
echo "Hint: If you haven't, you need to create the borg repository manually before first run if it doesn't exist:";
|
||||
echo "$BORGWRAPPER_BORG_BINARY init $BORGWRAPPER_BORG_INIT_PARAMS $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME";
|
||||
|
||||
# notify UI
|
||||
if [ "$BORGWRAPPER_BACKUP_NOTIFY_UI" = true ]; then
|
||||
notify-send "Starting backup" $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME::$BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT;
|
||||
fi
|
||||
|
||||
# create
|
||||
$BORGWRAPPER_BORG_BINARY create $BORGWRAPPER_BORG_CREATE_PARAMS $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME::$BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT "${BORGWRAPPER_BACKUP_FILES[@]}";
|
||||
|
||||
# check
|
||||
if [ "$BORGWRAPPER_BACKUP_CHECK" = true ]; then
|
||||
|
||||
# use for first time creation
|
||||
doCheck=false
|
||||
|
||||
if [ ! -f "$BORGWRAPPER_BACKUP_CHECK_FILE" ]; then
|
||||
touch $BORGWRAPPER_BACKUP_CHECK_FILE
|
||||
doCheck=true
|
||||
fi
|
||||
|
||||
# compare date
|
||||
lastMod=$(date -r $BORGWRAPPER_BACKUP_CHECK_FILE +%s)
|
||||
age=$(($BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT - $lastMod))
|
||||
|
||||
if [ "$age" -gt "$BORGWRAPPER_BACKUP_CHECK_MAX_AGE_IN_SECONDS" ]; then
|
||||
doCheck=true
|
||||
fi
|
||||
|
||||
|
||||
if [ "$doCheck" = true ]; then
|
||||
$BORGWRAPPER_BORG_BINARY check $BORGWRAPPER_BORG_CHECK_PARAMS $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME;
|
||||
touch $BORGWRAPPER_BACKUP_CHECK_FILE
|
||||
fi
|
||||
fi
|
||||
|
||||
# prune
|
||||
if [ "$BORGWRAPPER_BACKUP_PRUNE" = true ]; then
|
||||
$BORGWRAPPER_BORG_BINARY prune $BORGWRAPPER_BORG_PRUNE_PARAMS $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME;
|
||||
fi
|
||||
|
||||
# log
|
||||
if [ "$BORGWRAPPER_BACKUP_LOG" = true ]; then
|
||||
|
||||
if [ "$BORGWRAPPER_BACKUP_LOG_PRUNE" = true ] && [ -f "$BORGWRAPPER_BACKUP_LOG_FILE" ]; then
|
||||
rm $BORGWRAPPER_BACKUP_LOG_FILE;
|
||||
fi
|
||||
|
||||
touch $BORGWRAPPER_BACKUP_LOG_FILE;
|
||||
$BORGWRAPPER_BORG_BINARY list -v $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME >> $BORGWRAPPER_BACKUP_LOG_FILE;
|
||||
echo "---" >> $BORGWRAPPER_BACKUP_LOG_FILE;
|
||||
$BORGWRAPPER_BORG_BINARY info $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME::$BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT >> $BORGWRAPPER_BACKUP_LOG_FILE;
|
||||
|
||||
if [ "$BORGWRAPPER_BACKUP_NOTIFY_VIA_MAIL" = true ]; then
|
||||
cat $BORGWRAPPER_BACKUP_LOG_FILE|mailx -Ssendwait -s "[backup $BORGWRAPPER_BACKUP_NAME]" $BORGWRAPPER_BACKUP_NOTIFY_MAIL_ADDRESS;
|
||||
fi
|
||||
fi
|
||||
|
||||
# notify UI
|
||||
if [ "$BORGWRAPPER_BACKUP_NOTIFY_UI" = true ]; then
|
||||
notify-send "Finished backup" $BORGWRAPPER_BACKUP_REPOSITORY$BORGWRAPPER_BACKUP_NAME::$BORGWRAPPER_BACKUP_TIMESTAMP_FORMAT;
|
||||
fi
|
||||
|
||||
borgwrapper_post_backup;
|
||||
|
57
usr/local/bin/checkupdates
Executable file
57
usr/local/bin/checkupdates
Executable file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
USAGE=$(cat <<EOF
|
||||
Usage: checkupdates [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.checkupdates.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are at least required for the script to work:
|
||||
- CHECKUPDATES_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
UPDATES=$(checkupdates)
|
||||
UPDATES_AMOUNT=$(checkupdates|wc -l)
|
||||
CHECKUPDATES_MAIL_ADDRESS="";
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$backupConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.checkupdates.conf"
|
||||
|
||||
if [ "$UPDATES_AMOUNT" -gt "0" ]; then
|
||||
mailx -s "[updates $HOSTNAME]" $CHECKUPDATES_MAIL_ADDRESS << EOF
|
||||
There are $UPDATES_AMOUNT updates available on $HOSTNAME.
|
||||
|
||||
$UPDATES
|
||||
EOF
|
||||
fi
|
66
usr/local/bin/disk_space_alert
Executable file
66
usr/local/bin/disk_space_alert
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
USAGE=$(cat <<EOF
|
||||
Usage: disk_space_alert [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.disk_space_alert.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are at least required for the script to work:
|
||||
- DISK_SPACE_ALERT_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
|
||||
The following are optional or have reasonable defaults:
|
||||
- DISK_SPACE_ALERT_THRESHOLD=93 // in percent
|
||||
- DISK_SPACE_ALERT_MOUNTPOINTS=("/") // array of mountpoints
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
DISK_SPACE_ALERT_MAIL_ADDRESS="";
|
||||
DISK_SPACE_ALERT_THRESHOLD=93
|
||||
DISK_SPACE_ALERT_MOUNTPOINTS=("/")
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$backupConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.disk_space_alert.conf"
|
||||
|
||||
for point in "${DISK_SPACE_ALERT_MOUNTPOINTS[@]}"
|
||||
do
|
||||
CURRENT=$(df $point | grep $point | awk '{ print $5}' | sed 's/%//g')
|
||||
CURRENT_SPACE=$(df $point | grep $point | awk '{ print $5}' | sed 's/%//g')
|
||||
CURRENT_INODES=$(df -i $point | grep $point | awk '{ print $5}' | sed 's/%//g')
|
||||
|
||||
if [ "$CURRENT" -gt "$DISK_SPACE_ALERT_THRESHOLD" ] ; then
|
||||
mailx -s "[disk $HOSTNAME] $point" $DISK_SPACE_ALERT_MAIL_ADDRESS << EOF
|
||||
Your $point partition remaining free space is critically low. Used space: $CURRENT_SPACE%. Used inodes: $CURRENT_INODES%.
|
||||
EOF
|
||||
fi
|
||||
done
|
152
usr/local/bin/docker_check
Executable file
152
usr/local/bin/docker_check
Executable file
|
@ -0,0 +1,152 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
USAGE=$(cat <<EOF
|
||||
Usage: docker_check [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.docker_check.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are optional or have reasonable defaults:
|
||||
DOCKER_CHECK_LIST_FILE="HOME/.docker_check.list" // the list file (output current running to file: docker ps --format '{{.Names}}' >> $HOME/.docker_check.list)
|
||||
DOCKER_CHECK_NOTIFY_LEVELS=("UNKNOWN" "WARNING" "CRITICAL") // when to notify/output/send mail. possible: "UNKNOWN" "WARNING" "CRITICAL" "INFO", should at least be ()
|
||||
DOCKER_CHECK_MAIL_ENABLED=false // send email (address has to be set), values: false|true
|
||||
DOCKER_CHECK_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
DOCKER_CHECK_LIST_FILE="$HOME/.docker_check.list"
|
||||
DOCKER_CHECK_NOTIFY_LEVELS=("UNKNOWN" "WARNING" "CRITICAL")
|
||||
DOCKER_CHECK_MAIL_ENABLED=false
|
||||
DOCKER_CHECK_MAIL_ADDRESS=""
|
||||
CONTAINERS=()
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$backupConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.docker_check.conf"
|
||||
|
||||
if [ ! -f $DOCKER_CHECK_LIST_FILE ]; then
|
||||
echo "$DOCKER_CHECK_LIST_FILE doesn't exist. Add a file which holds one docker container per line.";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Scanning $DOCKER_CHECK_LIST_FILE for containers...";
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||
CONTAINERS+=("$line")
|
||||
echo "-> Found $line";
|
||||
done < "$DOCKER_CHECK_LIST_FILE"
|
||||
|
||||
# check if current status is in array of DOCKER_CHECK_NOTIFY_LEVELS
|
||||
function shouldLog() {
|
||||
local VALUE=$1;
|
||||
|
||||
for i in "${DOCKER_CHECK_NOTIFY_LEVELS[@]}"; do
|
||||
if [ "$i" == "$VALUE" ] ; then
|
||||
echo true;
|
||||
return;
|
||||
fi
|
||||
done
|
||||
|
||||
echo false;
|
||||
}
|
||||
|
||||
# log and send mail if enabled
|
||||
function log() {
|
||||
local CONTAINER=$1;
|
||||
local STATUS=$2;
|
||||
local MESSAGE=$3;
|
||||
|
||||
local SHOULD_LOG=$(shouldLog "$STATUS");
|
||||
if [ "$SHOULD_LOG" = "true" ]; then
|
||||
local SUBJECT="[docker $HOSTNAME] $STATUS $CONTAINER";
|
||||
echo "$SUBJECT: $MESSAGE";
|
||||
|
||||
if [ "$DOCKER_CHECK_MAIL_ENABLED" = true ]; then
|
||||
echo $MESSAGE|mailx -Ssendwait -s "$SUBJECT" $DOCKER_CHECK_MAIL_ADDRESS;
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# get status for a docker container
|
||||
function checkContainer() {
|
||||
local CONTAINER=$1;
|
||||
|
||||
if [ "x${CONTAINER}" == "x" ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "Container ID or Friendly Name Required"
|
||||
return;
|
||||
fi
|
||||
|
||||
if [ "x$(which docker)" == "x" ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "Missing docker binary"
|
||||
return;
|
||||
fi
|
||||
|
||||
docker info > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "Unable to talk to the docker daemon"
|
||||
return;
|
||||
fi
|
||||
|
||||
RUNNING=$(docker inspect --format="{{.State.Running}}" $CONTAINER 2> /dev/null)
|
||||
|
||||
if [ $? -eq 1 ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "$CONTAINER does not exist."
|
||||
return;
|
||||
fi
|
||||
|
||||
if [ "$RUNNING" == "false" ]; then
|
||||
log "$CONTAINER" "CRITICAL" "$CONTAINER is not running."
|
||||
return;
|
||||
fi
|
||||
|
||||
RESTARTING=$(docker inspect --format="{{.State.Restarting}}" $CONTAINER)
|
||||
|
||||
if [ "$RESTARTING" == "true" ]; then
|
||||
log "$CONTAINER" "WARNING" "$CONTAINER state is restarting."
|
||||
return;
|
||||
fi
|
||||
|
||||
#STARTED=$(docker inspect --format="{{.State.StartedAt}}" $CONTAINER)
|
||||
#NETWORK=$(docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $CONTAINER)
|
||||
#log "$CONTAINER" "INFO" "$CONTAINER is running. IP: $NETWORK, StartedAt: $STARTED"
|
||||
|
||||
log "$CONTAINER" "INFO" "$CONTAINER is running."
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# execute check for defined containers
|
||||
for container in "${CONTAINERS[@]}"; do
|
||||
echo "Checking $container...";
|
||||
checkContainer "$container"
|
||||
done
|
7
usr/local/bin/docker_housekeeping
Executable file
7
usr/local/bin/docker_housekeeping
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo "Doing docker housekeeping for containers, images and volumes";
|
||||
|
||||
yes | docker container prune
|
||||
yes | docker image prune
|
||||
yes | docker volume prune
|
64
usr/local/bin/memory_usage_alert
Executable file
64
usr/local/bin/memory_usage_alert
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
USAGE=$(cat <<EOF
|
||||
Usage: memory_usage_alert [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.memory_usage_alert.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are at least required for the script to work:
|
||||
- MEMORY_USAGE_ALERT_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
|
||||
The following are optional or have reasonable defaults:
|
||||
- MEMORY_USAGE_ALERT_THRESHOLD=128 // threshold to warn about (in megabytes)
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
SUBJECT="[memory $HOSTNAME] memory is low"
|
||||
MEMORY_USAGE_ALERT_MAIL_ADDRESS="";
|
||||
MEMORY_USAGE_ALERT_THRESHOLD=128;
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$backupConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.memory_usage_alert.conf"
|
||||
|
||||
# DO NOT TOUCH BELOW
|
||||
free=$(free -mt | grep Total | awk '{print $4}')
|
||||
|
||||
if [[ "$free" -le $MEMORY_USAGE_ALERT_THRESHOLD ]]; then
|
||||
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head >/tmp/top_proccesses_consuming_memory.txt
|
||||
|
||||
file=/tmp/top_proccesses_consuming_memory.txt
|
||||
echo -e "Memory on $HOSTNAME is running low ($MEMORY_USAGE_ALERT_THRESHOLD MB is the remaining threshold)!\n\nFree memory: $free MB" | mailx -a "$file" -s "$SUBJECT" "$MEMORY_USAGE_ALERT_MAIL_ADDRESS"
|
||||
fi
|
||||
|
||||
exit 0
|
61
usr/local/bin/smartctl_tests_long
Executable file
61
usr/local/bin/smartctl_tests_long
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
USAGE=$(cat <<EOF
|
||||
Usage: smartctl_tests_long [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.smartctl_tests_long.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are at least required for the script to work:
|
||||
- SMARTCTL_TESTS_LONG_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
- SMARTCTL_TESTS_LONG_DEVICES=(sda) // array of block devices (not partitions!) to check
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
SMARTCTL_TESTS_LONG_MAIL_ADDRESS="";
|
||||
SMARTCTL_TESTS_LONG_DEVICES=(sda)
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$backupConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.smartctl_tests_long.conf"
|
||||
|
||||
echo "Starting long tests for ...";
|
||||
|
||||
for d in ${SMARTCTL_TESTS_LONG_DEVICES[@]}; do
|
||||
DEVICE="/dev/"$d;
|
||||
echo $DEVICE;
|
||||
smartctl -t long $DEVICE;
|
||||
mailx -s "[smartd $HOSTNAME] queued long test" $SMARTCTL_TESTS_LONG_MAIL_ADDRESS << EOF
|
||||
Queued a smartd long test for $DEVICE.
|
||||
EOF
|
||||
done
|
||||
|
4
usr/local/bin/smartdnotify
Executable file
4
usr/local/bin/smartdnotify
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
HOSTNAME=$(hostname)
|
||||
echo "$SMARTD_MESSAGE" | mail -s "[smartd $HOSTNAME] $SMARTD_FAILTYPE" "$SMARTD_ADDRESS"
|
||||
wall "$SMARTD_MESSAGE"
|
94
usr/local/bin/systemd_check
Executable file
94
usr/local/bin/systemd_check
Executable file
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# usage
|
||||
usage() {
|
||||
SYSTEMD_CHECK_USAGE=$(cat <<EOF
|
||||
Usage: systemd_check.sh [CONFIG_FILE (absolute path)]
|
||||
|
||||
Checks if specific systemd SYSTEMD_CHECK_SERVICES are running and optionally sends a mail.
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.systemd_check.conf is used. This fallback option
|
||||
has to exist or the script will exit.
|
||||
|
||||
Configuration can be done in any file and any pre-defined variable can be overwritten.
|
||||
|
||||
The following are at least required for the script to work:
|
||||
- SYSTEMD_CHECK_LIST_FILE="HOME/.systemd_check.list" // path to file to list services to check, one per line
|
||||
|
||||
The following are optional or have reasonable defaults:
|
||||
- SYSTEMD_CHECK_MAIL_ENABLED=false // send email (SYSTEMD_CHECK_MAIL_ADDRESS has to be set to true)? false|true
|
||||
- SYSTEMD_CHECK_MAIL_ADDRESS="" // mail.rc has to be configured
|
||||
|
||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||
EOF
|
||||
)
|
||||
echo "$SYSTEMD_CHECK_USAGE";
|
||||
}
|
||||
|
||||
set -e;
|
||||
|
||||
# vars and defaults
|
||||
SYSTEMD_CHECK_LIST_FILE="$HOME/.systemd_check.list"
|
||||
SYSTEMD_CHECK_MAIL_ENABLED=fase
|
||||
SYSTEMD_CHECK_MAIL_ADDRESS=""
|
||||
SYSTEMD_CHECK_HOSTNAME=$(hostname)
|
||||
SYSTEMD_CHECK_USER=$(whoami)
|
||||
SYSTEMD_CHECK_SERVICES=()
|
||||
|
||||
# check for config file
|
||||
systemdCheckConfigFile=$1;
|
||||
systemdCheckConfigFileFallback=$HOME/.systemd_check.conf;
|
||||
|
||||
if [[ ! -f "$systemdCheckConfigFile" ]]; then
|
||||
if [[ ! -f "$systemdCheckConfigFileFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$systemdCheckConfigFileFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
systemdCheckConfigFile=$systemdCheckConfigFileFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$systemdCheckConfigFile";
|
||||
set +a;
|
||||
|
||||
if [ ! -f $SYSTEMD_CHECK_LIST_FILE ]; then
|
||||
echo "$SYSTEMD_CHECK_LIST_FILE doesn't exist. Add a file which holds one systemd service or timer per line.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Scanning $SYSTEMD_CHECK_LIST_FILE for services...";
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||
SYSTEMD_CHECK_SERVICES+=("$line")
|
||||
echo "-> Found $line";
|
||||
done < "$SYSTEMD_CHECK_LIST_FILE"
|
||||
|
||||
# get status for a service
|
||||
function checkService() {
|
||||
local SERVICE=$1;
|
||||
local MESSAGE="$SERVICE is not running for user $SYSTEMD_CHECK_USER";
|
||||
local COMMAND="systemctl is-active --quiet $SERVICE";
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
local COMMAND="systemctl --user is-active --quiet $SERVICE";
|
||||
fi
|
||||
|
||||
if ! $($COMMAND); then
|
||||
local SUBJECT="[systemd $SYSTEMD_CHECK_HOSTNAME for $SYSTEMD_CHECK_USER] CRITICAL $SERVICE";
|
||||
echo "-> $SUBJECT: $MESSAGE";
|
||||
|
||||
if [ "$SYSTEMD_CHECK_MAIL_ENABLED" = true ]; then
|
||||
echo $MESSAGE|mailx -Ssendwait -s "$SUBJECT" $SYSTEMD_CHECK_MAIL_ADDRESS;
|
||||
fi
|
||||
fi
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# execute check for defined SYSTEMD_CHECK_SERVICES
|
||||
for service in "${SYSTEMD_CHECK_SERVICES[@]}"; do
|
||||
echo "Checking $service...";
|
||||
checkService "$service"
|
||||
done
|
15
usr/share/doc/borgwrapper/.borgwrapper.conf.example
Normal file
15
usr/share/doc/borgwrapper/.borgwrapper.conf.example
Normal file
|
@ -0,0 +1,15 @@
|
|||
BORGWRAPPER_BACKUP_NAME="backup-name"
|
||||
BORGWRAPPER_BACKUP_REPOSITORY="/mnt/myBackups/"
|
||||
BORGWRAPPER_BACKUP_FILES=(\
|
||||
'/etc/' \
|
||||
'$HOME/' \
|
||||
)
|
||||
BORGWRAPPER_BORG_INIT_PARAMS="--encryption=repokey-blake2"
|
||||
|
||||
borgwrapper_pre_backup() {
|
||||
return;
|
||||
}
|
||||
|
||||
borgwrapper_post_backup() {
|
||||
return;
|
||||
}
|
1
usr/share/doc/checkupdates/.checkupdates.conf.example
Normal file
1
usr/share/doc/checkupdates/.checkupdates.conf.example
Normal file
|
@ -0,0 +1 @@
|
|||
CHECKUPDATES_MAIL_ADDRESS="alias@domain.tld"
|
|
@ -0,0 +1,3 @@
|
|||
DISK_SPACE_ALERT_MAIL_ADDRESS="alias@domain.tld"
|
||||
#DISK_SPACE_ALERT_THRESHOLD=99
|
||||
#DISK_SPACE_ALERT_MOUNTPOINTS=("/", "/home")
|
4
usr/share/doc/docker_check/.docker_check.conf.example
Normal file
4
usr/share/doc/docker_check/.docker_check.conf.example
Normal file
|
@ -0,0 +1,4 @@
|
|||
#DOCKER_CHECK_LIST_FILE="/root/other/directory/prefix_docker_check.list"
|
||||
#DOCKER_CHECK_NOTIFY_LEVELS=("UNKNOWN" "WARNING" "CRITICAL")
|
||||
#DOCKER_CHECK_MAIL_ENABLED=true
|
||||
#DOCKER_CHECK_MAIL_ADDRESS="alias@domain.tld"
|
|
@ -0,0 +1,2 @@
|
|||
MEMORY_USAGE_ALERT_MAIL_ADDRESS="alias@domain.tld"
|
||||
#MEMORY_USAGE_ALERT_THRESHOLD=512
|
|
@ -0,0 +1,2 @@
|
|||
SMARTCTL_TESTS_LONG_MAIL_ADDRESS="alias@domain.tld"
|
||||
#SMARTCTL_TESTS_LONG_DEVICES=512
|
3
usr/share/doc/systemd_check/.systemd_check.conf.example
Normal file
3
usr/share/doc/systemd_check/.systemd_check.conf.example
Normal file
|
@ -0,0 +1,3 @@
|
|||
SYSTEMD_CHECK_MAIL_ENABLED=true
|
||||
SYSTEMD_CHECK_MAIL_ADDRESS="alias@domain.tld"
|
||||
SYSTEMD_CHECK_LIST_FILE="$HOME/.systemd_check.list"
|
1
usr/share/doc/systemd_check/.systemd_check.list.example
Normal file
1
usr/share/doc/systemd_check/.systemd_check.list.example
Normal file
|
@ -0,0 +1 @@
|
|||
demo.service
|
Loading…
Reference in a new issue