Problem with running Mopidy as Service in chroot [Solved]

Hi

Im sorry for first posting in the issue thread at github, last time I asked for some support I got a reply of someone with same issue at github, so it was a bit confusing for me on which to use for support. Here is my question again.

I’m using mopidy for playing music from spotify and using a web extension to control it. I’m using a Synology NAS and got a debian chroot with debootstrap. Everything works flawless with the setup when I run it directly, but when setting it up as a service it wont play any music for me. I get this error in the log;

2015-05-26 10:13:08,167 ERROR [16284:MainThread] mopidy.audio.gst: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure

Can there be some permission problems somehow?

Here is my config:

[logging]
config_file = /etc/mopidy/logging.conf
debug_file = /var/log/mopidy/mopidy-debug.log

[local]
enabled = false

[m3u]
enabled = false

[mpd]
enabled = false

[stream]
enabled = false

[http]
enabled = true
hostname = ::
port = 6680

[spotify]
enabled = true
username = ******
password = ******
bitrate = 320
toplist_countries = SE

Hi again.

Don’t worry, it’s a relatively new policy.

I’ve just realised it was in fact you that had recently posted here about
running with chroot. Can you confirm if you are using pulseaudio? When
running as a service it runs under user mopidy, some people find permission
issues with that and pulseaudio. Have you tried running Mopidy in your
shell (i.e. not a service) as user mopidy?
npull https://discourse.mopidy.com/users/npull
May 26

Hi

Im sorry for first posting in the issue thread at github, last time I
asked for some support I got a reply of someone with same issue at github,
so it was a bit confusing for me on which to use for support. Here is my
question again.

I’m using mopidy for playing music from spotify and using a web extension
to control it. I’m using a Synology NAS and got a debian chroot with
debootstrap. Everything works flawless with the setup when I run it
directly, but when setting it up as a service it wont play any music for
me. I get this error in the log;

Yes that was me. =)

No I dont use pulseaudio, but uses the alsa library.

Running mopidy in “normal” mode with mopidy user gives me same error once I try play a song, with some more clues. It’s fairly safe to assume it has something to do with permissions (running with root user works just fine). Can mopidy run as service with the root user somehow? Or do you have any suggestion of how I should address this?

shm_open() failed: Permission denied
shm_open() failed: Permission denied
AL lib: alsa_open_playback: Could not open playback device 'default': No such file or directory
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
ERROR    GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.

I am guessing that mopidy is only a user of my chroot environment, while access to system hardware is granted by mouting /dev/, /sys/, /proc/ into it, where only root user have access to. Maybe I need to add mopidy user in the NAS primary environment and grant access somehow? I’m not so good at linux user setups…

I had to admit I’ve never played around with chroot but presumably /dev/shm should be world writeable

hm, here is permission for /dev/shm, looks like its not writable to any but root.

drwxr-xr-x 2 root root        40 May 26 14:06 shm

Outside the chroot its universally writable;

drwxrwxrwt    2 root     root            60 May 26 11:28 shm

Perhaps the way I mount /dev/ into the chroot environment makes it only writable for the root user.

I solved it by changing the daemon mopidy is running as to root. In /etc/init.d/mopidy I changed to;

DAEMON_USER=root
DAEMON_GROUP=root

Now everything works well =)
only the same old Warning message Ive got all along… (What is that btw?)

2015-05-26 14:15:27,223 WARNING [10125:MainThread] mopidy.audio.gst: Element doesn't implement handling of this stream. Please file a bug.

Edit: Here was some discussion why its not good/possible to run services with non-root users in chroot; http://serverfault.com/questions/135599/ubuntu-can-non-root-user-run-process-in-chroot-jail

I don’t believe that’s the correct conclusion to take away from that serverfault link. It should be perfectly acceptable (and is usually the entire point) to run a process with non-root permission in a chroot. The question you linked is specifically if a non-root user can chroot a process and the answer is no, as you must have root privilege to do chroot. And you shouldn’t have that problem since Mopidy’s init script (like all daemon init scripts) is run as root. It depends exactly how you were doing it but perhaps Best Practices for UNIX chroot() Operations is helpful

There are quite a few interesting looking google results for ‘shm chroot’ and I’d guess a better solution lies there rather than running Mopidy as root.

Oh yea, you are ofc correct, had a bit of a brainfart there. And there might be a better solution for this, but I fear the problem won’t end with just getting correct access to /dev/shm. I am content with the solution of running the service as root.

Any idea what that warning message is about?

Perhaps you’re missing a gstreamer plugin? Is it preventing you from
playing things?

No everything works fine. Things play without a hitch. I mostly was just curious what that warning was about, it says I should file a bug, =P

That message is from gstreamer itself rather than Mopidy. We use
gstreamer0.10 which is no longer maintained so you could file a bug…but
it probably won’t go anywhere. Gstreamer1.0 is on the Mopidy road map.

Hi all,

sorry for necroposting but before opening a new tread I was wondering if you share a guide to set up mopidy running on Synology Nas.

Moreover you’re using a usb sound card on it?

Thank you in advance

It was a long time ago now. I used it on my synology for about 2 years, was working relatively well. Had to restart it every once in a while (didn’t always restart itself after DSM updates). Now I got an amp with spotify installed so I don’t use mopidy anymore (I only used mopidy for spotify).

Since Gstreamer and a bunch of other required libraries are not installed on the distro that runs DSM you have to install a new debian distro along side the synology distro via chroot.

Here is a guide on how to do that;
http://www.rooot.net/en/geek-stuff/synology/39-chroot-debian-synology-debootstrap.html

But i think these days there is a package you can install from the DSM, in the community section of the package manager to install debian. Never tried this though.

Once you got debian installed its rather straight forward to install mopidy as service with apt-get, and there should be guides on that here i suppose.

To start and stop the service I created tasks in DSM. In the control panel and schedule tasks, you can create tasks that you run manually that are not scheduled. The commands i used was;

chroot /volume1/synodebian/ /etc/init.d/mopidy start
chroot /volume1/synodebian/ /etc/init.d/mopidy stop

Hope this helps you.

Yes, you’re right.

I installed chroot using a package made by synocommunity.

I have problem for setting pulseaudio for newtork streaming :frowning:

I used a USB audio card connected to the NAS, and got it to work with Alsa library. You can check if the audio card works by setting up and play music via the Audio station in DSM.

perhaps try;
sudo apt-get install alsa-utils

if its not installed on your debian yet, and maybe fiddle with the mopidy config a bit. I don’t really remember every step I took, I remember experiment a lot before it started working.