I have a script on the PI to shutdown my NAS "shutdown_nas.sh". I have created that script in /etc/init.d according to the instructions in /etc/init.d/README
It is symlinked in /etc/rc0.d/K01NAS_shutdown.sh
It works fine when I call:
sudo service shutdown_nas.sh stop
It also works fine when I halt the PI when I'm on ethernet (eth0).
It doesn't work on WIFI only, it seems like wlan is down before the needed request is done.