CentOS的SystemVinit启动脚本

CentOS系统本身自带了说明,在/usr/share/doc/initscripts-(*)/sysvinitfiles,内容如下:所有System V init脚本都命名为/etc/rc.d/init.d/,其中是服务的名称。必须没有“.init”后缀。

为榕江等地区用户提供了全套网页设计制作服务,及榕江网站建设行业解决方案。主营业务为成都网站建设、网站建设、榕江网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

示例脚本:

#!/bin/bash
#
# /etc/rc.d/init.d/ 
#
#  
#  
#
#   # of the file to the end of the tags section must begin with a # # character. After the tags section, there should be a blank line. # This keeps normal comments in the rest of the file from being # mistaken for tags, should they happen to fit the pattern.> # Source function library. . /etc/rc.d/init.d/ functions  local   shell functions used by the code that follows>

case "$1" in
   start)
       echo -n "Starting    services: " 
       
  
   function>        touch /var/lock/subsys/
   
        ;;    stop)        
    echo -n 
    "Shutting down    services: "         
    
     function>        rm -f /var/lock/subsys/
     
          ;;    status)        
      
       in free-form format,        perhaps with the status 
       function>    ;;    restart)        
       
        $0 stop; 
        $0 start>    ;;    reload)        
        
         kill -HUP or by restarting the daemons, possibly with        
         $0 stop; 
         $0 start>    ;;    probe)        
         
          then it should determine whether        or not the service needs to be restarted or reloaded (or        whatever) 
          in order to activate any changes 
          in the configuration        scripts. It should 
          print out a list of commands to give to        
          $0; see the description under the probe tag below.>    ;;    *)        
          echo 
          "Usage:    {start|stop|status|reload|restart[|probe]"         
          exit 1    ;; 
          esac 
         
        
       
      
     
    
   
  

注意:重启和重载功能可以(通常)组合成一个测试,

vis:

restart|reload)

不禁止您添加其他命令; 列出您打算以交互方式使用到使用消息的所有命令。

/etc/rc.d/init.d/functions函数

daemon [+/-nicelevel] program [arguments] [&]

如果守护程序尚未运行,则启动该守护程序。还有其他一些有用的东西,例如,如果守护进程意外终止,则保留守护进程。

killproc program [signal]

向程序发送信号; 默认情况下,它发送一个SIGTERM,如果进程没有死,它会在几秒钟后发送一个SIGKILL。

如果找到pid文件,它还会尝试删除它。

pidofproc program

试图找到一个程序的pid; 检查可能的pidfiles,使用pidof程序,甚至使用ps。主要用于此文件中的其他函数,但也可用于脚本。

status program

打印状态信息。假设程序名称与servicename相同。

Tags.

# chkconfig:          

必须。是默认情况下应启动服务的级别列表。和是优先级编号。例如:

# chkconfig:2345 20 80有关详细信息,请阅读“man chkconfig”。

除非有一个非常好的,显性相反的原因,应该等于 100 –

# description: 
  

必须。几行描述,继续使用”字符。以下行中的初始注释和后续空格将被忽略。

# description[ln]:  

可选。应将描述翻译成指定的语言。

# processname:

可选,允许多个条目。对于脚本启动的每个进程名称,应该有一个进程名称条目。例如,samba服务启动两个守护进程:

#processname:smdb
  #processname:nmdb

# config:

可选,允许多个条目。对于守护程序使用的每个静态配置文件,请使用单个条目。例如:

# config: /etc/httpd/conf/httpd.conf
  # config: /etc/httpd/conf/srm.conf

可选)如果服务器将自动重新加载配置文件(如果已更改),则可以在行中附加“autoreload”一词:

# config: /etc/foobar.conf autoreload

#pidfile:

可选,允许多个条目。使用就像配置条目一样,除了它指向pidfiles。假设pidfiles仅在进程创建时更新,而不是更晚。该文件的第一行应该是PID的ASCII表示; 终止换行符是可选的。不检查除第一行以外的任何行。

#project: true

可选,使用IN PLACE的processname,config和pidfile。如果存在,则可以通过运行以下命令来实现正确的重新加载 – 如果必要的循环:

command = $(/ etc / rd.d / init.d / SCRIPT probe)
[ -  n“$ command”] && /etc/rc.d/init.d/SCRIPT $ command

其中SCRIPT是服务的sysv init脚本的名称。

作为示例,需要执行复杂处理的脚本可以返回“run /var/tmp/

请注意,如果不需要执行任何操作使服务与其配置文件同步,则probe命令应该只是“exit 0”。

需要注意以下几点:

1、# chkconfig和# description不能少,必须写。

2、chkconfig的 为启动优先级,在man中查询不到,一般end…不用理解,直接100-start…即可。start为开始的顺序,一般系统从小执行到大,数值任意,这个对于依赖启动有很大的帮助,比如控制先启动某个服务,再启动某个服务。以下是查询设置后的命令:

# 查询启动级别
chkconfig --list 
  
   # 查询启动顺序 grep chkconfig /etc/rc.d/init.d/
   
  

本文题目:CentOS的SystemVinit启动脚本
网站链接:http://www.hantingmc.com/qtweb/news42/68692.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联