Local scan fails

Hello everyone!
I’m using mopidy on an OrangePi PC running DietPi, and it has been working fine for some time.
Now, when I try to update the local database (mopidyctl local scan) I receive the following error:

ERROR [Errno 13] Permission denied: '/mnt/dietpi_userdata/mopidy/dat /local/library.json.gz.fSFK1W' Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mopidy/__main__.py", line 134, in main return args.command.run(args, proxied_config) File "/usr/lib/python2.7/dist-packages/mopidy/local/commands.py", lin 167, in run library.close() File "/usr/lib/python2.7/dist-packages/mopidy/local/json.py", line 17 , in close 'tracks': self._tracks.values() File "/usr/lib/python2.7/dist-packages/mopidy/internal/storage.py", l ne 51, in dump prefix=basename + '.', dir=directory, delete=False) File "/usr/lib/python2.7/tempfile.py", line 462, in NamedTemporaryFil (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner fd = _os.open(file, flags, 0600) OSError: [Errno 13] Permission denied: '/mnt/dietpi_userdata/mopidy/dat /local/library.json.gz.fSFK1W' Traceback (most recent call last): File "/usr/bin/mopidy", line 9, in <module> load_entry_point('Mopidy==2.1.0', 'console_scripts', 'mopidy')() File "/usr/lib/python2.7/dist-packages/mopidy/__main__.py", line 134, in main return args.command.run(args, proxied_config) File "/usr/lib/python2.7/dist-packages/mopidy/local/commands.py", lin 167, in run library.close() File "/usr/lib/python2.7/dist-packages/mopidy/local/json.py", line 17 , in close 'tracks': self._tracks.values() File "/usr/lib/python2.7/dist-packages/mopidy/internal/storage.py", l ne 51, in dump prefix=basename + '.', dir=directory, delete=False) File "/usr/lib/python2.7/tempfile.py", line 462, in NamedTemporaryFil (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner fd = _os.open(file, flags, 0600) OSError: [Errno 13] Permission denied: '/mnt/dietpi_userdata/mopidy/dat /local/library.json.gz.fSFK1W'

It looks like a permission problem, but I can’t understand what I need to change (also it looks strange to me, since mopidy is running as root).
Any suggestion appreciated. Thanks.

That traceback is bizarrely missing random characters, which makes it harder to read than it should be.

Did you check if the root user actually has write permission in '/mnt/dietpi_userdata/mopidy/data/local/ (I am assuming that’s the path and the ‘a’ character is just missing for some reason)? Is there a reason you are running Mopidy as root?

Sorry, I’m posting from my phone, maybe that’s the problem.
Mopidy runs as root because this is how DietPi works, basically.

Here are the permissions of the folder:

root@OPiHome:~# l /mnt/dietpi_userdata/mopidy/data/
total 12
drwxrwxr-x 3 root root 4096 Mar 15 20:03 deezer
drwxrwxr-x 2 root root 4096 Aug  7 19:06 local
drwxrwxr-x 2 root root 4096 Mar 15 18:33 local-images

Here is a reposting of the error, let’s see if it works:

ERROR    [Errno 13] Permission denied: '/mnt/dietpi_userdata/mopidy/data/local/library.json.gz.fSFK1W'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mopidy/__main__.py", line 134, in main
    return args.command.run(args, proxied_config)
  File "/usr/lib/python2.7/dist-packages/mopidy/local/commands.py", line 167, in run
    library.close()
  File "/usr/lib/python2.7/dist-packages/mopidy/local/json.py", line 17, in close
    'tracks': self._tracks.values()
  File "/usr/lib/python2.7/dist-packages/mopidy/internal/storage.py", line 51, in dump
    prefix=basename + '.', dir=directory, delete=False)
  File "/usr/lib/python2.7/tempfile.py", line 462, in NamedTemporaryFile    (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
  File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 13] Permission denied: '/mnt/dietpi_userdata/mopidy/data/local/library.json.gz.fSFK1W'
Traceback (most recent call last):
  File "/usr/bin/mopidy", line 9, in <module>
    load_entry_point('Mopidy==2.1.0', 'console_scripts', 'mopidy')()
  File "/usr/lib/python2.7/dist-packages/mopidy/__main__.py", line 134, in main
    return args.command.run(args, proxied_config)
  File "/usr/lib/python2.7/dist-packages/mopidy/local/commands.py", line 167, in run
    library.close()
  File "/usr/lib/python2.7/dist-packages/mopidy/local/json.py", line 17, in close
    'tracks': self._tracks.values()
  File "/usr/lib/python2.7/dist-packages/mopidy/internal/storage.py", line 51, in dump
    prefix=basename + '.', dir=directory, delete=False)
  File "/usr/lib/python2.7/tempfile.py", line 462, in NamedTemporaryFile    (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
  File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 13] Permission denied: '/mnt/dietpi_userdata/mopidy/data/local/library.json.gz.fSFK1W'

Thanks

Are you 100% sure Mopidy is running as root? The permission for a user other than root doesn’t include write so that would explain what we are seeing here. Can you just confirm that /usr/sbin/mopidyctl has DAEMON_USER="root"?

Your phone seems to skipping the late character when the line is wrapping. I edited your post to put them back in, I hope you don’t mind but it’s easier to see what’s going on like this.

I’ve had a quick look at https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-software and I can’t see where they change the mopidyctl user to be root. Looks to me like it’s still using the mopidy user which does not have write permission in that directory. I suggest you fix /usr/sbin/mopidyctl and file the bug with them. It would probably make sense to remove the mopidy user from the system to avoid problems like this.

You are right, it actually reports:

DAEMON_USER=“mopidy”

I still don’t understand why it’s been working for months, though.
By fixing the file you mean to modify it to

DAEMON_USER=“root”

or have I misunderstood?

I’ve already contacted DietPi about this issue to warn them about this bug.
Thanks for your help.

I tried with

DAEMON_USER=“root”

and it worked.
Thank you very much.

Yep.

Perhaps while you’ve got their attention you can ask them what they are trying to do with this config:
https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-software#L8480-L8483*

if they want to use local-images then they don’t want line 8483. And they arguably want to be installing and using local-sqlite since it’s far superior to the json library.

I will pass this information along to the DietPi folks. Thanks!