V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ssvodown
V2EX  ›  NGINX

nginx 定时启动脚本

  •  
  •   ssvodown · 2016-11-27 00:15:07 +08:00 · 3051 次点击
    这是一个创建于 2708 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一、修改 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 文件

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2885 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:56 · PVG 14:56 · LAX 23:56 · JFK 02:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.