V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ssvodown
V2EX  ›  NGINX

nginx 定时启动脚本

  •  
  •   ssvodown · Nov 27, 2016 · 3889 views
    This topic created in 3444 days ago, the information mentioned may be changed or developed.

    一、修改 nginx.conf 脚本,,赋予 nginx-domain_X 可执行权限 chmod a+x /etc/nginx/conf.d/nginx-domain_1.conf /nginxshell.sh chmod a+x /etc/nginx/conf.d/nginx-domain_2.conf /nginxshell.sh chmod a+x /etc/nginx/conf.d/nginx-domain_3.conf /nginxshell.sh

    二、写 nginxshell.sh 脚本,内容: ####################################### #!/bin/bash

    tod=date +%Y%m%d

    va=$(( $tod % 2 ))

    if [ $va = 0 ] ; then cp -f /etc/nginx/conf.d/nginx-domain_1.conf /etc/nginx/conf.d/nginx-domain.conf

    elif [ $va = 1 ] ; then

    cp -f /etc/nginx/conf.d/nginx-domain_2.conf /etc/nginx/conf.d/nginx-domain.conf
    

    else cp -f /etc/nginx/conf.d/nginx-domain_3.conf /etc/nginx/conf.d/nginx-domain.conf

    fi

    /usr/sbin/nginx -s reload #######################################

    chmod a+x /etc/nginx/conf.d/nginxshell.sh

    三、每日启动 sh 脚本

    #crontab -e ######################################## 00 0 * * * root run-parts /etc/nginx/conf.d/nginxshell.sh ######################################## /sbin/service crond reload #重新载入配置 /sbin/service crond restart #重启服务 crontab -l #列出 crontab 文件 chkconfig --level 35 crond on #加入开机自动启动:

    /sbin/service crond start #启动服务 /sbin/service crond stop #关闭服务 /sbin/service crond restart #重启服务 /sbin/service crond reload #重新载入配置 ntsysv #查看 crontab 服务是否已设置为开机启动,执行命令: chkconfig --level 35 crond on #加入开机自动启动: crontab -l #列出 crontab 文件

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2479 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 08:42 · PVG 16:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.