bash error handling and reporting is atrocious. Without -e it will just ignore errors. With -e it will stop on errors, but not report where the error happened (apart from exiting itself with an error code). Improve that with the `trap ERR` command. Note that this won't be invoked on intentional error exit with `exit 1`. We apply this on every bash script that contains -e or that it appears trivial to set it in. Non-trivial scripts without -e are left unmodified, since they might intentionally invoke failing scripts. Closes scylladb/scylladb#22747
40 lines
1.1 KiB
Bash
40 lines
1.1 KiB
Bash
#!/bin/bash -e
|
|
#
|
|
# Copyright (C) 2023-present ScyllaDB
|
|
#
|
|
|
|
#
|
|
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
#
|
|
|
|
trap 'echo "error $? in $0 line $LINENO"' ERR
|
|
|
|
version_ge() {
|
|
[ "$2" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
|
|
}
|
|
|
|
KERNEL_VER=$(uname -r)
|
|
|
|
if ! version_ge $KERNEL_VER 5.8; then
|
|
# On older kernel environment, we have to relax perf_event_paranoid setting
|
|
# since there is no CAP_PERFMON.
|
|
PERF_EVENT_PARANOID=1
|
|
elif [ $(cat /proc/sys/kernel/perf_event_paranoid) -ge 3 ]; then
|
|
# On Debian/Ubuntu, it deny access from non-root even with CAP_PERFMON
|
|
# It requires to set perf_event_paranoid=2 to use CAP_PERFMON with non-root
|
|
PERF_EVENT_PARANOID=2
|
|
fi
|
|
if [ -n "$PERF_EVENT_PARANOID" ]; then
|
|
cat << EOS > /etc/sysctl.d/99-scylla-perfevent.conf
|
|
kernel.perf_event_paranoid = $PERF_EVENT_PARANOID
|
|
EOS
|
|
sysctl -p /etc/sysctl.d/99-scylla-perfevent.conf
|
|
fi
|
|
|
|
if [ ! -d /run/systemd/system ]; then
|
|
exit 0
|
|
fi
|
|
|
|
systemctl --system daemon-reload >/dev/null || true
|
|
systemctl --system enable --now scylla-tune-sched.service || true
|