如何自动处理NextCloud的错误?

Cloud storage

1 前言

一个问题,一篇文章,一出故事。
今天发现一个重复出现的错误,详细的错误提示如下,

{"reqId":"SnqmRf9tlMKpeFbOp0kN","level":4,"time":"2022-01-14T09:15:03+08:00","remoteAddr":"","user":"--","app":"files_antivirus","method":"","url":"--","message":"OCA\\Files_Antivirus\\BackgroundJob\\BackgroundScanner::run, exception: \"Documents/Quick Notes.xlsx\" is locked, existing lock on file: exclusive","userAgent":"--","version":"21.0.2.1"}

以上由于尚未找到根除的方法,于是想到使用脚本监视日志并自动处理,就此整理此文。

2 最佳实践

2.1 创建脚本目录

mkdir ~/scripts

2.2 创建脚本

vim ~/scripts/autoFlushRedis.sh

加入如下配置,

#!/bin/bash

monitorFiles="/var/log/nextcloud/nextcloud.log"
monitorLog="/var/log/autoFlushRedis.log"
monitorDate=`date +"%Y-%m-%d %H:%M:%S"`

if [ ! -f "$monitorLog" ]; then
        touch "$monitorLog"
fi
if [ ! -f "$monitorLog" ]; then
        echo "$monitorDate"' Failed to create log file!'
        exit 1
fi

reqId=`grep -i "is locked, existing lock on file" "$monitorFiles" | tail -n 1 | sed -e "s/{//g" -e "s/}//g" | cut -d"," -f1`
if [ "$reqId" == "" ]; then
        exit
fi

reqIdLog=`grep "$reqId" "$monitorLog"`
if [ "$reqIdLog" != "" ]; then
        exit
fi
redis-cli -a redispasswd flushall
if [ "$?" = "0" ]; then
        echo "$monitorDate"' '"$reqId" | tee -a "$monitorLog"
fi

需要注意的是,
– 参数“monitorFiles”声明需要监视可能更新的代码文件(多个文件请使用空格分隔)
– 参数“monitorLog”声明脚本运行日志路径
– 参数“serviceList”声明需要重启的服务列表(多个服务请使用空格分隔)

2.3 设置脚本触发

crontab -e

加入如下设置,

*/1 * * * * sh ~/scripts/autoFlushRedis.sh

参阅文档
====================
https://github.com/nextcloud-snap/nextcloud-snap/issues/1031

没有评论

发表回复

Cloud storage
如何部署基于Nginx部署NextCloud?

1 前言 一个问题,一篇文章,一出故事。 以往使用LAMP环境部署的NextCloud已经工作良久, …

Cloud storage
如何修复NextCloud通讯录图片损坏问题?

1 前言 一个问题,一篇文章,一出故事。 笔者最近需要测试升级NextCloud,发现通讯录显示损坏 …

Cloud storage
如何迁移NextCloud数据目录?

1 前言 一个问题,一篇文章,一出故事。 笔者需要迁移NextCloud的默认数据目录“/var/w …