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

01 #!/bin/bash
02 #
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  
14 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
15 DESC="nginx daemon"
16 NAME=nginx
17 DAEMON=/usr/local/sbin/$NAME
18 SCRIPTNAME=/etc/init.d/$NAME
19  
20 if [ ! -d /tmp/nginx ]; then
21     mkdir -p /tmp/nginx/client /tmp/nginx/fcgi /tmp/nginx/proxy
22 fi
23 chown -R $NAME /tmp/nginx
24  
25 # If the daemon file is not found, terminate the script.
26 test -x $DAEMON || exit 0
27  
28 d_start() {
29     $DAEMON || echo -n " already running"
30 }
31 d_stop() {
32     $DAEMON -s quit || echo -n " not running"
33 }
34 d_reload() {
35     $DAEMON -s reload || echo -n " could not reload"
36 }
37  
38 case "$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         ;;
67 esac
68 exit 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,注意中间没空格

你可能感兴趣的:(tomcat,nginx,开机启动)