zoukankan      html  css  js  c++  java
  • 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时,会报错,描述文字可以自定义。
  • 相关阅读:
    JS—超酷时钟
    JS—简单年历表
    ZZULI 1783 简单的求和
    ZZULI 1788 小金刚的宝藏(01背包模板)
    HDU 5172 GTY's gay friends(BestCoder Round #29)
    HDU 2157 How many ways??
    HDU 5171 GTY's birthday gift(BestCoder Round #29)
    在SQL Server 中启用 FileStream
    (转载)SQL Server的一个不显眼的功能 备份文件的分割
    面向对象建模方法与数据库建模方法的比较
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/9689462.html
Copyright © 2011-2022 走看看