linux服务脚本/etc/init.d/xxxx

服务脚本的写法:

#!/bin/bash

### BEGIN INIT INFO
# Provides:          MyServer
# RequiRED-Start:    $all
# RequiRED-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: my service.
# Description:       my service.
### END INIT INFO

RED="\\e[31m"
GREEN="\\e[32m"
YELLOW="\\e[33m"
BLACK="\\e[0m"
POS="\\e[60G"

ok_msg(){
    echo -e "${1}${POS}${BLACK}[${GREEN}  OK  ${BLACK}]"
}

failed_msg(){
    echo -e "${1}${POS}${BLACK}[${RED}FAILED${BLACK}]"
}

start() {
    failed_msg "Scheduler started, should not start it again."
}

stop() {
    ok_msg "Stopping scheduler..."
}

status() {
    echo "status ok!"
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac
exit $RETVAL


你可能感兴趣的:(linux服务脚本/etc/init.d/xxxx)