diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py
index 43743384c9..6c1a9098e2 100644
--- a/kolibri/utils/cli.py
+++ b/kolibri/utils/cli.py
@@ -334,6 +334,20 @@ def update(old_version, new_version):
 
     logger.info("Running update routines for new version...")
 
+    try:
+        # Check if there are other kolibri instances running
+        # If there are, then we need to stop users from starting kolibri again.
+        server.get_status()
+        logger.error(
+            "There is a Kolibri server running."
+            "Running updates now could cause a database error."
+            "Please use `kolibri stop` and try again."
+        )
+        sys.exit(1)
+
+    except server.NotRunning:
+        pass
+
     # Need to do this here, before we run any Django management commands that
     # import settings. Otherwise the updated configuration will not be used
     # during this runtime.

Migrations / Initialization happens without checking if another instance is running
### Observed behavior

Kolibri 0.13.0.dev runs migrations even though another instance is running, which can potentially lead to database corruption.

CC: @rtibbles 

### Expected behavior

Kolibri should immediately quit.

### User-facing consequences

Almost certainly bad.

### Errors and logs

```
➜  kolibri git:(develop) kolibri start --foreground          
WARNING:root:No C Extensions available for this platform.

INFO     Option RUN_MODE in section [Deployment] being overridden by environment variable KOLIBRI_RUN_MODE
INFO     Running Kolibri with the following settings: kolibri.deployment.default.settings.base
INFO     Version was 0.13.0.dev0+git.20190716150511, new version: 0.13.0.dev0+git.20190822215051
INFO     Running update routines for new version...
Operations to perform:
  Apply all migrations: admin, analytics, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, notifications, sessions
Running migrations:
  Applying content.0019_contentnode_slideshow_options... OK
  Applying morango.0013_auto_20190627_1513... OK
Operations to perform:
  Apply all migrations: admin, analytics, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, notifications, sessions
Running migrations:
  Applying content.0019_contentnode_slideshow_options... OK
  Applying morango.0013_auto_20190627_1513... OK
Installed 2 object(s) from 1 fixture(s)
INFO     Sqlite database Vacuum finished.
INFO     Running Kolibri
ERROR    Port 8080 is occupied.
Please check that you do not have other processes running on this port and try again.
```

### Steps to reproduce

Run Kolibri 0.12, so it shares directory with current `develop`. Then run `kolibri start --foreground`.

### Context

Development env. for current `develop` branch on a system with 0.12.8 installed from .deb.

### Related

The otherwise great #5494 
diff --git a/kolibri/utils/tests/test_cli.py b/kolibri/utils/tests/test_cli.py
index 6ef76aed0f..5296fa5f55 100755
--- a/kolibri/utils/tests/test_cli.py
+++ b/kolibri/utils/tests/test_cli.py
@@ -228,6 +228,20 @@ def test_update(update, get_version):
     update.assert_called_once()
 
 
