bmApp服务重启脚本

bmApp服务重启脚本

[root@ansible-server-xxxtyt shell]# cat app_service_restart.sh 
#!/bin/bash
# Author: royoy
# Desc: restart services for xxxtyt app

salt_bin=/bin/salt
app_master=app-1-xxxtyt.production
app_slave=app-2-xxxtyt.production
app_project=(xxxtyt-mobile-api-restful:xxxtyt-mobile-api-restful_0 xxxtyt-mobile-api-websocket:xxxtyt-mobile-api-websocket_0 xxxtyt-mobile-api-h5web:xxxtyt-mobile-api-h5web_0)

usage(){
	echo "Usage: `basename $0` [ -r restful | -w  websocket | -h h5web ] "
}

restart_func(){
	$salt_bin $1 cmd.run "supervisorctl restart $3" && {
		$salt_bin $2 cmd.run "supervisorctl restart $3" || exit 33
	} || exit 33
}

# Interactive mode
while [[ $# -eq 0 ]]
do
	stty erase ^H
        echo "Please input option: ( b|xxxtyt ) ( x|xytt ) ( h|h5 ) ( a|api ) ( q|e|quit|exit )"
        read OPTARG
        case $OPTARG in
                r|restful)
                        restart_func $app_slave $app_master ${app_project[0]}
			wait
                        ;;      
                w|websocket)
                        restart_func $app_slave $app_master ${app_project[1]}
                        wait
                        ;;
                h|h5web)
                        restart_func $app_slave $app_master ${app_project[2]}
                        wait
                        ;;
                exit|quit|q|e)
                        exit
        esac
done

# Auto mode
while getopts ":r:w:h:" opt
do
        case $opt in
                r|restful)
			restart_func $app_slave $app_master ${app_project[0]}
			wait
                        ;;
                w|websocket)
			restart_func $app_slave $app_master ${app_project[1]}
			wait
                        ;;
                h|h5web)
			restart_func $app_slave $app_master ${app_project[2]}
			wait
                        ;;
                \?)
                        echo "Invalid option: -$OPTARG"
                        usage
                        ;;
        esac
done