您的位置:首页 > 运维架构 > Apache

用case分支语句控制apache服务的实例

2016-08-10 10:49 260 查看
用case分支语句控制apache服务的实例

[root@ChangerLee 控制结构]# cat case_httpd.sh 

#!/bini/bash

#this is an apache command

[ -f /etc/init.d/functions ] && . /etc/init.d/functions||exit 1

if [ $# -ne 1 ]

   then

       echo "Usage:case_httpd.sh start|stop|restart"

       exit 1

else

case "$1" in 

    "start") 

    systemctl start httpd.service

    sleep 1

    action "apache is running." /bin/true

    ;;

    "stop")

    systemctl stop httpd.service

    sleep 1

    action "apache is stop." /bin/true 

    ;;

    "restart")

    systemctl restart httpd.service

    action "apache is running." /bin/true

esac

    sleep 1 && netstat -antple|grep httpd 

fi

[root@ChangerLee 控制结构]# sh case_httpd.sh start

apache is running.                                         [  OK  ]

tcp6       0      0 :::80                   :::*                    LISTEN      0          1181108    29104/httpd         

tcp6       0      0 :::443                  :::*                    LISTEN      0          1181116    29104/httpd         

 

[root@ChangerLee 控制结构]# sh case_httpd.sh stop

apache is stop.                                            [  OK  ]

[root@ChangerLee 控制结构]# sh case_httpd.sh restart

apache is running.                                         [  OK  ]

tcp6       0      0 :::80                   :::*                    LISTEN      0          1194047    30430/httpd         

tcp6       0      0 :::443                  :::*                    LISTEN      0          1194055    30430/httpd          
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