初始化脚本。引导和启动活动的区别

初始化脚本。引导和启动活动的区别

我有一些脚本可以运行并关闭放置在/etc/init.d.它具有/etc/rc5.d添加的符号链接,chkconfig用于在启动时自动启动。因此,它在启动时启动service myscript start,并且可以由用户通过 等手动控制service myscript stop。众所周知,start章节中描述的序列是在启动时执行的。但我还需要执行一些活动仅有的当系统已经启动时,在启动时无需给予用户手动执行此活动的显式访问权限。在本文据描述,我们可以将boot()序列添加到脚本中,并且它只会在启动时执行。但那东西不起作用。我尝试了不同的方法:将其写为boot()andfunction boot()但结果是相同的:它不起作用。因此出现了一些问题:它是特定于分发的功能还是这个序列必须位于脚本的某个位置?如果两者都错误(或者如果所有内容boot()都错误或已弃用),我如何才能仅在启动时执行某些操作?我的系统是Linux Red Hat Enterprise 6.

这是我的脚本:

#!/bin/bash
#Some comments here

#some inclusions of another scripts here

function startService()
{
      #some activity for launching
}
boot()
{
        #That's it. Here I want to perform some preparations (remove files)
        #and then launch starting sequence:
        if [ -f "somefilename" ]
        then
            rm -f "somefilename"
        fi
        startService
}
function stopService()
{
        #Activity for stopping
}

#Some functions for service's status retrieving here

case "$1" in
        start)
                startService
                ;;
        stop)
                stopService
                ;;
        status)
                #Calls of status functions
                ;;
        *)
                echo "Usage: {start | stop | status}"
                exit 1
                ;;
esac

提前致谢。

答案1

我不熟悉具有 boot() 部分的 init 脚本,因此它可能是 OpenWRT 或 busybox 特有的。在 RHEL6 中,只能使用“start”参数来调用 init 脚本,而不会使用“boot”参数来调用。

要让脚本在 RHEL6 中启动时运行,您需要在 /etc/init 目录中为 Upstart 配置一个“conf 文件”。我建议将 /etc/init/rc.conf 作为起始示例。将其命名为类似myscript.conf,并用这样的内容填充它:

# adjust the runlevels if you don't want to run myscript in every runlevel
start on runlevel [0123456]

# this tells init to just run this once and let it exit
task

# if you want to see the output from your script on the console, use the following line; otherwise remove it
console output

# call myscript with a boot flag (to keep one copy of your script in /etc/init.d; adjust this if you'd rather have a separate boot-script)
exec /etc/init.d/myscript boot

请参阅有关 upstart 的 init 的更多信息man -s5 init

相关内容