#!/bin/bash
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ];then
echo "Error:you should be root to run this script!"
exit 1
fi
systemctl start httpd &>>/dev/null
if [ $? == 0 ];then
while true
do
echo -e "
\033[31m start 启动Apache服务 \033[0m
\033[32m stop 停止Apache服务 \033[0m
\033[33m restart 重启Apache服务 \033[0m
\033[34m status 检查Apache服务 \033[0m
\033[35m exit 退出执行程序 \033[0m
"
read -p "请输入一个您的指令:" i
case $i in
start|START)
systemctl start httpd && echo "Apache启动成功" || echo "Apache启动失败"
;;
stop|STOP)
systemctl stop httpd && echo "Apache停止成功" || echo "Apache停止失败"
;;
restart|RESTART)
systemctl restart httpd && echo "Apache重启成功" || echo "Apache重启失败"
;;
status|STATUS)
systemctl status httpd && echo -e `systemctl status httpd`
;;
exit|EXIT)
exit 0
;;
esac
done
fi
echo "没有安装Apache服务"
while true
do
echo -e "
\033[31m install 安装Apache服务 \033[0m
\033[32m exit 退出执行程序 \033[0m
"
read -p "请输入一个您的指令:" o
case $o in
install|INSTALL)
yum install httpd -y &> /dev/null && echo "安装成功,请重新启动程序" || echo "您的yum源出现问题"
;;
exit|EXIT)
exit 0
;;
esac
done