Permission denied: '/home/klippy/.config/moonraker.conf' leads to 502 Bad Gateway issue
Hi,
I've tried to pull latest version and started getting 502 Bad Gateway on fluidd and mainsail, after investigation it seems they're not able to connect moonraker
From container startup log:
PermissionError: [Errno 13] Permission denied: '/home/klippy/.config/moonraker.conf' [moonraker.py:main()] - Server Shutdown return self._accessor.stat(self, follow_symlinks=follow_symlinks) File "/usr/local/lib/python3.10/pathlib.py", line 1097, in stat File "/usr/local/lib/python3.10/pathlib.py", line 1322, in is_file return S_ISREG(self.stat().st_mode) if not file_path.is_file(): File "/home/klippy/moonraker/moonraker/confighelper.py", line 1012, in _parse_file self._parse_file(main_conf, []) File "/home/klippy/moonraker/moonraker/confighelper.py", line 1028, in read_file source.read_file(start_path) File "/home/klippy/moonraker/moonraker/confighelper.py", line 1040, in get_configuration config = confighelper.get_configuration(self, self.app_args) File "/home/klippy/moonraker/moonraker/moonraker.py", line 129, in _parse_config self.config = config = self._parse_config() File "/home/klippy/moonraker/moonraker/moonraker.py", line 67, in __init__ server = Server(app_args, file_logger, event_loop) File "/home/klippy/moonraker/moonraker/moonraker.py", line 460, in main Traceback (most recent call last): During handling of the above exception, another exception occurred: stat = file_path.stat() File "/home/klippy/moonraker/moonraker/confighelper.py", line 924, in _parse_file [moonraker.py:main()] - Moonraker Error [utils.py:setup_logging()] - python_version: 3.10.7 (main, Sep 13 2022, 03:02:33) [GCC 10.2.1 20210110] [utils.py:setup_logging()] - software_version: v0.7.1-660-g5d856b9 [utils.py:setup_logging()] - log_file: /var/log/klipper/moonraker.log [utils.py:setup_logging()] - startup_warnings: []
Have something changed in the last docker images updates?
I run mainsail but I seem to be affected by the same issue. It seems like something in Moonraker has changed and now it's not working anymore...
I've ended up using some older version from docker build as a workaround, but having issues with config as well, so put all needed items in the printer.cfg
@speendo I ended up migrating to https://github.com/mkuf/prind, seems like more robust and better maintained solution with same set of feature/frontends
Thanks. I was using prind before, it sort of worked but this project was easier to handle for me. Well, at least until recently :)
@dimalo do you have any plans about this issue? (just to make it clear: I am fine if you don't have any, just want to know)
I think I might have understood where the problem is coming from.
Recent versions of moonraker expect all files to be in the directory /home/<user>/printer_data/, e.g. /home/<user>/config or /home/<user>/gcodes.
This docker image however is configured to store all files at /home/klippy (where klippy is the user name defined in the Dockerfile). So the config lays in /home/klippy/.config and gcodes files are at /home/klippy/gcode_files.
For an ideal solution, it would be best to follow the standard, that moonraker expects. However, to do this, one would not only need to change the Dockerfile (which would be okay), but also many people who linked their gcode or settings folder in the docker-compose.yml would need to change their settings.
For the moment, I decided for a quick workaround (that I actually would need to repeat every time I update my docker image, so take care). It works like this
- Go to
klipper/moonraker.iniand change the linecommand=/home/klippy/moonraker-env/bin/python /home/klippy/moonraker/moonraker/moonraker.py -l /var/log/klipper/moonraker.log -c /home/klippy/.config/moonraker.conftocommand=/home/klippy/moonraker-env/bin/python /home/klippy/moonraker/moonraker/moonraker.py -l /var/log/klipper/moonraker.log -d /home/klippy -c /home/klippy/.config/moonraker.conf - Go into the running docker container with
docker exec -it klipper /bin/bash - In the docker container delete the directories
/home/klippy/printer_data/configand/home/klippy/printer_data/gcodes. Make sure that you backup the content of those folders, in case they are not empty. You have been warned! To delete a folder, use `rm -r <folder_path> - Create symlinks to replace the folders you just deleted: Run
ln -s /home/klippy/.config /home/klippy/printer_data/configandln -s /home/klippy/gcode_files /home/klippy/printer_data/gcodes. - Restart the docker container.
- In case you still have problems, they might be caused by permission problems. Make sure that the user klippy has read and write access to the folders you just linked (you can check by logging into the docker container again and run
ls -al /home/klippy).
It would be possible to integrate this workaround in the dockerfile, however it might be better to think of a solution that is consistent with the moonraker default configuration.
The problems should be solved with my pull request or by using https://github.com/speendo/klipper-web-control-docker/tree/main in the mean time
@dimalo any update on getting this fix merged in?