+@pytest.mark.django_db
+@patch("kolibri.utils.cli.get_version", return_value="0.0.1")
+def test_update_exits_if_running(get_version):
+    """
+    Tests that update() function performs as expected
+    """
+    with patch("kolibri.utils.cli.server.get_status"):
+        try:
+            cli.initialize()
+            pytest.fail("Update did not exit when Kolibri was already running")
+        except SystemExit:
+            pass
+
+
 @pytest.mark.django_db
 def test_version_updated():
     """

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest mock
apt-get update apt-get install -y gcc
3.9
requirements/base.txt requirements/dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.16
anyio==4.9.0
args==0.1.0
aspy.yaml==1.3.0
babel==2.17.0
certifi==2025.1.31
cfgv==3.4.0
chardet==3.0.4
cheroot==6.1.2
CherryPy==13.0.1
Click==7.0
clint==0.5.1
colorama==0.4.6
colorlog==3.2.0
configobj==5.0.6
coreapi==2.3.3
coreschema==0.0.4
distlib==0.3.9
Django==1.11.23
django-debug-panel==0.8.3
django-debug-toolbar==1.9.1
django-filter==1.1.0
django-ipware==1.1.6
django-js-asset==1.2.3
django-js-reverse==0.9.1
django-mptt==0.9.1
django-oidc-provider==0.7.0
django-redis-cache==2.0.0
django-rest-swagger==2.2.0
djangorestframework==3.9.1
djangorestframework-csv==2.1.0
docutils==0.19
exceptiongroup==1.2.2
filelock==3.18.0
flake8==3.5.0
fonttools==3.29.0
future==0.16.0
futures==3.1.1
h11==0.14.0
html5lib==1.0.1
iceqube==0.4
identify==2.6.9
idna==2.8
ifcfg==0.18
imagesize==1.4.1
importlib_metadata==8.6.1
iniconfig==2.1.0
itypes==1.2.0
Jinja2==3.1.6
jsonfield==2.0.2
-e git+https://github.com/learningequality/kolibri.git@99ba95d7b0e26095292bbe1bcd382ea634927967#egg=kolibri
kolibri-exercise-perseus-plugin==1.2.2a3
le-utils==0.1.20
MarkupSafe==3.0.2
mccabe==0.6.1
Metafone==0.5
mock==5.2.0
morango==0.4.9
more-itertools==10.6.0
nodeenv==1.3.3
openapi-codec==1.3.2
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
portend==3.2.0
porter2stemmer==1.0
pre-commit==1.15.1
py==1.11.0
pyasn1==0.6.1
pycodestyle==2.3.1
pycountry==17.5.14
pycryptodomex==3.22.0
pyflakes==1.6.0
Pygments==2.19.1
pyjwkest==1.4.2
pytest==8.3.5
python-dateutil==2.7.5
pytz==2018.5
PyYAML==6.0.2
redis==3.2.1
requests==2.21.0
requests-toolbelt==0.8.0
rsa==3.4.2
semver==2.8.1
simplejson==3.20.1
six==1.11.0
sniffio==1.3.1
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinx-autobuild==2024.10.3
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
SQLAlchemy==1.2.10
sqlparse==0.5.3
starlette==0.46.1
tabulate==0.8.2
tempora==1.12
toml==0.10.2
tomli==2.2.1
tox==3.1.3
typing_extensions==4.13.0
tzlocal==1.5.1
unicodecsv==0.14.1
uritemplate==4.1.1
urllib3==1.24.3
uvicorn==0.34.0
virtualenv==20.29.3
watchfiles==1.0.4
webencodings==0.5.1
websockets==15.0.1
zipp==3.21.0

name: kolibri
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.16
      - anyio==4.9.0
      - args==0.1.0
      - aspy-yaml==1.3.0
      - babel==2.17.0
      - certifi==2025.1.31
      - cfgv==3.4.0
      - chardet==3.0.4
      - cheroot==6.1.2
      - cherrypy==13.0.1
      - click==7.0
      - clint==0.5.1
      - colorama==0.4.6
      - colorlog==3.2.0
      - configobj==5.0.6
      - coreapi==2.3.3
      - coreschema==0.0.4
      - distlib==0.3.9
      - django==1.11.23
      - django-debug-panel==0.8.3
      - django-debug-toolbar==1.9.1
      - django-filter==1.1.0
      - django-ipware==1.1.6
      - django-js-asset==1.2.3
      - django-js-reverse==0.9.1
      - django-mptt==0.9.1
      - django-oidc-provider==0.7.0
      - django-redis-cache==2.0.0
      - django-rest-swagger==2.2.0
      - djangorestframework==3.9.1
      - djangorestframework-csv==2.1.0
      - docutils==0.19
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - flake8==3.5.0
      - fonttools==3.29.0
      - future==0.16.0
      - futures==3.1.1
      - h11==0.14.0
      - html5lib==1.0.1
      - iceqube==0.4
      - identify==2.6.9
      - idna==2.8
      - ifcfg==0.18
      - imagesize==1.4.1
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - itypes==1.2.0
      - jinja2==3.1.6
      - jsonfield==2.0.2
      - kolibri-exercise-perseus-plugin==1.2.2a3
      - le-utils==0.1.20
      - markupsafe==3.0.2
      - mccabe==0.6.1
      - metafone==0.5
      - mock==5.2.0
      - morango==0.4.9
      - more-itertools==10.6.0
      - nodeenv==1.3.3
      - openapi-codec==1.3.2
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - portend==3.2.0
      - porter2stemmer==1.0
      - pre-commit==1.15.1
      - py==1.11.0
      - pyasn1==0.6.1
      - pycodestyle==2.3.1
      - pycountry==17.5.14
      - pycryptodomex==3.22.0
      - pyflakes==1.6.0
      - pygments==2.19.1
      - pyjwkest==1.4.2
      - pytest==8.3.5
      - python-dateutil==2.7.5
      - pytz==2018.5
      - pyyaml==6.0.2
      - redis==3.2.1
      - requests==2.21.0
      - requests-toolbelt==0.8.0
      - rsa==3.4.2
      - semver==2.8.1
      - simplejson==3.20.1
      - six==1.11.0
      - sniffio==1.3.1
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinx-autobuild==2024.10.3
      - sphinxcontrib-applehelp==2.0.0
      - sphinxcontrib-devhelp==2.0.0
      - sphinxcontrib-htmlhelp==2.1.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==2.0.0
      - sphinxcontrib-serializinghtml==2.0.0
      - sqlalchemy==1.2.10
      - sqlparse==0.5.3
      - starlette==0.46.1
      - tabulate==0.8.2
      - tempora==1.12
      - toml==0.10.2
      - tomli==2.2.1
      - tox==3.1.3
      - typing-extensions==4.13.0
      - tzlocal==1.5.1
      - unicodecsv==0.14.1
      - uritemplate==4.1.1
      - urllib3==1.24.3
      - uvicorn==0.34.0
      - virtualenv==20.29.3
      - watchfiles==1.0.4
      - webencodings==0.5.1
      - websockets==15.0.1
      - zipp==3.21.0
prefix: /opt/conda/envs/kolibri

kolibri/utils/tests/test_cli.py::test_update_exits_if_running
kolibri/utils/tests/test_cli.py::test_kolibri_listen_port_env
kolibri/utils/tests/test_cli.py::test_bogus_plugin_autoremove kolibri/utils/tests/test_cli.py::test_bogus_plugin_autoremove_no_path kolibri/utils/tests/test_cli.py::test_bogus_plugin_disable kolibri/utils/tests/test_cli.py::test_plugin_cannot_be_imported_disable kolibri/utils/tests/test_cli.py::test_real_plugin_disable kolibri/utils/tests/test_cli.py::test_real_plugin_disable_twice kolibri/utils/tests/test_cli.py::test_plugin_with_no_plugin_class kolibri/utils/tests/test_cli.py::test_first_run kolibri/utils/tests/test_cli.py::test_update kolibri/utils/tests/test_cli.py::test_version_updated kolibri/utils/tests/test_cli.py::test_update_no_version_change kolibri/utils/tests/test_cli.py::test_cli_usage
kolibri/utils/cli.py
kolibri/utils/cli.py