Lucas Peregrino
(usa Debian)
Enviado em 19/04/2021 - 11:51h
#!/bin/bash
### BEGIN INIT INFO
# Provides: mv.sh
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
. /lib/lsb/init-functions
DATA=$(date +%d-%m-%Y)
HORA=$(date +%H:%M)
mkdir -p /var/log/TP/
touch /var/log/TP/tpross_online.log
touch /var/log/TP/tpross_offline.log
VERIFICA=$(ps aux | grep tpross | sed -n "1p" | cut -b96-121)
sysctl -w vm.nr_hugepages=$(nproc)
for i in $(find /sys/devices/system/node/node* -maxdepth 0 -type d);
do
echo 3 > "$i/hugepages/hugepages-1048576kB/nr_hugepages";
done
echo "1GB pages successfully enabled"
case "$1" in
verifica)
if [ "$VERIFICA" = "teste.com" ] ; then
echo "Servidor Oline"
echo "No dia $DATA, as $HORA => O servidor estava ligado" >> /var/log/TP/tpross_online.log
else
echo "Servidor Desligado"
echo "No dia $DATA, as $HORA => O servidor estava desligado" >> /var/log/TP/tpross_offline.log
/etc/programas/TP/build.sh start
fi
;;
turbo)
if [[ -z $(which rdmsr) ]]; then
echo "msr-tools is not installed. Run 'sudo apt install msr-tools' to install it." >&2
echo 'echo msr >> /etc/modules'
exit 1
fi
if [[ ! -z $1 && $1 != "enable" && $1 != "disable" ]]; then
echo "Invalid argument: $1" >&2
echo ""
echo "Usage: $(basename $0) [disable|enable]"
exit 1
fi
cores=$(cat /proc/cpuinfo | grep processor | awk '{print $3}')
for core in $cores; do
if [[ $1 == "disable" ]]; then
wrmsr -p${core} 0x1a0 0x4000850089
fi
if [[ $1 == "enable" ]]; then
modprobe msr
wrmsr -p${core} 0x1a0 0x850089
fi
state=$(rdmsr -p${core} 0x1a0 -f 38:38)
if [[ $state -eq 1 ]]; then
echo "core ${core}: disabled"
else
echo "core ${core}: enabled"
fi
done
;;
*)
echo "Usage: /etc/init.d/build.sh {verifica|turbo}"
exit 1
;;
esac
exit 0