Skip to content

Instantly share code, notes, and snippets.

@jasoares
Created January 18, 2016 09:06
Show Gist options
  • Save jasoares/403305e4a96878699028 to your computer and use it in GitHub Desktop.
Save jasoares/403305e4a96878699028 to your computer and use it in GitHub Desktop.
Bash script to setup /etc/init.d/disable-transparent-hugepages on multiple nodes
nodes=(rs0p rs0s)
for i in "${nodes[@]}"; do ssh -ti ~/.ec2/your_aws_key_pair.pem "ec2-user@$i.onliquid.com" 'sudo touch /etc/init.d/disable-transparent-hugepages && sudo bash -c "echo \"#!/bin/sh
### BEGIN INIT INFO
# Provides: disable-transparent-hugepages
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before: mongod mongodb-mms-automation-agent
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description: Disable Linux transparent huge pages, to improve
# database performance.
### END INIT INFO
case \\\$1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
return 0
fi
echo '"'"'never'"'"' > \\\${thp_path}/enabled
echo '"'"'never'"'"' > \\\${thp_path}/defrag
unset thp_path
;;
esac
\" > /etc/init.d/disable-transparent-hugepages" && sudo chmod 755 /etc/init.d/disable-transparent-hugepages && sudo chkconfig --add disable-transparent-hugepages && sudo /etc/init.d/disable-transparent-hugepages start && cat /sys/kernel/mm/transparent_hugepage/enabled && cat /sys/kernel/mm/transparent_hugepage/defrag'; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment