Configuration (config.yaml) changed by what ever?

after some days doing some other stuff, I wanted to start a 3D print job.
But on the web user interface there where no files shown at all.
Reason: the directory settings at config.yamal had been changed by a ghost.

actual config file:

(...)
feature:
    printStartConfirmation: true
    sdSupport: false
folder:
    timelapse: /mnt/usb1/octoprint/timelapse
plugins:
    DisplayLayerProgress:
        sendLayerInformationsViaWebSocket: false
(...)

my backup of config file:

(...)
feature:
    printStartConfirmation: true
    sdSupport: false
folder:
    logs: /mnt/usb1/octoprint/logs
    timelapse: /mnt/usb1/octoprint/timelapse
    timelapse_tmp: /mnt/usb1/octoprint/timelapse/tmp
    uploads: /mnt/usb1/octoprint/uploads
    watched: /mnt/usb1/octoprint/watched
plugins:
    DisplayLayerProgress:
        sendLayerInformationsViaWebSocket: false
(...)

How can this happen?
Definitely nobody has attached OctoPrint configuration since last print and there was everything as it should.
Surely in the mean time the Pi had to do other work and was started and stopped several times. Because OctoPrint is configured as daemon it had been started several times also. But it was just in the background without doing some prints.

Ok, at the end it was not really a problem. Just stop Octoprint, restore security copy of config.yaml and restart Octoprint and everything was right again.
But: how can this happen? (Octoprint V. 1.4.2 ahead Python 3.6.x, Pi 3B+ with full Pi Ubuntu Stretch)

It happened again.
What the hell is Octoprint doing with it's config.yaml?

If the folders are not available on boot of OctoPrint, they are reset to the defaults - otherwise everything will crash. You should make sure that that path (/mnt/usb1) is available before OctoPrint starts up.

wasn't there an issue recently that had an example of how to set the Needs or Needed parameter of the service file to include a mount point?

This one: Octoprint is reverting custom timelaps directory to default Β· Issue #3931 Β· OctoPrint/OctoPrint (github.com)

1 Like

Yep, just found it as well. @bastelulli the link in there by foosel might be of assistance for figuring out what you need to add to the service file for octoprint.

Ok. it's a feature to change config file, also it might make admin unhappy :wink:
Might be worth to think about changing directories internal only without changing config file in case of no access to configured directories. Maybe it's temporary only.
I'll set a condition at service start file, that OctoPrint deamon start depends on already mounted USB file system.

Thanks for your explenation of OctoPrint internals.

1 Like

Tweaking the octoprint service file did not help solving my issue with the reverting to default folders.
I "guess" octoprint may not happy with custom folders?

Well we definitely know that it's not happy when it can't see or access folders on initialization, and that's what causes the configured folder settings to revert to the defaults. I'm not familiar enough with linux service config files to be of any help here.

there must be a awful bug in the deeps of Python or Octoprint.
Actually Octoprint is not willing to use my folders also they are well mounted and there is access to everyone.

WIthout rebooting the Pi, I stopped Octoprint. Then I added the folders section

folder:
    logs: /mnt/usb1/octoprint/logs
    timelapse: /mnt/usb1/octoprint/timelapse
    timelapse_tmp: /mnt/usb1/octoprint/timelapse/tmp
    uploads: /mnt/usb1/octoprint/uploads
    watched: /mnt/usb1/octoprint/watched

to the config file and called
sudo systemctl start octoprint

From the syslog:

Jan 21 11:26:37 raspiMil octoprint[1275]: 2021-01-21 11:26:37,813 - octoprint.settings - ERROR - Invalid configured logs folder at /mnt/usb1/octoprint/logs, attempting to fall back on default folder at /home/pi/.octoprint/logs
Jan 21 11:26:38 raspiMil octoprint[1275]: 2021-01-21 11:26:38,751 - octoprint.startup - INFO - ******************************************************************************
Jan 21 11:26:38 raspiMil octoprint[1275]: 2021-01-21 11:26:38,753 - octoprint.startup - INFO - Starting OctoPrint 1.4.2
Jan 21 11:26:38 raspiMil octoprint[1275]: 2021-01-21 11:26:38,754 - octoprint.startup - INFO - ******************************************************************************
Jan 21 11:26:38 raspiMil octoprint[1275]: 2021-01-21 11:26:38,756 - octoprint.settings - ERROR - Invalid configured uploads folder at /mnt/usb1/octoprint/uploads, attempting to fall back on default folder at /home/pi/.octoprint/uploads
Jan 21 11:26:39 raspiMil octoprint[1275]: 2021-01-21 11:26:39,126 - octoprint.settings - ERROR - Invalid configured timelapse folder at /mnt/usb1/octoprint/timelapse, attempting to fall back on default folder at /home/pi/.octoprint/timelapse
Jan 21 11:26:39 raspiMil octoprint[1275]: 2021-01-21 11:26:39,490 - octoprint.settings - ERROR - Invalid configured timelapse_tmp folder at /mnt/usb1/octoprint/timelapse/tmp, attempting to fall back on default folder at /home/pi/.octoprint/timelapse/tmp
Jan 21 11:26:39 raspiMil octoprint[1275]: 2021-01-21 11:26:39,864 - octoprint.settings - ERROR - Invalid configured watched folder at /mnt/usb1/octoprint/watched, attempting to fall back on default folder at /home/pi/.octoprint/watched

