服务不支持chkconfig解决方法脚本

写了脚本,想用命令chkconfig加载自启动.提示"**服务不支持chkconfig",原来是自己写的脚本时,忘记写两行了.开头一般要这样写

#!/bin/bash
#chkconfig:345 61 61 //此行的345参数表示,在哪些运行级别启动,启动序号(S61);关闭序号(K61)
#description:Apache //此行必写,描述服务.

把脚本拷贝至/etc/init.d/目录下,执行命令:

执行chkconfig --add Apache
#ln -s /etc/init.d/httpd /etc/rc.d/rc3.d/S61httpd
#ln -s /etc/init.d/httpd /etc/rc.d/rc4.d/S61httpd
#ln -s /etc/init.d/httpd /etc/rc.d/rc5.d/S61httpd

或者执行
#chkconfig --levels httpd 345 on

chkconfig命令会自动建立软连接,相当于ln -s 命令

 


不过别忘了要先chmod a+x scriptname来更改权限。

 

示例脚本:

#!/bin/bash
#
#
# rc.single     This file is executed by init when it goes into runlevel
#               1, which is the administrative state. It kills all
#               deamons and then puts the system into single user mode.
#               Note that the file systems are kept mounted.
#
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#               Modified for RHS Linux by Damien Neil
#
#chkconfig:345 61 61
#description:lionzl
case "$1" in
    start)
        /downloads/a
        ;;
esac

start()
{
echo "start a"
/downloads/a &
exit 0;
}
stop()
{
kill -9 a
echo "stop a"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "usage: $0 start|stop|restart"
exit 0;
esac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值