这个脚本,可以满足nginx开启,停止和重启的操作
#!/bin/bash
. /etc/init.d/functions
function usage() {
echo $"usage:$0 {start|stop|restart}"
exit 1
}
function start() {
/usr/local/nginx/sbin/nginx
sleep 1
if [ `netstat -antlpe | grep nginx | wc -l` -ge 0 ];then
action "nginx is started." /bin/true
else
action "nginx is started." /bin/false
fi
}
function stop() {
killall nginx &>/dev/null
sleep 1
if [ `netstat -antlpe | grep nginx | wc -l` -eq 0 ];then
action "nginx is stopped." /bin/true
else
action "nginx is stopped." /bin/false
fi
}
function main() {
if [ $# -ne 1 ];then
usage $0
fi
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
usage $0
;;
esac
}
main $*运行试试
1.停止nginx

2.开启nginx

3.重启nginx

以上就是nginx自动化脚本怎么写的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号