Reputation: 11242
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 ?
Upvotes: 1
Views: 1232
Reputation: 84561
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 numbered S##
(start) were run during boot and K##
(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:
/etc/init.d/
boot.d/
rc0.d/ # runlevel 0
rc1.d/ # runlevel 1
rc2.d/ # runlevel 2
rc3.d/ # runlevel 3
...
S01random # S## - Start init script ## in order 00 -> XX
S01resmgr
S02consolekit
S03haldaemon
S05network # network start
...
K01stopblktrace # KXX - Kill (stop) init script ## in order
K02atieventsd
K09cron
...
K14sshd
K15smbfs
K16apcupsd
K16auditd
K16nmb
K16portmap
K16splash_early
K17syslog
K18network # network shutdown
...
rc4.d/
rc5.d/
rc6.d/
rcS.d/
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 by S05network
on boot and K18network
on shutdown. So if you wanted to create a custom script to run curl
on 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.d
and 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 script K10curlonsd
(curl on shutdown), it would run after cron
shutdown, but before any of the network services were taken down.
The scheme should still be the same on centos, although your /etc/init.d
may be /etc/rc.d
, etc., but the general approach will be the same. Let me know if you have any questions.
Upvotes: 1