记录下使用chkconfig将nginx加入自启动的过程
一.在 /etc/init.d中编写nginx文件
1 #!/bin/bash
2 # nginx Startup script for the Nginx HTTP Server
3 # it is v.0.0.2 version.
4 # chkconfig: - 85 15
5 # description: Nginx is a high-performance web and proxy server.
6 # It has a lot of features, but it's not for everyone.
7 # processname: nginx
8 # pidfile: /var/run/nginx.pid
9 # config: /usr/local/nginx/conf/nginx.conf
10 nginxd=/usr/local/nginx/sbin/nginx
11 nginx_config=/usr/local/nginx/conf/nginx.conf
12 nginx_pid=/usr/local/nginx/logs/nginx.pid
13 RETVAL=0
14 prog="nginx"
15 # Source function library.
16 . /etc/rc.d/init.d/functions
17 # Source networking configuration.
18 . /etc/sysconfig/network
19 # Check that networking is up.
20 [ ${NETWORKING} = "no" ] && exit 0
21 [ -x $nginxd ] || exit 0
22
23 # Start nginx daemons functions.
24 start() {
25 if [ -e $nginx_pid ];then
26 echo "nginx already running...."
27 exit 1
28 fi
29 echo -n $"Starting $prog: "
30 daemon $nginxd -c ${nginx_config}
31 RETVAL=$?
32 echo
33 [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
34 return $RETVAL
35 }
36
37 # Stop nginx daemons functions.
38 stop() {
39 echo -n $"Stopping $prog: "
40 killproc $nginxd
41 RETVAL=$?
42 echo
43 [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
44 }
45
46
47 # reload nginx service functions.
48 reload() {
49 echo -n $"Reloading $prog: "
50 #kill -HUP `cat ${nginx_pid}`
51 killproc $nginxd -HUP
52 RETVAL=$?
53 echo
54 }
55
56
57
58
59 # See how we were called.
60 case "$1" in
61 start)
62 start
63 ;;
64 stop)
65 stop
66 ;;
67 reload)
68 reload
69 ;;
70 restart)
71 stop
72 start
73 ;;
74 status)
75 status $prog
76 RETVAL=$?
77 ;;
78 *)
79 echo $"Usage: $prog {start|stop|restart|reload|status|help}"
80 exit 1
81 esac
82 exit $RETVAL
其中
1)nginxd是nginx启动程序的路径
2)nginx_config是nginx的配置文件存放的路径
3)nginx_pid是配置文件中 pid文件存放的路径
二.给nginx文件赋权
chmod 755 nginx
三.chkconfig操作
#
chkconfig --add nginx
chkconfig nginx on
如图所示,就为配置成功