shell安装http启动脚本

[复制链接]
发表于 2024-10-16 12:46:26 | 显示全部楼层 |阅读模式

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

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

×
使用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企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表