Mattermost resets config file periodically / on startup

Hi, thanks for your response. Yes what you are describing matches my experience from earlier today. Though it did not always reset the config immediately upon start. One time it took a while (20+ minutes).
My initial reaction was “the script must have failed copying the config file back” (which makes no sense as my login still worked, without the correct config file there would not have been database access for logging in users)

I have created a script based on the standard upgrade instructions (Upgrading Mattermost Server — Mattermost 5.31 documentation) with a couple of optimisations and automated backups etc:

#!/bin/bash
#steps taken from
# https://docs.mattermost.com/administration/upgrade.html
# last checked 2020-01-20

###
# You should gather the following information before starting the upgrade:
#
# Existing install directory - {install-path}
# If you don’t know where Mattermost Server is installed, use the whereis mattermost command. The output should be similar to /opt/mattermost/bin/mattermost. The install directory is everything before the first occurrence of the string /mattermost. In this example, the {install-path} is /opt. If that command does not produce any results because your version is older, try whereis platform instead.
#
# Location of your local storage directory
# The local storage directory contains all the files that users have attached to their messages. If you don’t know its location, open the System Console and go to Files > Storage in prior versions or Environment> File Storage in versions after 5.12 and read the value in Local Storage Directory. Relative paths are relative to the mattermost directory. For example, if the local storage directory is ./data/ then the absolute path is {install-path}/mattermost/data.
###
# here: $install_path and $data_path
#

version=$1
ts=$(date +'%F-%H-%M')

if test "$1" == ""; then
  echo 'no version'
  exit 1

else
  test "$version" == "latest" && url=$(wget -qO- https://mattermost.com/download/ | grep 'https://[^&]*releases[^&]*mattermost[^&]*\.tar\.gz' -o | grep -v 'desktop' | uniq) || url="https://releases.mattermost.com/${version}/mattermost-${version}-linux-amd64.tar.gz"
  tmp=${url#*/*/*/}
  v=${tmp%%/*}
  while true; do
    read -p "Current version is [ $( grep -o 'Current version is [^[:space:]]*' /var/log/mattermost/mattermost.log | tail -n1 | cut -d' ' -f4 ) ]. Updating to [ $v ]. Do you wish to continue? " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
  done

install_path=/opt
mm_path=${install_path}/mattermost
data_path=${mm_path}/data/
###

# modified from MM instructions: extract to install_path
#cd /tmp/

wget "$url"
version=$(echo "$url" | cut -d/ -f4)

backupvers=mm-backup-pre-${version//./-}

here=$(pwd)
file=$(basename "$url")
mkdir "./$version"
#cd "./$version"
#tar -xf mattermost*.gz --transform='s,^[^/]\+,\0-upgrade,'
tar -C ./$version -xf $file

cd ${install_path}

read -p "READY TO STOP MM?"

# already in install_path (changed from MM instructions)
#cd ${install_path}
sudo systemctl stop mattermost || echo "Unable to stop MM"
echo "$(date) start DB SNAPSHOT now:"
aws rds create-db-snapshot --db-snapshot-identifier "${backupvers}" --db-instance-identifier "mattermost" --region "ap-southeast-2"

# MM Upgrade page suggestion:
#sudo cp -ra mattermost/ mattermost-$backupvers-$(date +'%F-%H-%M')/
#sudo find mattermost/ mattermost/client/ -mindepth 1 -maxdepth 1 \! \( -type d \( -path mattermost/client -o -path mattermost/client/plugins -o -path mattermost/config -o -path mattermost/logs -o -path mattermost/plugins -o -path mattermost/data \) -prune \) | sort | sudo xargs echo rm -r

# Quicker implementation. Less risk of losing data.
sudo mv -iv mattermost mattermost-$backupvers-$ts
sudo mv -iv $here/$version/mattermost ./mattermost
sudo chown -hR mattermost:mattermost ./mattermost
sudo cp -ra ./mattermost-$backupvers-$ts/logs ./mattermost/
sudo cp -ra ./mattermost-$backupvers-$ts/config ./mattermost/

sudo setcap cap_net_bind_service=+ep $mm_path/bin/mattermost

echo "$( date ) waiting for snapshot to complete"
aws rds wait db-snapshot-completed  --db-instance-identifier "mattermost" --region "ap-southeast-2"
echo "$( date ) snapshot completed. Starting Mattermost"
#read -p "READY TO START MM AGAIN? Snapshot complete etc?"
sudo systemctl start mattermost
RES=$?
if test "$RES" -eq "0"; then
  echo "$( date ) Mattermost started [ $RES ]"
else
  echo ' **************************************************************************** '
  echo ' ** HELP ****** HELP ****** HELP ****** HELP ****** HELP ****** HELP ******** '
  echo ' ******** HELP ****** HELP ****** HELP ****** HELP ****** HELP ****** HELP ** '
  echo ' **************************************************************************** '
  read -p "$(date) UNABLE TO START MM. PLEASE CHECK. [ $RES ]"
fi

  echo ' **************************************************************************** '
  echo ' **************************************************************************** '
echo "$( date ) Open the System Console and change a setting, then revert it. This should enable the Save button for that page. SAVE, then reload that page"
echo "https://mm.snapit.group:40404/admin_console or https://mm.snapit.group:40404/admin_console/site_config/localization"

while true; do
    read -p "Have you updated MM settings and wish to continue? " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

echo "$( date ) config updated. Stopping Mattermost"
sudo systemctl stop mattermost
RES=$?
if test "$RES" -eq "0"; then
  echo "$( date ) Mattermost stopped again [ $RES ]"
else
  echo ' **************************************************************************** '
  echo ' ** HELP ****** HELP ****** HELP ****** HELP ****** HELP ****** HELP ******** '
  echo ' ******** HELP ****** HELP ****** HELP ****** HELP ****** HELP ****** HELP ** '
  echo ' **************************************************************************** '
  read -p "$(date) UNABLE TO STOP MM. PLEASE CHECK. [ $RES ]"
fi

echo "$( date ) MM Stopped. Copy plugins back"
sudo cp -ra ./mattermost-$backupvers-$ts/plugins ./mattermost/
echo "$( date ) Copy client plugins back"
sudo cp -ra ./mattermost-$backupvers-$ts/client/plugins ./mattermost/client/
echo "$( date ) All plugins copied. Starting Mattermost"

sudo systemctl start mattermost
RES=$?
if test "$RES" -eq "0"; then
  echo "$( date ) Mattermost started again - all set and upgraded [ $RES ]"
else
  echo ' **************************************************************************** '
  echo ' ** HELP ****** HELP ****** HELP ****** HELP ****** HELP ****** HELP ******** '
  echo ' ******** HELP ****** HELP ****** HELP ****** HELP ****** HELP ****** HELP ** '
  echo ' **************************************************************************** '
  read -p "$(date) UNABLE TO START MM. PLEASE CHECK. [ $RES ]"
fi

cd $here

while true; do
    read -p "Do you want to proceed with a system update? " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done
sudo apt update
sudo apt upgrade
sudo apt autoremove
sudo apt autoclean
sudo apt clean

while true; do
    read -p "Do you want to proceed with a system reboot? " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done
sudo reboot now

fi