Create a gist now

Instantly share code, notes, and snippets.

Filesystem prefetch init.d script
#!/bin/bash
### BEGIN INIT INFO
# Provides: usr-prefetch
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Prefetch system files to page cache.
# Description: Prefetches files under /opt, /usr and /etc, and the FS entries for /.
### END INIT INFO
FULL_PREFETCH_PATHS="/usr /opt /usr/sbin /usr/lib /usr/bin /sbin /lib /bin /etc"
ENTRY_PREFETCH_PATHS="/usr /"
prefetch_full() {
find $1 -type f -mount -print0 -readable 2>/dev/null | xargs -0 -L 200 cat >/dev/null
}
prefetch_entries() {
find $1 -type f -mount -print0 -readable 2>/dev/null >/dev/null
}
prefetch() {
for f in $FULL_PREFETCH_PATHS
do
prefetch_full $f
done
for f in $ENTRY_PREFETCH_PATHS
do
prefetch_entries $f
done
}
case "$1" in
start)
prefetch &
;;
stop)
;;
restart|force-reload)
prefetch &
;;
*)
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment