if [ "$EUID" -ne 0 ] then echo "Please run as root" exit fi
proc=( "nginx" "mariadb" "php7.4-fpm" ) comm=( "nginx" "mariadbd" "php-fpm7.4" ) for i in "${!comm[@]}"; do ps cax | grep ${comm[i]} > /dev/null if [ $? -eq 0 ]; then if [ "$opt" = "stop" ] then service ${proc[i]} stop if [ $? -eq 0 ]; then echo "${comm[i]} stop successfully" else echo "${comm[i]} stop fail!" fi else echo "${comm[i]} is running" fi else if [ "$opt" = "start" ] then service ${proc[i]} start if [ $? -eq 0 ]; then echo "${comm[i]} start successfully" else echo "${comm[i]} start fail!" fi else echo "${comm[i]} is NOT run" fi fi done
if [ "$EUID" -ne 0 ] then echo "Please run as root" exit fi
for i in apache2 mariadb; do ps cax | grep $i > /dev/null if [ $? -eq 0 ]; then if [ "$opt" = "stop" ] then service $i stop if [ $? -eq 0 ]; then echo "$i stop successfully" else echo "$i stop fail!" fi else echo "$i is running" fi else if [ "$opt" = "start" ] then service $i start if [ $? -eq 0 ]; then echo "$i start successfully" else echo "$i start fail!" fi else echo "$i is NOT run" fi fi done