简体   繁体   English

在SysVinit中关闭之前执行具有curl调用的脚本

[英]Execute a script having curl call before shutdown in SysVinit

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. 因此,默认情况下,我处于运行级别3。在关闭期间,我切换到运行级别0。但是,如果将我的脚本(具有curl调用)放在/etc/rc0.d/ ,则不会获得任何成功,就像在运行级别0网络中那样。已经停止,因此无法执行curl调用。

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 numbered S## (start) were run during boot and K## (kill/stop) scripts were run during shutdown. 通常,在较旧的SysVinit系统中,引导顺序和关闭顺序由符号链接的字母数字顺序控制,该符号链接位于/etc/init.d (或/etc/rc.d/ )下每个运行级别目录中的init脚本。其中编号为S## (开始)的链接在引导期间运行,而K## (kill / stop)脚本在关机期间运行。 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: 例如,较旧的SuSE方案为:

/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. 如果在/etc/init.d/rc3.d/查看runlevel-3的启动/关闭顺序,则会看到网络启动和关闭由启动时的K18network和关闭时的S05network控制。 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. 因此,如果要创建自定义脚本以在网络关闭之前在关闭时运行curl ,则需要创建一个初始化脚本并在/etc/init.d/rc3.d创建一个软链接并对其进行编号在关闭网络服务( ssh等)之前。 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. 在上面,如果您创建了杀死链接K10curlonsd (关闭时卷曲)的软链接并对其编号,则它将在cron关闭后但在关闭任何网络服务之前运行。

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. 尽管您的/etc/init.d可能是/etc/rc.d等,但方案在centos上仍应相同,但是一般方法是相同的。 Let me know if you have any questions. 如果您有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM