From cc792ddd57691bb54972c73b9c861c768fce8c34 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Thu, 22 Aug 2019 19:22:27 +0300 Subject: Snap: Delete old MongoDB log, and log to syslog instead, because syslog usually already has log rotation. Thanks to xet7 ! Closes wekan/wekan-snap#92, closes #1911 --- snap-src/bin/mongodb-control | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'snap-src/bin') diff --git a/snap-src/bin/mongodb-control b/snap-src/bin/mongodb-control index 28e58670..db01cffd 100755 --- a/snap-src/bin/mongodb-control +++ b/snap-src/bin/mongodb-control @@ -16,6 +16,24 @@ fi export LC_ALL=C +# When starting MongoDB, if logfile exist, delete it, because now uses syslog instead of logfile, +# because syslog usually already has log rotation. +# https://github.com/wekan/wekan-snap/issues/92 +if test -f "$SNAP_COMMON/mongodb.log"; then + rm -f "$SNAP_COMMON/mongodb.log" +fi + +# Alternative: When starting MongoDB, and using logfile, truncate log to last 1000 lines of text. +# 1) If file exists: +#if test -f "$SNAP_COMMON/mongodb.log"; then +# # 2) Copy last 1000 lines to variable loglast1000lines. +# loglast1000lines=$(tail -1000 "$SNAP_COMMON/mongodb.log") +# # 3) Copy variable to replace original MongoDB log. +# echo "$loglast1000lines" > "$SNAP_COMMON/mongodb.log" +# # 4) Set variable to be empty. +# loglast1000lines="" +#fi + if [ -z "$MONGO_URL" ]; then # start mongo deamon @@ -31,11 +49,17 @@ if [ -z "$MONGO_URL" ]; then fi echo "mongodb bind options: $BIND_OPTIONS" - mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $BIND_OPTIONS --smallfiles + ## OLD: Logging to file. + #mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $BIND_OPTIONS --smallfiles + ## NEW: Logging to syslog, that usually has already log rotation. + mongod --dbpath $SNAP_COMMON --syslog --journal $BIND_OPTIONS --smallfiles else - mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $MONGO_URL --smallfiles + ## OLD: Logging to file. + #mongod --dbpath $SNAP_COMMON --logpath $SNAP_COMMON/mongodb.log --logappend --journal $MONGO_URL --smallfiles + ## NEW: Logging to syslog, that usually has already log rotation. + mongod --dbpath $SNAP_COMMON --syslog --journal $MONGO_URL --smallfiles fi -- cgit v1.2.3-1-g7c22