美文网首页
简易init.d脚本

简易init.d脚本

作者: bluexiii | 来源:发表于2016-11-22 14:36 被阅读153次
    #!/bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          redsocks
    # Required-Start:    $network
    # Required-Stop:     $network
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start redsocks daemon.
    ### END INIT INFO
    
    SERVICE_NAME=redsocks
    SERVICE_PATH=/usr/local/bin/redsocks
    SERVICE_PARAM="-c /etc/redsocks.conf"
    SERVICE_HOME=/home/pi
    SERVICE_USER=pi
    SERVICE_PID_FILE=/var/run/${SERVICE_NAME}.pid
    
    start() {
        start-stop-daemon --start \
        --chdir  "${SERVICE_HOME}" \
        --chuid "${SERVICE_USER}" \
        --user "${SERVICE_USER}" \
        -b -m -p "${SERVICE_PID_FILE}" \
        --exec ${SERVICE_PATH} -- ${SERVICE_PARAM}
    }
    
    stop() {
        start-stop-daemon --stop \
        --chdir "${SERVICE_HOME}" \
        --chuid "${SERVICE_USER}" \
        --user "${SERVICE_USER}" \
        -p "${SERVICE_PID_FILE}"
    }
    
    case "$1" in
        start)
           start
           ;;
        stop)
           stop
           ;;
        restart)
           stop
           start
           ;;
        status)
           # code to check status of app comes here
           # example: status program_name
           ;;
        *)
           echo "Usage: $0 {start|stop|status|restart}"
    esac
    
    exit 0
    

    相关文章

      网友评论

          本文标题:简易init.d脚本

          本文链接:https://www.haomeiwen.com/subject/hlgppttx.html