diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 15cfbbbf..e182e6bb 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -621,7 +621,8 @@ Use the following settings to configure the server: .. code-block:: yaml server: - # Use this option to define the host to which to bind the server, defaults to "0.0.0.0" (= all interfaces) + # Use this option to define the host to which to bind the server, defaults to "0.0.0.0" (= all + # interfaces) host: 0.0.0.0 # Use this option to define the port to which to bind the server, defaults to 5000 @@ -691,6 +692,18 @@ Use the following settings to configure the server: # Maximum size of requests other than file uploads in bytes, defaults to 100KB. maxSize: 102400 + # Commands to restart/shutdown octoprint or the system it's running on + commands: + + # Command to restart OctoPrint, defaults to being unset + serverRestartCommand: sudo service octoprint restart + + # Command to restart the system OctoPrint is running on, defaults to being unset + systemRestartCommand: sudo shutdown -r now + + # Command to shut down the system OctoPrint is running on, defaults to being unset + systemShutdownCommand: sudo shutdown -h now + .. note:: diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 5a0da551..c96ed33f 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -150,9 +150,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, "restart": "octoprint" }, }, - - "octoprint_restart_command": None, - "environment_restart_command": None, "pip_command": None, "cache_ttl": 24 * 60, @@ -177,13 +174,35 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_ttl = self._settings.get_int(["cache_ttl"]) * 60 def get_settings_version(self): - return 3 + return 4 def on_settings_migrate(self, target, current=None): + + if current is None or current < 4: + # config version 4 and higher moves octoprint_restart_command and + # environment_restart_command to the core configuration + + # current plugin commands + configured_octoprint_restart_command = self._settings.get(["octoprint_restart_command"]) + configured_environment_restart_command = self._settings.get(["environment_restart_command"]) + + # current global commands + configured_system_restart_command = self._settings.global_get(["server", "commands", "systemRestartCommand"]) + configured_server_restart_command = self._settings.global_get(["server", "commands", "serverRestartCommand"]) + + # only set global commands if they are not yet set + if configured_system_restart_command is None and configured_environment_restart_command is not None: + self._settings.global_set(["server", "commands", "systemRestartCommand"], configured_environment_restart_command) + if configured_server_restart_command is None and configured_octoprint_restart_command is not None: + self._settings.global_set(["server", "commands", "serverRestartCommand"], configured_octoprint_restart_command) + + # delete current plugin commands from config + self._settings.set(["environment_restart_command"], None) + self._settings.set(["octoprint_restart_command"], None) + if current is None or current == 2: - # there might be some left over data from the time we still persisted everything to settings, - # even the stuff that shouldn't be persisted but always provided by the hook - let's - # clean up + # No config version and config version 2 need the same fix, stripping + # accidentally persisted data off the checks configured_checks = self._settings.get(["checks"], incl_defaults=False) if configured_checks is None: @@ -229,6 +248,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._settings.set(["checks", key], None, defaults=dummy_defaults) elif current == 1: + # config version 1 had the error that the octoprint check got accidentally + # included in checks["octoprint"], leading to recursion and hence to + # yaml parser errors + configured_checks = self._settings.get(["checks"], incl_defaults=False) if configured_checks is None: return @@ -239,7 +262,6 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, dummy_defaults["plugins"][self._identifier] = dict(checks=dict()) dummy_defaults["plugins"][self._identifier]["checks"]["octoprint"] = None self._settings.set(["checks", "octoprint"], None, defaults=dummy_defaults) - self._settings.save() def _clean_settings_check(self, key, data, defaults, delete=None, save=True): if delete is None: @@ -496,7 +518,11 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if restart_type is not None and restart_type in ("octoprint", "environment"): # one of our updates requires a restart of either type "octoprint" or "environment". Let's see if # we can actually perform that - restart_command = self._settings.get(["%s_restart_command" % restart_type]) + + if restart_type == "octoprint": + restart_command = self._settings.global_get(["server", "commands", "serverRestartCommand"]) + elif restart_type == "environment": + restart_command = self._settings.global_get(["server", "commands", "systemRestartCommand"]) if restart_command is not None: self._send_client_message("restarting", dict(restart_type=restart_type, results=target_results)) diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 1e192fe8..36cc7657 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -19,8 +19,6 @@ $(function() { self.workingOutput = undefined; self.loglines = ko.observableArray([]); - self.config_restartCommand = ko.observable(); - self.config_rebootCommand = ko.observable(); self.config_cacheTtl = ko.observable(); self.configurationDialog = $("#settings_plugin_softwareupdate_configurationdialog"); @@ -84,8 +82,6 @@ $(function() { var data = { plugins: { softwareupdate: { - octoprint_restart_command: self.config_restartCommand(), - environment_restart_command: self.config_rebootCommand(), cache_ttl: parseInt(self.config_cacheTtl()) } } @@ -94,8 +90,6 @@ $(function() { }; self._copyConfig = function() { - self.config_restartCommand(self.settings.settings.plugins.softwareupdate.octoprint_restart_command()); - self.config_rebootCommand(self.settings.settings.plugins.softwareupdate.environment_restart_command()); self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl()); }; diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index cee30242..d649099d 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -55,18 +55,6 @@