This commit is contained in:
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=00-platform-guard.inc
|
||||
source "$SCRIPT_DIR/00-platform-guard.inc"
|
||||
JOURNAL_SOURCE="$SCRIPT_DIR/../files/systemd/journald-ailab-limits.conf"
|
||||
JOURNAL_DEST="/etc/systemd/journald.conf.d/ailab-limits.conf"
|
||||
SYSCTL_SOURCE="$SCRIPT_DIR/../files/sysctl/99-ailab.conf"
|
||||
SYSCTL_DEST="/etc/sysctl.d/99-ailab.conf"
|
||||
|
||||
install_config() {
|
||||
local source_path="$1"
|
||||
local destination_path="$2"
|
||||
local mode="$3"
|
||||
local backup
|
||||
|
||||
install -d -m 0755 "$(dirname "$destination_path")"
|
||||
if [[ -f "$destination_path" ]] && cmp -s "$source_path" "$destination_path"; then
|
||||
printf 'OK: %s is already current\n' "$destination_path"
|
||||
return 0
|
||||
fi
|
||||
if [[ -f "$destination_path" ]]; then
|
||||
backup="${destination_path}.$(date '+%Y%m%d-%H%M%S').bak"
|
||||
install -m "$mode" "$destination_path" "$backup"
|
||||
printf 'INFO: backed up %s to %s\n' "$destination_path" "$backup"
|
||||
fi
|
||||
install -m "$mode" "$source_path" "$destination_path"
|
||||
printf 'OK: installed %s\n' "$destination_path"
|
||||
}
|
||||
|
||||
if ((EUID != 0)); then
|
||||
printf 'CRITICAL: tuning setup must run as root\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
require_supported_ubuntu
|
||||
for source_path in "$JOURNAL_SOURCE" "$SYSCTL_SOURCE"; do
|
||||
if [[ ! -r "$source_path" ]]; then
|
||||
printf 'CRITICAL: required configuration is missing: %s\n' "$source_path" >&2
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
|
||||
if ! command -v sysctl >/dev/null 2>&1 || ! command -v systemctl >/dev/null 2>&1; then
|
||||
printf 'CRITICAL: sysctl and systemctl are required\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! command -v sensors-detect >/dev/null 2>&1 || \
|
||||
! systemctl cat sysstat.service >/dev/null 2>&1; then
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y lm-sensors sysstat
|
||||
fi
|
||||
|
||||
install_config "$JOURNAL_SOURCE" "$JOURNAL_DEST" 0644
|
||||
install_config "$SYSCTL_SOURCE" "$SYSCTL_DEST" 0644
|
||||
|
||||
sysctl --system
|
||||
systemctl restart systemd-journald
|
||||
systemctl enable --now sysstat
|
||||
|
||||
if command -v sensors-detect >/dev/null 2>&1; then
|
||||
sensors-detect --auto || printf 'WARNING: sensors-detect did not complete successfully\n'
|
||||
fi
|
||||
printf 'OK: host tuning completed\n'
|
||||
Reference in New Issue
Block a user