不言不语

您现在的位置是: 首页 >  Linux

Linux

linux之写nginx的启动脚本

2022-03-18Linux
linux写nginx的启动脚本,基本属于傻瓜式操作,小白必备,几行代码,以贴代码实例,按步骤操作即可!

本文简单介绍了,linux写nginx的启动脚本,基本属于傻瓜式操作,很简单,几行代码,复制黏贴即可!


例如:home目录


[root@localhost home]# mkdir shell


[root@localhost shell]# vi http.sh


精简版


#!/bin/bash

#include functions

# chkconfig:- 50 60

. /etc/init.d/functions

exec=/usr/local/nginx/sbin/nginx

prog=nginx

function start(){

pidofproc $exec 

[ $? = 0 ] && echo "  It s already started $prog  "  && exit

daemon $exec

[ $? = 0 ] && echo  " Start successful  $prog " 

}


function stop(){

pidofproc $exec 

[ $? != 0 ] && echo " Not running $prog" && exit

killproc $exec

[ $? = 0 ] && echo " stop $prog " 

}


case $1 in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)


;;

esac



启动nginx脚本


[root@localhost shell]# ./http.sh start


image.png


停止nginx脚本


[root@localhost shell]# ./http.sh stop


image.png


重启nginx脚本


[root@localhost shell]# ./http.sh restart


image.png


查看端口


[root@localhost shell]# netstat -ntlp


image.png

文章评论