Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions plugins/ca.mover.tuning.plg
Original file line number Diff line number Diff line change
Expand Up @@ -721,34 +721,37 @@ if [[ ! -f "$config_file" ]]; then
echo 'version="&version;"' >> "$config_file"
else
echo "Updating config file"
# a file without a final newline would glue a key appended below onto its last key
[ -n "$(tail -c 1 "$config_file")" ] && echo >> "$config_file"
if [ &upgrade; = "major" ]; then
echo "- Major upgrade, forcing test mode"
if grep -q "testmode" "$config_file"; then
sed -i "s/testmode=.*$/testmode=\"yes\"/" "$config_file"
if grep -q '^testmode=' "$config_file"; then
sed -i "s/^testmode=.*$/testmode=\"yes\"/" "$config_file"
else
echo 'testmode="yes"' >> "$config_file"
fi
else
echo "- Minor upgrade, not forcing test mode"
fi
echo "- Updating version number"
if grep -q "version" "$config_file"; then
sed -i "s/version=.*$/version=\"&version;\"/" "$config_file"
if grep -q '^version=' "$config_file"; then
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
sed -i "s/^version=.*$/version=\"&version;\"/" "$config_file"
else
echo "version=\"&version;\"" >> "$config_file"
fi
if grep -q "threshold=" $config_file; then
if grep -q '^threshold=' "$config_file"; then
echo "- Updating movingThreshold"
sed "s/threshold=/movingThreshold=/" -i "$config_file"
sed "s/^threshold=/movingThreshold=/" -i "$config_file"
fi
if grep -q 'freeingThreshold=""' "$config_file"; then
# the first freeingThreshold line is the one age_mover reads, so only that one is checked and replaced
if [ "$(grep -m1 '^freeingThreshold=' "$config_file" | tr -d '\r')" = 'freeingThreshold=""' ]; then
echo "- Updating freeingThreshold"
thresh=$(grep "movingThreshold=" $config_file | cut -d'=' -f 2 | tr -d '"' | tr -d '\r')
sed "s/freeingThreshold=.*$/freeingThreshold=$thresh/" -i "$config_file"
thresh=$(grep -m1 '^movingThreshold=' "$config_file" | cut -d'=' -f 2 | tr -d '"' | tr -d '\r')
sed "0,/^freeingThreshold=/s/^freeingThreshold=.*$/freeingThreshold=\"$thresh\"/" -i "$config_file"
fi
if ! grep -q 'freeingThreshold=' $config_file; then
if ! grep -q '^freeingThreshold=' "$config_file"; then
echo "- Updating freeingThreshold"
grep 'movingThreshold=' "$config_file" | sed 's/movingThreshold/freeingThreshold/' >> "$config_file"
grep -m1 '^movingThreshold=' "$config_file" | sed 's/^movingThreshold/freeingThreshold/' >> "$config_file"
fi
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ if [[ "$CONFIGLOGFOLDER" != /* ]]; then
else
LOGFOLDER="$CONFIGLOGFOLDER"
fi
# A folder that cannot be created or written sends one error per log line to syslog: check the nearest one that exists
LOGFOLDER_PROBE="${LOGFOLDER}/ca.mover.tuning"
while [ ! -e "$LOGFOLDER_PROBE" ] && [ ! -L "$LOGFOLDER_PROBE" ]; do
LOGFOLDER_PROBE=$(dirname "$LOGFOLDER_PROBE")
done
# Under /mnt a folder on the root filesystem means its pool or share is not mounted: the logs would go to RAM under the mount point
if [ ! -d "$LOGFOLDER_PROBE" ] || [ ! -w "$LOGFOLDER_PROBE" ] ||
{ [[ "$LOGFOLDER/" == /mnt/* ]] && [ "$(stat -L -c %d "$LOGFOLDER_PROBE")" = "$(stat -c %d /)" ]; }; then
LOGFOLDER="/tmp"
fi

NOW=$(date +"%FT%H%M%S")
FILTERED_FILELIST="${LOGFOLDER}/ca.mover.tuning/Filtered_files_$NOW.list"
Expand Down Expand Up @@ -927,6 +937,8 @@ getMoverSettings() {
cfg_default loggingFolder /tmp
LOGFOLDER="/tmp"
fi
elif [ "$(cfg loggingFolder)" != "$LOGFOLDER" ]; then
mvlogger "Log parent folder: $LOGFOLDER ($(qp "$(cfg loggingFolder)") cannot be used)"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
else
mvlogger "Log parent folder: $LOGFOLDER"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,29 @@ for config_file in "$OVERRIDE_CFGFOLDER"/*.cfg; do
done

# Newest logs up to $MAXLOGBYTES; this took only files modified today.
if [ -d "$LOGFOLDER" ]; then
# age_mover logs to /tmp when the configured folder cannot be used, so read both; -ef keeps one folder from counting twice
LOGFOLDERS=()
[ -d "$LOGFOLDER" ] && LOGFOLDERS+=("$LOGFOLDER")
[ -d /tmp/ca.mover.tuning ] && [ ! /tmp/ca.mover.tuning -ef "$LOGFOLDER" ] && LOGFOLDERS+=(/tmp/ca.mover.tuning)
if [ ${#LOGFOLDERS[@]} -gt 0 ]; then
mkdir -p $DEBUGROOT/PLUGIN/Logs 2>&1
find "$LOGFOLDER" -maxdepth 1 -type f -printf '%T@\t%s\t%p\0' 2>/dev/null |
find -H "${LOGFOLDERS[@]}" -maxdepth 1 -type f -printf '%T@\t%s\t%p\0' 2>/dev/null |
sort -zrn |
gawk -v RS='\0' -v ORS='\0' -v budget="$MAXLOGBYTES" '
{
# index, not fields: a path may contain a tab
r = substr($0, index($0, "\t") + 1)
size = substr(r, 1, index(r, "\t") - 1)
# a file over what is left of the budget is skipped, so smaller ones after it still fit
if (total + size > budget) next
total += size
if (total > budget) exit
print substr(r, index(r, "\t") + 1)
}' |
while IFS= read -r -d '' file; do
cp -f "$file" $DEBUGROOT/PLUGIN/Logs/"$(basename "$file").txt" 2>&1
# a name taken by the newer copy from the other folder gets a prefix, keeping the .list.txt ending the anonymizer keys on
dest="$DEBUGROOT/PLUGIN/Logs/$(basename "$file").txt"
[ -e "$dest" ] && dest="$DEBUGROOT/PLUGIN/Logs/older.$(basename "$file").txt"
cp -f "$file" "$dest" 2>&1
done
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ getMoverSettings() {
done <"$config_file"
echo "${value//\"/}" # Print value or empty string if not found, without quotes
}
# mirrors age_mover's cfg_default: one KEY="VALUE" line replaces every KEY line
cfg_default() {
sed -i "/^$1=/d" "$config_file"
[ -n "$(tail -c 1 "$config_file")" ] && echo >>"$config_file"
echo "$1=\"$2\"" >>"$config_file"
}

timezone=$(grep "timeZone=" "/boot/config/ident.cfg" | cut -d '"' -f 2)

Expand All @@ -62,7 +68,7 @@ getMoverSettings() {
if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
mvlogger "No Turbo Mode argument provided, defaulting to no"
ENABLETURBO="no"
echo 'enableTurbo="no"' >>$config_file
cfg_default enableTurbo no
fi
else
ENABLETURBO=$(cfg enableTurbo)
Expand All @@ -72,7 +78,7 @@ getMoverSettings() {
if [ -z $(cfg testmode) ]; then
if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
mvlogger "No Test Mode argument provided, defaulting to yes"
echo 'testmode="yes"' >>$config_file
# yes for this run only: written to the global cfg it would put the scheduled mover in test mode too
TESTMODE="yes"
fi
else
Expand Down
Loading