#cd /etc/rc.d/init.d#touch nginx#vi nginx nginx内容如下所示#!/bin/bash # # nginx This shell script takes care of starting and stopping # standalone nginx # software version 2.1.2# description: nginx service # processname: nginx # config file:# Source function library. . /etc/rc.d/init.d/functionsnginx="/u02/software/tengine/sbin/nginx"prog=$(basename $nginx)#第一行是防止nginx自启动抛出异常80端口被占用,可自行修改默认端口号#如果停止命令和开始命令是分开的,不在同一次执行,则不会出现异常start(){ chmod 755 /u02/software/tengine/sbin/nginx /u02/software/tengine/sbin/nginx echo "nginx start success"}stop(){ pid=`ps -ef | grep "nginx" | grep -v "grep" | awk '{print $2}'` if [ -n "$pid" ]; then kill $pid echo "nginx stop success" else echo "no nginx service is running." fi}nginx_status() {status $prog}restart(){ stop start}case "$1" in start) start ;; stop) stop ;; status)nginx_status ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1esacexit
kill $pid
#service nginx status#service nginx start#service nginx stop#service nginx restart