So by default I am in runlevel 3. During shutdown I switch into runlevel 0. But I am not getting any success if am putting my script (having a curl call) in /etc/rc0.d/, as in runlevel 0 network is already stopped and therefore it is not able to do the curl call.
How to get the desired result ?
Generally in the older SysVinit systems, boot sequence and shutdown sequence were controlled by the alpha-numeric order of symbolic links to your init-script located in each runlevel directory under
/etc/init.d(or/etc/rc.d/) where the links numberedS##(start) were run during boot andK##(kill/stop) scripts were run during shutdown. The services available at any given point in time are controlled by what is running during the boot or shutdown sequence. For example an older SuSE scheme would be:If you look at the boot/shutdown sequence for runlevel-3 in
/etc/init.d/rc3.d/you see that the network start and shutdown are controlled byS05networkon boot andK18networkon shutdown. So if you wanted to create a custom script to runcurlon shutdown prior to the network shutting down, you would need to create an init script and create a soft-link in/etc/init.d/rc3.dand have it numbered prior to the network services (ssh, etc.) being taken down. Above if you created and numbered the soft-link to your kill scriptK10curlonsd(curl on shutdown), it would run aftercronshutdown, but before any of the network services were taken down.The scheme should still be the same on centos, although your
/etc/init.dmay be/etc/rc.d, etc., but the general approach will be the same. Let me know if you have any questions.