首页 > 系统相关 >shell安装http启动脚本

shell安装http启动脚本

时间:2024-10-13 18:18:31浏览次数:17  
标签:脚本 HTTPD shell http SERVICE httpd echo exit fi

利用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

执行脚本

标签:脚本,HTTPD,shell,http,SERVICE,httpd,echo,exit,fi
From: https://blog.csdn.net/2301_82330629/article/details/142876467

相关文章

  • golang从http请求中读取xml格式的body,并转成json
    推荐学习文档golang应用级os框架,欢迎stargolang应用级os框架使用案例,欢迎star案例:基于golang开发的一款超有个性的旅游计划app经历golang实战大纲golang优秀开发常用开源库汇总想学习更多golang知识,这里有免费的golang学习笔记专栏文章目录以下是在Go语言中从HTT......
  • 如何从命令行界面运行交互式PHP Shell
    从命令行界面运行交互式PHPShell(也称为PHPCLI交互模式)非常简单。你可以通过以下步骤来启动它:打开命令行界面:在Windows上,你可以使用命令提示符(CMD)或PowerShell。在macOS或Linux上,你可以使用终端(Terminal)。运行PHP命令:在命令行中输入以下命令并按回车:php-a这个命令会启......
  • 第109天:免杀对抗-PowerShell&混淆&分离加载&特征修改&EXE生成&填充替换
    知识点知识点:1、Powershell-对变量数据做文章2、Powershell-对Shellcode做文章3、Powershell-对执行代码特征做文章章节点:编译代码面-ShellCode-混淆编译代码面-编辑执行器-编写编译代码面-分离加载器-编写程序文件面-特征码定位-修改程序文件面-加壳花指令-资源代码......