zoukankan      html  css  js  c++  java
  • Linux 系统服务注册

    #!/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时,会报错,描述文字可以自定义。
    Linux注册系统服务步骤
    1.编写服务脚本
    2.拷贝到/etc/init.d目录下
    3.为服务脚本添加可执行权限    >>chmod a+x xxxd
    4.添加到系统服务中           >>chkconfig --add xxxd
    5.检测是否添加成功           >>chkconfig --list | grep xxxd
    6.设置开机启动              >>chkconfig xxxd on
    删除系统服务命令             >>chkconfig --del xxxd
  • 相关阅读:
    delphi 调用百度地图api
    Delphi XE5 for android 图片缩放和拖动处理
    利用FMX控件的MakeScreenshot过程实现WAIT效果
    老外写的在桌面添加快捷方式(DELPHI XE5 ANDROID)
    第01组 Alpha冲刺(5/6)
    2019 SDN上机第4次作业
    2019 SDN阅读作业
    第01组 Alpha冲刺(4/6)
    第01组 Alpha冲刺(3/6)
    第01组 Alpha冲刺(2/6)
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/9531938.html
Copyright © 2011-2022 走看看