扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
已知Nginx管理命令为:
启动:/application/nginx/sbin/nginx
停止:/application/nginx/sbin/nginx -s stop
重新加载:/application/nginx/sbin/nginx -s reload
请用case脚本模拟Nginx服务启动关闭:
/etc/init.d/nginx {start|stop|reload|restart},并可通过chkconfig管理。
[root@web01 ~]# cat /etc/init.d/nginx #/bin/sh # chkconfig: 2345 15 62 #设定运行级别以及启动和停止Nginx服务顺序 # description: Nginx Server #脚本说明 [ -f /etc/init.d/functions]&&. /etc/init.d/functions||exit 1 #Define Arivables Path=/application/nginx/sbin/nginx RETVAL=0 #Define Start Function start() { if [ `ss -lntup|grep nginx|wc -l` -gt 0];then echo "Nginx is Running..." else $Path RETVAL=$? if [ $RETVAL -eq 0 ];then action "Starting Nginx..."/bin/true else action "Starting Nginx..."/bin/false fi fi return $RETVAL } #Define Stop Function stop() { if [ `ss -lntup|grep nginx|wc -l` -gt 0];then $Path -s stop RETVAL=$? if [ $RETVAL -eq 0 ];then action "Stopping Nginx..."/bin/true else action "Stopping Nginx..."/bin/false fi else echo "Nginx is Stopped" fi return $RETVAL } #Define Restart Function reload() { if [ `ss -lntup|grep nginx|wc -l` -gt 0];then $Path -s reload RETVAL=$? if [ $RETVAL -eq 0 ];then action "Reloading Nginx..."/bin/true else action "Reloading Nginx..."/bin/false fi else echo "Nginx is Stopped" fi return $RETVAL } #Define Restart Function restart() { stop sleep 1 start return $RETVAL } case "$1" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; reload) reload RETVAL=$? ;; restart) restart RETVAL=$? ;; *) echo "USAGE:$0 {start|stop|reload|restart}" RETVAL=2 ;; esac exit $RETVAL [root@web01 ~]# ls -l /etc/init.d/nginx -rwxr-xr-x. 1 root root 1680 Jun 9 12:13 /etc/init.d/nginx [root@web01 ~]# chkconfig --list|grep nginx nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流