源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Shell脚本注册到Linux系统服务实例

  • 时间:2022-12-16 02:27 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Shell脚本注册到Linux系统服务实例
注册一个系统服务,开机自启动. [b]1 脚本编写[/b] #vim test.sh
[u]复制代码[/u] 代码如下:
#!/bin/bash    #description: hello.sh  #chkconfig: 2345 20 81    EXEC_PATH=/usr/local/  EXEC=hello.sh  DAEMON=/usr/local/hello.sh  PID_FILE=/var/run/hello.sh.pid    . /etc/rc.d/init.d/functions    if [ ! -x $EXEC_PATH/$EXEC ] ; then         echo "ERROR: $DAEMON not found"         exit 1  fi    stop()  {         echo "Stoping $EXEC ..."         ps aux | grep "$DAEMON" | kill -9 `awk '{print $2}'` >/dev/null 2>&1         rm -f $PID_FILE         usleep 100         echo "Shutting down $EXEC: [  OK  ]"      }    start()  {         echo "Starting $EXEC ..."         $DAEMON > /dev/null &         pidof $EXEC > $PID_FILE         usleep 100         echo "Starting $EXEC: [  OK  ]"          }    restart()  {      stop      start  }    case "$1" in      start)          start          ;;      stop)          stop          ;;      restart)          restart          ;;      status)          status -p $PID_FILE $DAEMON          ;;      *)          echo "Usage: service $EXEC {start|stop|restart|status}"          exit 1  esac    exit $? 
[b]2注册服务[/b]
[u]复制代码[/u] 代码如下:
# chmod 700 test.sh # cp test.sh /etc/init.d/ # chkconfig --add test.sh # chkconfig --list
[b]3.删除服务[/b]
[u]复制代码[/u] 代码如下:
# chkconfig  --del test.sh
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部