lyd2004888 发表于 2018-12-5 09:31:18

centos下nginx,tomcat开机自启动脚本

01#!/bin/bash02#
03# nginx         Startup script for the Apache HTTP Server
04#
05# chkconfig:    345 85 15
06# description:Nginx is a high performance web server
07# config:       /etc/nginx/nginx.conf
08# pidfile:      /var/run/nginx.pid
09#
10# modify:       waiting 20111007
11#
12
13
14PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
15DESC="nginx daemon"
16NAME=nginx
17DAEMON=/usr/local/sbin/$NAME
18SCRIPTNAME=/etc/init.d/$NAME
19
20if [ ! -d /tmp/nginx ]; then
21    mkdir -p /tmp/nginx/client /tmp/nginx/fcgi /tmp/nginx/proxy
22fi
23chown -R $NAME /tmp/nginx
24
25# If the daemon file is not found, terminate the script.
26test -x $DAEMON || exit 0
27
28d_start() {
29    $DAEMON || echo -n " already running"
30}
31d_stop() {
32    $DAEMON -s quit || echo -n " not running"
33}
34d_reload() {
35    $DAEMON -s reload || echo -n " could not reload"
36}
37
38case "$1" in
39    start)
40      echo -n "Starting $DESC: $NAME"
41      d_start
42      echo "."
43      ;;
44    stop)
45      echo -n "Stopping $DESC: $NAME"
46      d_stop
47      echo "."
48      ;;
49    reload)
50      echo -n "Reloading $DESC configuration..."
51      d_reload
52      echo "reloaded."
53      ;;
54    restart)
55      echo -n "Restarting $DESC: $NAME"
56      d_stop
57      # Sleep for two seconds before starting again, this should give the   
58      # Nginx daemon some time to perform a graceful stop.
59      sleep 2
60      d_start
61      echo "."
62      ;;
63    *)
64      echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
65      exit 3
66      ;;
67esac
68exit 0
1/sbin/chkconfig --add nginx
2
3/sbin/chkconfig nginx on
4
5 /etc/init.d/nginx start|stop|reload|restart
6
7/sbin/service nginx start|stop|reload|restart  根据实际情况,自己修改 NAME=nginx 的值。我是用nginx用户跑nginx程序所以这儿是nginx,如果你是www用户那么就改成 NAME=www,注意中间没空格



页: [1]
查看完整版本: centos下nginx,tomcat开机自启动脚本