一、传统模式下Nginx的启动、关闭
1、启动:/usr/local/nginx/sbin/nginx 2、关闭:killall nginx 3、重启:/usr/local/nginx/sbin/nginx -s reload
二、通过配置/etc/init.d/nginx来管理Nginx
#!/bin/bash # nginx Startup script for the Nginx HTTP Server nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL 保存并添加执行权限 service nginx start //启动Nginx service nginx stop //关闭Nginx service nginx restart //重启Nginx service nginx status //查看Nginx的状态 添加至开机启动 chkconfig --add nginx chkconfig nginx on
三、传统Tomcat的开启、关闭
1、启动:/usr/local/apache-tomcat-9.0.7/bin/startup.sh 2、关闭:/usr/local/apache-tomcat-9.0.7/bin/shutdown.sh
四、配置/etc/init.d/tomcat管理Tomcat
# tomcat startup script for the Tomcat server . /etc/rc.d/init.d/functions prog=tomcat JAVA_HOME=/usr/local/java/ export JAVA_HOME CATALANA_HOME=/usr/local/apache-tomcat-9.0.7/ export CATALINA_HOME case "$1" in start) echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;; stop) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh ;; restart) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh sleep 2 echo echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;; *) echo "Usage: $prog {start|stop|restart}" ;; esac exit 0 service tomcat start service tomcat stop service tomcat restart chkconfig --add tomcat chkconfig tomcat on
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/54285.html