文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>自定义Linux service

自定义Linux service

时间:2006-12-30  来源:int345

  1.写一个脚本接受 start,stop 等等参数。比如   FileName:test  

#!/bin/bash

# source function library

. /etc/rc.d/init.d/functions

usage(){

  echo " usage:$0 {start|stop|restart} "

}

start(){

  echo "Start."

}

stop(){

 echo "Stop."

}

restart(){

  stop

  start

}

#main function

case $1 in

  start)

     start

     ;;

  stop)

     stop

     ;;

  restart)

     restart

     ;;

  *)

     usage

     ;;

esac

2.将脚本放进/etc/init.d目录下,此时就能用 service test start 来进行管理了。

3.运行chkconfig --list test,会出现错误提示:

service test does not support chkconfig

4.在代码头部加入注释

# chkconfig: 345 85 15

# description: Thisis a test service.

这个注释表示test服务在运行级别345下自动启动(/etc/rc.d/下 rc3.d rc4.d rc5.d都用相应链接到init.d/test),启动的优先级是85,停止的优先级是15。这样就能自动在相应的rc#.d/生成 S##test和K##test了。

这时就能用 chkconfig 和 ntsysv 进行管理了。

 

 

相关阅读 更多 +
排行榜 更多 +
武士刀之战

武士刀之战

休闲益智 下载
闲置肥皂切割

闲置肥皂切割

休闲益智 下载
大航海时代2

大航海时代2

休闲益智 下载