Before start I looked to the configured folders by remote/WinSCP. Everything looks fine as it should.
Not to fall into a writing error additional I tried using remote/Putty:
Copy the one path from log file to Windows clipboard and past it to cd-command

pi@raspiMil:~ $ cd /mnt/usb1/octoprint/timelapse
pi@raspiMil:/mnt/usb1/octoprint/timelapse $ ls -l
insgesamt 8
drwxrwxrwx 2 root root 8192 Jan 21 11:09 tmp

Could it be because they are owned by root, and so OctoPrint running (hopefully not as root) can't write to them?

no. access is allowe to ervybody

It is to despair. It doesn't work as I guess:
Error is thrown by settings.py #1579 ..

		try:
			_validate_folder(folder, create=create, check_writable=check_writable, deep_check_writable=deep_check_writable, log_error=log_error)
		except Exception:
			if folder != default_folder and allow_fallback:
				if log_error:
					self._logger.error("Invalid configured {} folder at {}, attempting to "
					                   "fall back on default folder at {}".format(type,
					                                                              folder,
					                                                              default_folder))

_validate_folder should log some detailed error messages:

def _validate_folder(folder, create=True, check_writable=True, deep_check_writable=False, log_error=False):
	logger = logging.getLogger(__name__)

	if not os.path.exists(folder):
		if os.path.islink(folder):
			# broken symlink, see #2644
			raise IOError("Folder at {} appears to be a broken symlink".format(folder))

		elif create:
			# non existing, but we are allowed to create it
			try:
				os.makedirs(folder)
			except Exception:
				if log_error:
					logger.exception("Could not create {}".format(folder))
				raise IOError("Folder for type {} at {} does not exist and creation failed".format(type, folder))

		else:
			# not extisting, not allowed to create it
			raise IOError("No such folder: {}".format(folder))

	elif os.path.isfile(folder):
		# hardening against misconfiguration, see #1953
		raise IOError("Expected a folder at {} but found a file instead".format(folder))

	elif check_writable:
		# make sure we can also write into the folder
		error = "Folder at {} doesn't appear to be writable, please fix its permissions".format(folder)
		if not os.access(folder, os.W_OK):
			raise IOError(error)

		elif deep_check_writable:
			# try to write a file to the folder - on network shares that might be the only reliable way
			# to determine whether things are *actually* writable
			testfile = os.path.join(folder, ".testballoon.txt")
			try:
				with io.open(testfile, 'wt', encoding='utf-8') as f:
					f.write("test")
				os.remove(testfile)
			except Exception:
				if log_error:
					logger.exception("Could not write test file to {}".format(folder))
				raise IOError(error)

But also log level is set to DEBUG
logging.yaml:

loggers:
  octoprint:
    level: DEBUG

and logging directory is default, there are no log messages from _validate_folder:

2021-01-21 12:28:20,030 - octoprint.startup - INFO - ******************************************************************************
2021-01-21 12:28:20,032 - octoprint.startup - INFO - Starting OctoPrint 1.4.2
2021-01-21 12:28:20,033 - octoprint.startup - INFO - ******************************************************************************
2021-01-21 12:28:20,035 - octoprint.settings - ERROR - Invalid configured uploads folder at /mnt/usb1/octoprint/uploads, attempting to fall back on default folder at /home/pi/.octoprint/uploads
2021-01-21 12:28:20,993 - octoprint.settings - ERROR - Invalid configured timelapse folder at /mnt/usb1/octoprint/timelapse, attempting to fall back on default folder at /home/pi/.octoprint/timelapse
2021-01-21 12:28:21,361 - octoprint.settings - ERROR - Invalid configured timelapse_tmp folder at /mnt/usb1/octoprint/timelapse/tmp, attempting to fall back on default folder at /home/pi/.octoprint/timelapse/tmp
2021-01-21 12:28:21,726 - octoprint.settings - ERROR - Invalid configured watched folder at /mnt/usb1/octoprint/watched, attempting to fall back on default folder at /home/pi/.octoprint/watched
2021-01-21 12:28:22,119 - octoprint.util.connectivity.connectivity_checker - INFO - Connectivity state is currently: online
2021-01-21 12:28:22,119 - octoprint.util.connectivity.connectivity_checker - INFO - Connecting to 8.8.8.8:53 is working
2021-01-21 12:28:22,119 - octoprint.util.connectivity.connectivity_checker - INFO - Resolving octoprint.org is working
2021-01-21 12:28:22,179 - octoprint.plugin.core - INFO - Loading plugins from /home/pi/OctoPrint/venv/lib/python3.6/site-packages/octoprint/plugins, /home/pi/.octoprint/plugins and installed plugin packages...
2021-01-21 12:28:22,181 - octoprint.plugin.core - DEBUG - Parsing plugin metadata for gcodeviewer from AST of

Proposal:
Change code of getBaseFolder(), settings.py #1567 Octoprint 4.2

existing:
try:
_validate_folder(folder, create=create, check_writable=check_writable, deep_check_writable=deep_check_writable, log_error=log_error)
except Exception as e:
self._logger.error( str(e))
if folder != default_folder and allow_fallback:
if log_error:

new:
except Exception as e:
self._logger.error( str(e))
if folder != default_folder and allow_fallback:

This might help to find what's going wrong.

The problem is Python os.access() function.
To go deeper, maybe one could tell me where the code of this function is.
Seems, that is is the same problem than I found at a shelutil function. System is Linux, but USB file system is FAT, what not supports all Linux access functions.