[Android Software/Hacking General [Developers Only]] zeppelinrox:
Through alot of trial and error I had come up with a bit of a hack to avoid bootloops while waiting for android to load.

basically it was "$0 & exit 0" (relaunch itself and exiting) until it was time to do something.

So your code would be like:

if [ -f "$storage/swapfile" ]; then
echo " Mounted...Time To Get Our SwapOn!!!" > $LOG
echo "" >> $LOG
swapon $storage/swapfile
echo "$(cat $storage/swappinessvalue.txt)" > /proc/sys/vm/swappiness
echo " ##########################################################################" >> $LOG
echo " #>>>>>>>°•°•°•[{[{Defiant07's SwapOn Verification!?!?!?!}]}]•°•°•°<<<<<<<#" >> $LOG
echo " ##########################################################################" >> $LOG
echo "" >> $LOG
echo " Swappy Swap Swappin' Swappiness: $(cat /proc/sys/vm/swappiness)" >> $LOG
echo " SwapOn@: $(date +"%r %Y.%m.%d")" >> $LOG
echo "" >> $LOG
free >> $LOG
echo "" >> $LOG
echo " ##########################################################################" >> $LOG
exit 0
else $0 & exit 0
fi

Of course, the script would relaunch and exit a few times before android loaded so it wasn't an ideal solution :p

Since then I moved onto using functions with a huge thanks to this thread:

[SHELL] Proper init.d and shared standard by @dk_zero-cool.

I notice now he has since changed it.

I had went with what he had originally which would result in something like this (mixing in my stuff with what dk originally posted:

swappin_time(){
while [ ! "`ps | grep -m 1 [a]ndroid`" ]; do sleep 10; done
if [ -f "$storage/swapfile" ]; then
echo " Mounted...Time To Get Our SwapOn!!!" > $LOG
echo "" >> $LOG
swapon $storage/swapfile
echo "$(cat $storage/swappinessvalue.txt)" > /proc/sys/vm/swappiness
echo " ##########################################################################" >> $LOG
echo " #>>>>>>>°•°•°•[{[{Defiant07's SwapOn Verification!?!?!?!}]}]•°•°•°<<<<<<<#" >> $LOG
echo " ##########################################################################" >> $LOG
echo "" >> $LOG
echo " Swappy Swap Swappin' Swappiness: $(cat /proc/sys/vm/swappiness)" >> $LOG
echo " SwapOn@: $(date +"%r %Y.%m.%d")" >> $LOG
echo "" >> $LOG
free >> $LOG
echo "" >> $LOG
echo " ##########################################################################" >> $LOG
exit 0
fi
}
if [ "`ps | grep -m 1 [a]ndroid`" ]; then swappin_time
else exec > /data/BootLog_SwapOn.log 2>&1
swappin_time &
fi
exit 0

In the event busybox doesnt have pgrep, I use ps instead along with grep (the square brackets in [a]ndroid avoids a false positive in case grep itself creates a hit for "android")

I also wait 10 seconds instead of 1 (I'm in no hurry and no sense in wasting cpu cycles with a 1 second wait time since there is no chance of the script effecting boot time)

If I recall, at the end, dk would have originally had this:

}
swappin_time &
exit 0

But I had to make it a little more elaborate to avoid unexplainable bootloops on some kernels.

Which is why I added the "exec > /data/BootLog_SwapOn.log 2>&1" if android isn't in memory (ie. running during bootup)

And another big thanks to user feedback for that fix lol ( I believe I owe that one to @gu5t3r )

It looks like dk's new code actually addresses that issue with the info he has since posted about logwrapper - logwrapper sounds like the "unexplainable" reason my scripts would sometimes bootloop :p

In his new method, I'd change this:

if pgrep logwrapper; then
killall logwrapper
fi

To this:

pkill -9 logwrapper

Since pkill won't spit an error if there is no logwrapper in memory.

Not sure if I'll change methods tho - I kinda like having obligatory BootLogs created for init.d scripts - even if it was orignally done to avoid bootloops on some kernels lol

edit: oh hey, why not create the swapfile if it's not found?

swappin_time(){
while [ ! "`ps | grep -m 1 [a]ndroid`" ]; do sleep 10; done
if [ ! -f "$storage/swapfile" ]; then
dd if=/dev/zero of=$storage/swapfile bs=1048576 count=$desiredsize
mkswap $storage/swapfile
fi
echo " Time To Get Our SwapOn!!!" > $LOG
echo "" >> $LOG
swapon $storage/swapfile
echo "$(cat $storage/swappinessvalue.txt)" > /proc/sys/vm/swappiness
echo " ##########################################################################" >> $LOG
echo " #>>>>>>>°•°•°•[{[{Defiant07's SwapOn Verification!?!?!?!}]}]•°•°•°<<<<<<<#" >> $LOG
echo " ##########################################################################" >> $LOG
echo "" >> $LOG
echo " Swappy Swap Swappin' Swappiness: $(cat /proc/sys/vm/swappiness)" >> $LOG
echo " SwapOn@: $(date +"%r %Y.%m.%d")" >> $LOG
echo "" >> $LOG
free >> $LOG
echo "" >> $LOG
echo " ##########################################################################" >> $LOG
exit 0
}
if [ "`ps | grep -m 1 [a]ndroid`" ]; then swappin_time
else exec > /data/BootLog_SwapOn.log 2>&1
swappin_time &
fi
exit 0

edit 2 lol:

Cool idea about the xbin scripts!

Howabout adding a line to the swapXX files?

cat > /system/xbin/swapXX << EOF
#!/system/bin/sh

echo XX> /proc/sys/vm/swappiness
[COLOR=Red]echo XX> \$storage/swappinessvalue.txt[/COLOR]
echo " All done...enjoy."
echo " You can use --cat /proc/sys/vm/swappiness--"
echo " command to verify if you want."
exit
EOF

That way, the init.d script loads the value which was last applied with a swapXX script ;)