• Linux 系统服务注册


    Linux注册系统服务步骤
    1.编写服务脚本
    2.拷贝到/etc/init.d目录下
    3.为服务脚本添加可执行权限   >>chmod a+x xxxd
    4.添加到系统服务中           >>chkconfig --add xxxd
    5.检测是否添加成功           >>chkconfig --list | grep xxxd
    6.设置开机启动               >>chkconfig xxxd on
    7.删除系统服务命令             >>chkconfig --del xxxd
     
    #!/bin/bash
    # chkconfig: - 90 10
    # description: asr service
    
    #设置启动文件
    startup=/home/test/src/asr_server
    
    #设置相应的环境变量
    export LD_LIBRARY_PATH=/home/test/lib:$LD_LIBRARY_PATH
    
    start(){
        echo -n "Starting asr service:"
        RETVAL=`ps -ef |grep asr_serve[r] |awk -F " " '{print $2}'`
        if [ -n $RETVAL ];then
            $startup
        fi
        echo "asrserver is succeessfully started up"
    }
    
    stop(){
        echo -n "Shutting down tomcat: "
        RETVAL=`ps -ef |grep asr_serve[r] |awk -F " " '{print $2}'`
        if [ -z $RETVAL ];then
            RETVAL=`kill -9 $RETVAL`
        fi
        echo "tomcat is succeessfully shut down."
    }
    
    status(){
        RETVAL=`ps -ef |grep asr_serve[r] |awk -F " " '{print $2}'`
        if [ -n $RETVAL ];then
            echo "asrserver is running..." 
        else
            echo "asrserver is stopped..." 
        fi
    }
    
    restart(){
        echo -n "restart asr service:"
        RETVAL=`ps -ef |grep asr_serve[r] |awk -F " " '{print $2}'`
        if [ -z $RETVAL ];then
            RETVAL=`kill -9 $RETVAL`
        fi
        $startup
        echo "asrserver is succeessfully started up"
    }
    
    case "$1" in
    start)
        start
        ;;
    stop)
        stop 
        ;;  
    status)
        status
        ;;
    restart)
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
    esac

    注意事项

    >>service xxxd start
    env: /etc/init.d/xxxd: 没有那个文件或目录
    报错原因:文件格式可能不正确,有可能是dos文件,也可能文件中有 等windows转义字符
    解决方案:
    1.如果文件格式不正确,那么使用Notepad工具转码
    2.判断文件中是否有 这种不可见转义字符,可以把xxxd当做shell脚本执行,执行就会报错"行4: $' ': 未找到命令",
    解决办法
    使用vi打开文本文件
    vi xxxd
    命令模式下输入
    :set fileformat=unix
    :wq
     
     
    # chkconfig: - 90 10命令解释
     
    2345表示系统运行级别是2,3,4或者5时都启动此服务,该项也可以设置为"-"表示默认
    20,是启动的优先级,80是关闭的优先级,
    如果启动优先级配置的数太小时如0时,则有可能启动不成功,
    因为此时可能其依赖的网络服务还没有启动,从而导致自启动失败。
     
    #"#chkconfig: - 90 10" 和 "#description: xxx"是必须的,否则在运行chkconfig --add auto_run时,会报错,描述文字可以自定义。
  • 相关阅读:
    第一讲小结(位运算)
    新学期开始
    前缀表达式-怎样用空格分隔一个字符串
    计概期末前的小小总结
    动规作业-求数组不相邻元素之和的最大值
    网格-递归作业2-放苹果问题
    1025 数的划分(搜索和递推方法)
    网格-递归作业 集合里的乘法
    网格-递归作业 城堡问题
    去先导零的一个大坑
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/9689462.html
Copyright © 2020-2023  润新知