shell安装http启动脚本

打印 上一主题 下一主题

主题 1881|帖子 1881|积分 5643

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
使用case语法安装httpd服务
[root@localhost shell]# cat httpd_start1.sh
#!/bin/bash
# This script manages the Apache HTTP server.
# by author rivers on 2024-10-12

# 查抄是否提供了参数
if [ -z "$1" ]; then
  echo "Usage: $0 {start|stop|restart|status}"
  exit 1
fi

# 界说变量
HTTPD_SERVICE="httpd"
HTTPD_CONFIG="/etc/httpd/conf/httpd.conf"

# 查抄 httpd 是否已安装
if ! command -v $HTTPD_SERVICE &> /dev/null; then
  echo "Error: $HTTPD_SERVICE is not installed."
  exit 1
fi

# 查抄配置文件是否存在
if [ ! -f "$HTTPD_CONFIG" ]; then
  echo "Error: Configuration file $HTTPD_CONFIG does not exist."
  exit 1
fi

# 使用 case 语句处理差别的命令
case "$1" in
  start)
    echo "Starting $HTTPD_SERVICE..."
    if sudo systemctl start $HTTPD_SERVICE; then
      echo "$HTTPD_SERVICE started successfully."
    else
      echo "Failed to start $HTTPD_SERVICE."
      exit 1
    fi
    ;;
  stop)
    echo "Stopping $HTTPD_SERVICE..."
    if sudo systemctl stop $HTTPD_SERVICE; then
      echo "$HTTPD_SERVICE stopped successfully."
    else
      echo "Failed to stop $HTTPD_SERVICE."
      exit 1
    fi
    ;;
  restart)
    echo "Restarting $HTTPD_SERVICE..."
    if sudo systemctl restart $HTTPD_SERVICE; then
      echo "$HTTPD_SERVICE restarted successfully."
    else
      echo "Failed to restart $HTTPD_SERVICE."
      exit 1
    fi
    ;;
  status)
    echo "Checking $HTTPD_SERVICE status..."
    sudo systemctl status $HTTPD_SERVICE
    ;;
  *)
    echo "Invalid option: $1"
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0
实验脚本


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

怀念夏天

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表