apache - 执行停止启动多个 httpd 实例的 shell 脚本
问题描述
我想编写一个脚本来重新启动 httpd 实例,前提是它处于运行状态。对于一个实例,它工作正常,但不止一个实例它失败了。
下面是我正在使用的脚本:
ctl_var=`find /opt/apache/instances/ -name apachectl | grep -v "\/httpd\/"`
ctl_proc=`ps -ef | grep -i httpd | grep -i " 1 " wc -l`
if [ $ctl_proc <= 0 ];
then echo "httpd is not running";
else $ctl_var -k stop; echo "httpd stopped successfully" ;
sleep 5;
$ctl_var -k start;
sleep 5;
echo "httpd started" ps -ef | grep httpd | grep -i " 1 ";
fi
请建议...
解决方案
你提到有多个实例,我看到它在执行脚本时错过了循环。在这里它只重新启动 $ctl_var 中选择的最后一个
修改后的脚本应如下所示,必要时调整脚本:
ctl_var=`find /opt/apache/instances/ -name apachectl | grep -v "\/httpd\/"`
ctl_proc=`ps -ef | grep -i httpd | grep -i " 1 " wc -l`
for i in `echo $ctl_var`
do
if [ $ctl_proc <= 0 ];
then echo "httpd is not running";
else $i -k stop; echo "httpd stopped successfully" ;
sleep 5;
$i -k start;
sleep 5;
echo "httpd started" ps -ef | grep httpd | grep -i " 1 ";
fi
done
希望这可以帮助。
推荐阅读
- java - JDBC Mysql SSH 连接,Url 不能为空
- javascript - 在 Rails 中浏览器返回导航后,引导工具提示仍然存在
- python-3.x - 如何迭代具有超时的异步迭代器?
- octobercms - OctoberCMS - 插入时更新相关表中的字段
- python - Numpy 矩阵的映射函数
- msbuild - 使用 nuget 将 MSBuild 构建到公共输出目录
- react-native - FlatList 不通过 0 或 null 进入 renderItem 道具
- azure-devops - 是否可以将 html 报告与 VSTS 构建摘要集成?
- c++ - 如何重载 << 运算符以使用模板函数将元素添加到向量?(c++)
- django - 填写表单后,将元素添加到视图中的表单