from apscheduler.schedulers.background import backgroundscheduler # 子程序排程器
from apscheduler.executors.pool import threadpoolexecutor # 執行器
import os, time, shutil
base_path =
'/home/uwsgi/log/web'
executor = threadpoolexecutor(
)scheduler = backgroundscheduler(executors=
)def
main()
:'''
對uwsgi的系統級別的日誌輸出進行轉移
:return:
'''today = time.strftime(
"%y-%m-%d"
, time.localtime())
# 得到原目標檔案路徑
base_file = os.path.join(base_path,
'uwsgi.log'
)# 得到cp後的檔案路徑
new_file = os.path.join(base_path,
'uwsgi.log_{}'
.format
(today)
)# cp 操作
shutil.copyfile(base_file, new_file)
# 清空原始檔的內容
os.system(
'cat /dev/null > {}'
.format
(base_file)
)if __name__ ==
'__main__'
:# 每天凌晨執行一下任務
scheduler.add_job(main,
'cron'
, hour=
'0')
scheduler.start(
)while
true
: time.sleep(60*
60*24)
uWSGI日誌按照日期自動切割
touch logreopen root hello touchforlogrotat注 uwsgi.ini 新增配置選項 日誌檔案 aemonize root hello uwsgi.log 生成乙個監聽的檔案,touch touchforlogrotat 相當於修改了建立時間,系統會重新relo...
nginx 日誌切割定時
1.安裝定時任務 yum install crontabs 1 usr local nginx sbin cut my log.sh 3.重啟定時任務 service crond restart 附 常用定時任務命令 service crond start 啟動服務 service crond st...
Nginx定時日誌切割
進入到nginx的可執行sbin目錄裡,usr local nginx sbin 下 建立乙個shell可執行檔案 cut my log.sh 內容為 bin bash log path var log nginx record time date d yesterday y m d h m pid...