{codewalker}<=Sat Mar 03-03:08 PM=>

==>~/my_script<==

=>$cat start_web_server.sh

#!/bin/bash

USAGE(){

cat <<EOF

1:start php,nginx,varnish;

2:stop php,nginx,varnish;

3:restart php,nginx,varnish;

EOF

}

function start_php_nginx_varnish (){

echo 'starting php-fpm...';

sudo /etc/rc.d/php-fpm start

echo 'starting nginx...';

sudo /etc/rc.d/nginx start

echo 'starting varnish';

sudo varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:8080

sudo /etc/rc.d/varnish start

}

function stop_php_nginx_varnish (){

echo 'stop webserver';

sudo /etc/rc.d/php-fpm stop

sudo /etc/rc.d/nginx stop 

sudo /etc/rc.d/varnish stop

sudo pkill varnish

}

function restart_php_nginx_varnish (){

stop\_php\_nginx_varnish

start\_php\_nginx_varnish

}

function mysql_control(){

echo "you chose $@ mysql"

case "$1" in

 #control mysql case statement



START|start) echo "now start mysql"

    sudo /etc/rc.d/mysqld start;;



STOP|stop) echo "now stop mysql"

    sudo /etc/rc.d/mysqld stop;;



RESTART|restart)

    sudo /etc/rc.d/mysqld start;;



q|Q) done="true" #ends while loop 

    ;;

 *)   echo "Invalid option, choose again...";;

esac

}

count_input=0

while [ “$switch” == ‘’ ]; do

 read -p "what are you doing?" switch

 ((count_input++))

# echo $count_input

 if \[ $count_input -ge 3 \];then

    USAGE

 fi

 if \[ $count_input -ge 5 \];then

     echo 'are u nuts!!!'

     mytime=5

     less_time=10

     while \[ $mytime -ge -4 \];do

         sleep 1

         ((less_time--))

         echo $less_time

         ((mytime--))

     done

     echo 'quitting....'

     exit 0

 fi

done

if [ “$switch” == “1” ];then

start\_php\_nginx_varnish

read -p 'Do you start mysql(type:1=yes or 2=no)' is\_start\_mysql

if \[ "$is\_start\_mysql" == "1" \];then

    mysql_control 'start'

fi

fi

if [ “$switch” == “2” ];then

stop\_php\_nginx_varnish

read -p 'Do you stop mysql(type:1=yes or 2=no)' is\_start\_mysql

if \[ "$is\_start\_mysql" == "1" \];then

     mysql_control 'stop'

fi

fi

if [ “$switch” == “3” ];then

restart\_php\_nginx_varnish

read -p 'Do you restart mysql(type:1=yes or 2=no)' is\_start\_mysql

if \[ "$is\_start\_mysql" == "1" \];then

    mysql_control 'restart'

else

    echo 'i chose no'

fi

fi