Skip to content

Commit

Permalink
♻️ Use file instead of config for incomplete startup flag
Browse files Browse the repository at this point in the history
Makes it easier in CI situations to reconfigure the server.
  • Loading branch information
foosel committed Jul 18, 2023
1 parent ceb85d3 commit fc53dab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 0 additions & 4 deletions docs/configuration/config_yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,6 @@ Use the following settings to configure the server:
# reset the setting to false
startOnceInSafeMode: false
# Signals to OctoPrint that the last startup was incomplete. OctoPrint will then startup
# in safe mode
incompleteStartup: false
# Set this to true to make OctoPrint ignore incomplete startups. Helpful for development.
ignoreIncompleteStartup: false
Expand Down
2 changes: 1 addition & 1 deletion src/octoprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def init_platform(
)
settings_incomplete_startup_safemode = (
"incomplete_startup"
if settings.getBoolean(["server", "incompleteStartup"])
if os.path.exists(os.path.join(settings._basedir, ".incomplete_startup"))
and not settings.getBoolean(["server", "ignoreIncompleteStartup"])
else None
)
Expand Down
3 changes: 0 additions & 3 deletions src/octoprint/schema/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ class ServerConfig(BaseModel):
ignoreIncompleteStartup: bool = False
"""Set this to true to make OctoPrint ignore incomplete startups. Helpful for development."""

incompleteStartup: bool = False
"""Signals to OctoPrint that the last startup was incomplete. OctoPrint will then startup in safe mode."""

seenWizards: Dict[str, str] = {}

secretKey: Optional[str] = None
Expand Down
19 changes: 15 additions & 4 deletions src/octoprint/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging.config
import mimetypes
import os
import pathlib
import re
import signal
import sys
Expand Down Expand Up @@ -300,9 +301,14 @@ def run(self):
if self._settings is None:
self._settings = settings()

incomplete_startup_flag = (
pathlib.Path(self._settings._basedir) / ".incomplete_startup"
)
if not self._settings.getBoolean(["server", "ignoreIncompleteStartup"]):
self._settings.setBoolean(["server", "incompleteStartup"], True)
self._settings.save()
try:
incomplete_startup_flag.touch()
except Exception:
self._logger.exception("Could not create startup triggered safemode flag")

if self._plugin_manager is None:
self._plugin_manager = octoprint.plugin.plugin_manager()
Expand Down Expand Up @@ -1294,8 +1300,13 @@ def call_on_after_startup(name, plugin):

# if there was a rogue plugin we wouldn't even have made it here, so remove startup triggered safe mode
# flag again...
self._settings.setBoolean(["server", "incompleteStartup"], False)
self._settings.save()
try:
if incomplete_startup_flag.exists():
incomplete_startup_flag.unlink()
except Exception:
self._logger.exception(
"Could not clear startup triggered safe mode flag"
)

# make a backup of the current config
self._settings.backup(ext="backup")
Expand Down

0 comments on commit fc53dab

Please sign in to comment.