创建服务类脚本

  

服务类脚本:
start

SysV: /etc/rc.d/init.d
start|stop|restart|status
reload|configtest

chkconfig

# chkconfig: runlevels SS KK 当chkconfig命令来为此脚本在rc#.d目录创建链接时,runlevels表示默认创建为S*开头的链接,-表示没有级别默认为S*开头的链接;除此之外的级别默认创建为K*开头的链接;
S后面的启动优先级为SS所表示的数字;K后面关闭优先次序为KK所表示的数字;
# description: 用于说明此脚本的简单功能; \, 续行

chkconfig --list: 查看所有独立守护服务的启动设定;独立守护进程!
chkconfig --list SERVICE_NAME

chkconfig --add SERVICE_NAME

chkconfig --del SERVICE_NAME

chkconfig [--level RUNLEVELS] SERVICE_NAME {on|off}
如果省略级别指定,默认为2345级别;

样例:

#!/bin/bash

# chkconfig: 2345 88 11    ###注意冒号,配置runlevel  SS  KK
# description: myservices  ### 描述信息
FILEPATH=/var/lock/subsys/myservice

status()  {
   if [ -e $FILEPATH ]; then
     echo "myservices is running"
   else
     echo "myservices is stopped"
    fi
}

 usage() {

    echo " `basename $0` {start|stop|restart|staus}  "
}

case $1 in 
start)
            touch $FILEPATH  &> /dev/null
            echo "myservices is starting"
;;
 stop)
            rm -rf  $FILEPATH
            echo "myservices is stopping"
;;
restart)
          echo "myservice is restarting"
;;
 status)
            status
;;             
 *)
           usage ;;
esac

 

 

# cd rc.local
# chkconfig --add myservices # find -name "*myservices*" ./rc6.d/K11myservices ./rc4.d/S88myservices ./rc0.d/K11myservices ./rc1.d/K11myservices ./rc3.d/S88myservices ./rc2.d/S88myservices ./init.d/myservices ./rc5.d/S88myservices # chkconfig --list myservices myservices 0:off 1:off 2:on 3:on 4:on 5:on 6:off # chkconfig --level 24 myservices off # chkconfig --list myservices myservices 0:off 1:off 2:off 3:on 4:off 5:on 6:off # chkconfig --del myservices # find -name "*myservices*" ./init.d/myservices # chkconfig --list myservices service myservices supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add myservices')

 

posted @ 2016-09-26 13:44  岁月童话  阅读(354)  评论(0编辑  收藏  举报