Linux(RedHat)中service命令和/etc/init.d/的关系

service xxx启动 /etc/init.d/ 目录下的xxx脚本
如一个脚本名为 mysvc保存在/etc/init.d/下可以用 service mysvc 运行mysvc脚本
echo passed in option $0 $1

if [ $1 = "start" ]
then
        echo myservice started........................................
elif [ $1 = "stop" ]
then
        echo myservice stoped........................................
else
        echo myservice not supported option........................................

fi


[root@localhost init.d]# service mysvc start
passed in option /etc/init.d/mysvc start
myservice started........................................

[root@localhost init.d]# service mysvc stop
passed in option /etc/init.d/mysvc stop
myservice stoped........................................

[root@localhost init.d]# service mysvc xxx
passed in option /etc/init.d/mysvc xxx
myservice not supported option........................................

如何增加一个服务在机器启动时启动:
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig --add servicename
    在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3.chkconfig --level 35 servicename on
    修改服务的默认启动等级。

脚本需要有下面的的内容,否则会 service servicename does not support chkconfig

# chkconfig: - 85 15
# description: description for the service

#上面为固定格式:- 表示运行级别(所有),85表示开机执行顺序,15为关机顺序,完整内容如下

#!/bin/bash
#chkconfig: - 85 15
# description: mytestservice is a serveice created for testing. 

if [ $1 = "start" ]
then
        echo myservice started `date` ....................................... >>
 /home/mytestservice.log
elif [ $1 = "stop" ]
then
        echo myservice stoped  `date` ........................................ >
> /home/mytestservice.log
else
        echo myservice not supported option `date` .............................
........... >>/home/mytestservice.log

fi


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值