summaryrefslogtreecommitdiff
path: root/nureadahead-init
diff options
context:
space:
mode:
Diffstat (limited to 'nureadahead-init')
-rwxr-xr-xnureadahead-init30
1 files changed, 30 insertions, 0 deletions
diff --git a/nureadahead-init b/nureadahead-init
new file mode 100755
index 0000000..f8b315b
--- /dev/null
+++ b/nureadahead-init
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+usage() {
+ echo "usage: nureadahead-init [FILE [TIMEOUT [INIT [ARGS...]]]]" >&2
+}
+
+case "$1" in
+ -*) usage; exit 1
+esac
+
+case "$#" in
+ 0) file=/.nureadahead timeout=120 init=init;;
+ 1) file=$1 timeout=120 init=init; shift 1;;
+ 2) file=$1 timeout=$2 init=init; shift 2;;
+ *) file=$1 timeout=$2 init=$3; shift 3;;
+esac
+
+export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+device=$(awk '$2 == "/" { d=$1 } END { print d }' < /proc/self/mounts)
+if [ -n "$device" ]; then
+ if [ -e "$file" ]; then
+ nureadahead-preload "$device" < "$file" &
+ else
+ echo "nureadahead-init: no file, skipping preload" >&2
+ fi
+ nureadahead-collect "$device" "$timeout" > "$file" &
+else
+ echo "nureadahead-init: cannot find root device, skipping preload + collect" >&2
+fi
+exec "$init" "$@"