博客
关于我
nginx开机启动脚本
阅读量:791 次
发布时间:2023-02-15

本文共 1619 字,大约阅读时间需要 5 分钟。

hot3.png

chmod +x /etc/rc.d/init.d/nginx   # 赋予执行权限

chkconfig nginx on   #设置开机启动

将nginx放在此目录里面:vi /etc/rc.d/init.d/nginx 

nginx文件内容如下:

#!/bin/bash 

# nginx Startup script for the Nginx HTTP Server 
# it is v.1.3.0 version. 
# chkconfig: - 85 15 
# description: Nginx is a high-performance web and proxy server. 
#              It has a lot of features, but it's not for everyone. 
# processname: nginx 
# pidfile: /var/run/nginx.pid 
# config: /usr/local/nginx/conf/nginx.conf 
nginxd=/usr/local/nginx/sbin/nginx 
nginx_config=/usr/local/nginx/conf/nginx.conf 
nginx_pid=/usr/local/nginx/logs/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 /usr/local/nginx/logs/nginx.pid 
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

转载于:https://my.oschina.net/lovetyh/blog/904221

你可能感兴趣的文章
NAT的两种模式SNAT和DNAT,到底有啥区别?
查看>>
Navicat for MySQL 命令列 执行SQL语句 历史日志
查看>>
Navicat for MySQL 查看BLOB字段内容
查看>>
Navicat Premium 12 卸载和注册表的删除
查看>>
navicat 系列软件一点击菜单栏就闪退
查看>>
navicat 连接远程mysql
查看>>
Navicat下载和破解以及使用
查看>>
Navicat可视化界面导入SQL文件生成数据库表
查看>>
Neat Stuff to Do in List Controls Using Custom Draw
查看>>
NeHe OpenGL教程 第四十四课:3D光晕
查看>>
neo4j图形数据库Java应用
查看>>
Neo4j安装部署及使用
查看>>
Neo4j电影关系图Cypher
查看>>
Neo4j的安装与使用
查看>>
Neo4j(2):环境搭建
查看>>
Neo私链
查看>>
Nerves 项目教程
查看>>
nessus快速安装使用指南(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Nessus漏洞扫描教程之配置Nessus
查看>>
Nest.js 6.0.0 正式版发布,基于 TypeScript 的 Node.js 框架
查看>>