Make scripts work for global user
This commit is contained in:
parent
00f034a9a8
commit
bf6615b034
9 changed files with 326 additions and 162 deletions
|
@ -5,7 +5,7 @@ usage() {
|
|||
USAGE=$(cat <<EOF
|
||||
Usage: check_updates [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.check_updates.conf is used. This fallback option
|
||||
If no CONFIG_FILE is given, HOME/.check_updates.conf or /etc/check_updates.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.
|
||||
|
@ -27,26 +27,42 @@ UPDATES_AMOUNT=$(/usr/bin/checkupdates|wc -l)
|
|||
CHECK_UPDATES_MAIL_ADDRESS="";
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.check_updates.conf"
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf"
|
||||
|
||||
if [ "$UPDATES_AMOUNT" -gt "0" ]; then
|
||||
mailx -s "[updates $HOSTNAME]" $CHECK_UPDATES_MAIL_ADDRESS << EOF
|
||||
|
|
|
@ -5,7 +5,7 @@ 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
|
||||
If no CONFIG_FILE is given, HOME/.disk_space_alert.conf or /etc/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.
|
||||
|
@ -31,26 +31,42 @@ DISK_SPACE_ALERT_THRESHOLD=93
|
|||
DISK_SPACE_ALERT_MOUNTPOINTS=("/")
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.disk_space_alert.conf"
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
source_config "$1" "$HOME/.disk_space_alert.conf" "/etc/disk_space_alert.conf"
|
||||
|
||||
for point in "${DISK_SPACE_ALERT_MOUNTPOINTS[@]}"
|
||||
do
|
||||
|
|
|
@ -5,7 +5,7 @@ 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
|
||||
If no CONFIG_FILE is given, HOME/.docker_check.conf or /etc/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.
|
||||
|
@ -26,45 +26,69 @@ set -e;
|
|||
|
||||
HOSTNAME=$(hostname)
|
||||
DOCKER_CHECK_LIST_FILE="$HOME/.docker_check.list"
|
||||
DOCKER_CHECK_GLOBAL_LIST_FILE="/etc/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;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
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.";
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
source_config "$1" "$HOME/.docker_check.conf" "/etc/docker_check.conf"
|
||||
|
||||
listFileToUse=""
|
||||
if [[ -f "$DOCKER_CHECK_LIST_FILE" ]]; then
|
||||
listFileToUse="$DOCKER_CHECK_LIST_FILE"
|
||||
else
|
||||
listFileToUse="$DOCKER_CHECK_GLOBAL_LIST_FILE"
|
||||
fi
|
||||
|
||||
if [[ ! -f $listFileToUse ]]; then
|
||||
echo "$listFileToUse doesn't exist. Add a file which holds one systemd service or timer per line.";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Scanning $DOCKER_CHECK_LIST_FILE for containers...";
|
||||
echo "Scanning $listFileToUse for containers...";
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||
CONTAINERS+=("$line")
|
||||
echo "-> Found $line";
|
||||
done < "$DOCKER_CHECK_LIST_FILE"
|
||||
done < "$listFileToUse"
|
||||
|
||||
# check if current status is in array of DOCKER_CHECK_NOTIFY_LEVELS
|
||||
function shouldLog() {
|
||||
|
|
|
@ -5,7 +5,7 @@ usage() {
|
|||
USAGE=$(cat <<EOF
|
||||
Usage: docker_compose_update [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.docker_compose_update.conf is used. This fallback option
|
||||
If no CONFIG_FILE is given, HOME/.docker_compose_update.conf or /etc/docker_compose_update.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.
|
||||
|
@ -29,25 +29,42 @@ set -e;
|
|||
declare -A DOCKER_COMPOSE_UPDATE_COMMANDS;
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
|
||||
apply_defaults() {
|
||||
[[ -z ${DOCKER_COMPOSE_UPDATE_IGNORES} ]] && DOCKER_COMPOSE_UPDATE_IGNORES=();
|
||||
[[ -z ${DOCKER_COMPOSE_UPDATE_COMMAND} ]] && DOCKER_COMPOSE_UPDATE_COMMAND="docker-compose down; docker-compose pull; docker-compose up -d;"
|
||||
|
@ -67,7 +84,8 @@ check_required() {
|
|||
# check requirements
|
||||
CONFIG_FILE="$1";
|
||||
FALLBACK_CONFIG_FILE="${HOME}/.docker_compose_update.conf";
|
||||
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}";
|
||||
FALLBACK_CONFIG_GLOBAL_FILE="/etc/docker_compose_update.conf";
|
||||
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}";
|
||||
apply_defaults;
|
||||
check_required;
|
||||
|
||||
|
|
37
usr/local/bin/dynv6
Normal file → Executable file
37
usr/local/bin/dynv6
Normal file → Executable file
|
@ -6,7 +6,7 @@ usage() {
|
|||
USAGE=$(cat <<EOF
|
||||
Usage: dynv6 [CONFIG_FILE (absolute path)]
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.dynv6.conf is used. This fallback option
|
||||
If no CONFIG_FILE is given, HOME/.dynv6.conf or /etc/dynv6.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.
|
||||
|
@ -27,19 +27,14 @@ EOF
|
|||
}
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
|
||||
set -a;
|
||||
|
@ -47,6 +42,27 @@ source_config() {
|
|||
set +a;
|
||||
}
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
|
||||
apply_defaults() {
|
||||
if [ -z ${DYNV6_MAIL_ENABLED} ]; then
|
||||
DYNV6_MAIL_ENABLED=false;
|
||||
|
@ -84,8 +100,9 @@ check_required() {
|
|||
|
||||
# check requirements
|
||||
CONFIG_FILE="$1";
|
||||
FALLBACK_CONFIG_FILE="${HOME}/.dynv6.conf";
|
||||
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}";
|
||||
FALLBACK_CONFIG_FILE="${HOME}/dynv6.conf";
|
||||
FALLBACK_CONFIG_GLOBAL_FILE="/etc/dynv6.conf";
|
||||
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}";
|
||||
apply_defaults;
|
||||
check_required;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ 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
|
||||
If no CONFIG_FILE is given, HOME/.memory_usage_alert.conf or /etc/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.
|
||||
|
@ -30,26 +30,43 @@ MEMORY_USAGE_ALERT_MAIL_ADDRESS="";
|
|||
MEMORY_USAGE_ALERT_THRESHOLD=512;
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.memory_usage_alert.conf"
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
|
||||
source_config "$1" "$HOME/.memory_usage_alert.conf" "/etc/memory_usage_alert.conf"
|
||||
|
||||
# DO NOT TOUCH BELOW
|
||||
total=$(free -mt | grep Total | awk '{print $2}')
|
||||
|
|
|
@ -5,7 +5,7 @@ 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
|
||||
If no CONFIG_FILE is given, HOME/.smartctl_tests_long.conf or /etc/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.
|
||||
|
@ -27,26 +27,42 @@ SMARTCTL_TESTS_LONG_MAIL_ADDRESS="";
|
|||
SMARTCTL_TESTS_LONG_DEVICES=(sda)
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.smartctl_tests_long.conf"
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
source_config "$1" "$HOME/.smartctl_tests_long.conf" "/etc/smartctl_tests_long.conf"
|
||||
|
||||
echo "Starting long tests for ...";
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ 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
|
||||
If no CONFIG_FILE is given, HOME/.systemd_check.conf or /etc/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.
|
||||
|
@ -29,6 +29,7 @@ set -e;
|
|||
|
||||
# vars and defaults
|
||||
SYSTEMD_CHECK_LIST_FILE="$HOME/.systemd_check.list"
|
||||
SYSTEMD_CHECK_GLOBAL_LIST_FILE="/etc/systemd_check.list"
|
||||
SYSTEMD_CHECK_MAIL_ENABLED=fase
|
||||
SYSTEMD_CHECK_MAIL_ADDRESS=""
|
||||
SYSTEMD_CHECK_HOSTNAME=$(hostname)
|
||||
|
@ -36,39 +37,62 @@ SYSTEMD_CHECK_USER=$(whoami)
|
|||
SYSTEMD_CHECK_SERVICES=()
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$1" "$HOME/.systemd_check.conf"
|
||||
|
||||
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.";
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
source_config "$1" "$HOME/.systemd_check.conf" "/etc/systemd_check.conf"
|
||||
|
||||
listFileToUse=""
|
||||
if [[ -f "$SYSTEMD_CHECK_LIST_FILE" ]]; then
|
||||
listFileToUse="$SYSTEMD_CHECK_LIST_FILE"
|
||||
else
|
||||
listFileToUse="$SYSTEMD_CHECK_GLOBAL_LIST_FILE"
|
||||
fi
|
||||
|
||||
if [[ ! -f $listFileToUse ]]; then
|
||||
echo "$listFileToUse doesn't exist. Add a file which holds one systemd service or timer per line.";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Scanning $SYSTEMD_CHECK_LIST_FILE for services...";
|
||||
echo "Scanning $listFileToUse for services...";
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||
SYSTEMD_CHECK_SERVICES+=("$line")
|
||||
echo "-> Found $line";
|
||||
done < "$SYSTEMD_CHECK_LIST_FILE"
|
||||
done < "$listFileToUse"
|
||||
|
||||
# get status for a service
|
||||
function checkService() {
|
||||
|
|
|
@ -14,7 +14,7 @@ OnFailure=systemd_failure_notify@%n.service
|
|||
|
||||
You should place the <scriptname>'s service into systemd's user and systemd's system folder so it can be used by global and user services.
|
||||
|
||||
If no CONFIG_FILE is given, HOME/.systemd_failure_notify.conf is used. This fallback option
|
||||
If no CONFIG_FILE is given, HOME/.systemd_failure_notify.conf or /etc/systemd_failure_notify.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.
|
||||
|
@ -43,26 +43,42 @@ SYSTEMD_FAILURE_NOTFY_USER=$(whoami)
|
|||
SYSTEMD_FAILURE_NOTIFY_MAIL_ADDRESS="";
|
||||
|
||||
# check for config file
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
apply_config() {
|
||||
local config=$1;
|
||||
|
||||
if [[ ! -f "$config" ]]; then
|
||||
if [[ ! -f "$configFallback" ]]; then
|
||||
echo "No config file specified and could not find default in '$configFallback'!";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
else
|
||||
config=$configFallback;
|
||||
fi
|
||||
fi
|
||||
if [[ ! -f "$config" ]]; then
|
||||
echo "No config file specified";
|
||||
echo "";
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
set -a;
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
source_config "$2" "$HOME/.systemd_failure_notify.conf"
|
||||
|
||||
source_config() {
|
||||
local config=$1;
|
||||
local configFallback=$2;
|
||||
local configGlobalFallback=$3;
|
||||
|
||||
if [[ -f "$config" ]]; then
|
||||
apply_config "$config";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configFallback" ]]; then
|
||||
apply_config "$configFallback";
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [[ -f "$configGlobalFallback" ]]; then
|
||||
apply_config "$configGlobalFallback";
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
source_config "$2" "$HOME/.systemd_failure_notify.conf" "/etc/systemd_failure_notify.conf"
|
||||
|
||||
SUBJECT="[systemd $SYSTEMD_FAILURE_NOTFY_HOSTNAME for $SYSTEMD_FAILURE_NOTFY_USER] $SYSTEMD_FAILURE_NOTFY_SERVICE RUN FAILED"
|
||||
MESSAGE="$SYSTEMD_FAILURE_NOTFY_SERVICE run failed"
|
||||
|
|
Loading…
Reference in a new issue