-
-
Save 6d61726b760a/a979cb93977114406951c0a69f8ff378 to your computer and use it in GitHub Desktop.
readahead initscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# readahead set readhead for specific block devices | |
# | |
# chkconfig: 35 85 15 | |
# description: set readhead for specific block devices | |
# processname: | |
# | |
### BEGIN INIT INFO | |
# Provides: readahead | |
# Short-Description: set readahead for specific block devices | |
# Description: Use blockdev utility to set readahead for specific block devices | |
### END INIT INFO | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
# Path to the blockdev binary. | |
binary=/sbin/blockdev | |
RETVAL=0 | |
# initialize dev_list array | |
dev_list=() | |
# append devices below with format: | |
# dev_list+=("/path/to/device|readahead_val") | |
dev_list+=("/dev/vdb|32") | |
dev_list+=("/dev/dm-2|32") | |
start() { | |
for dev in "${dev_list[@]}" | |
do | |
device=${dev%%|*} | |
devicename=${device##*/} | |
value=${dev##*|} | |
store_file="/var/run/readahead-${devicename}.default" | |
# if readahead is already set to preferred value, | |
# skip to next iteration iteration | |
current_value=$(${binary} --getra ${device}) | |
if [ ${current_value} = ${value} ]; then | |
echo "preferred readahead already set ${device}:${value}" | |
continue | |
fi | |
# store the current readahead value | |
cmd="${binary} --getra ${device} > $store_file" | |
action "storing current readahead value for ${device}:" eval "${cmd}" | |
RETVAL=$? | |
# if we couldnt store the current value, skip to next iteration | |
if [ $RETVAL != 0 ]; then | |
continue | |
fi | |
# set new the preferred readahead | |
cmd="${binary} --setra ${value} ${device}" | |
action "setting readahead for ${device} to ${value}:" eval "${cmd}" | |
RETVAL=$? | |
if [ $RETVAL = 0 ]; then | |
logger -t readahead "set readahead for ${device} to ${value}" | |
fi | |
done | |
} | |
stop() { | |
for dev in "${dev_list[@]}" | |
do | |
device=${dev%%|*} | |
devicename=${device##*/} | |
store_file="/var/run/readahead-${devicename}.default" | |
# if we can open $store_file, continue | |
if [ -f ${store_file} ]; then | |
value=$(cat $store_file) | |
cmd="${binary} --setra ${value} ${device}" | |
action "restoring default readahead value for ${device}:" eval "${cmd}" | |
RETVAL=$? | |
if [ $RETVAL = 0 ]; then | |
logger -t 'readahead' "set readahead for ${device} to ${value}" | |
rm -f ${store_file} | |
fi | |
else | |
echo "could not open ${store_file}, unable to restore default value." | |
fi | |
done | |
} | |
status() { | |
for dev in "${dev_list[@]}" | |
do | |
device=${dev%%|*} | |
devicename=${device##*/} | |
cmd="${binary} --getra ${device}" | |
echo "current readahead value for ${device}: " $(eval "${cmd}") | |
done | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
*) | |
echo $"Usage: $prog {start|stop|status|help}" | |
RETVAL=2 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment