# Problem with running Mopidy as Service in chroot \[Solved\]

**URL:** <https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744>\
**Category:** Misc\
**Created:** [May 26, 2015, 7:40am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744 "2015-05-26T07:40:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [May 26, 2015, 7:40am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/1 "2015-05-26T07:40:57Z")

</div>

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;

```auto
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:

```auto
[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

```

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [May 26, 2015, 8:14am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/2 "2015-05-26T08:14:13Z")

</div>

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](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;

---

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [May 26, 2015, 8:44am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/3 "2015-05-26T08:44:37Z")

</div>

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?

```auto
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…

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [May 26, 2015, 9:48am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/4 "2015-05-26T09:48:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [May 26, 2015, 11:17am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/5 "2015-05-26T11:17:59Z")

</div>

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

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

```

Outside the chroot its universally writable;

```auto
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;

```auto
DAEMON_USER=root
DAEMON_GROUP=root

```

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

```auto
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](http://serverfault.com/questions/135599/ubuntu-can-non-root-user-run-process-in-chroot-jail)

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [May 26, 2015, 2:30pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/6 "2015-05-26T14:30:29Z")

</div>

> [@npull](#):
>
> Edit: Here was some discussion why its not good/possible to run services with non-root users in chroot; [Ubuntu - can non-root user run process in chroot jail? - Server Fault](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](http://www.unixwiz.net/techtips/chroot-practices.html) 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.

---

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [May 26, 2015, 7:33pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/7 "2015-05-26T19:33:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [May 26, 2015, 7:51pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/8 "2015-05-26T19:51:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [May 26, 2015, 8:34pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/9 "2015-05-26T20:34:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [May 26, 2015, 8:55pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/10 "2015-05-26T20:55:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jokerigno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jokerigno/32/701_2.png) [@jokerigno](https://discourse.mopidy.com/u/jokerigno)\
**Post date:** [December 12, 2017, 10:03am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/11 "2017-12-12T10:03:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [December 12, 2017, 1:32pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/12 "2017-12-12T13:32:15Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![jokerigno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jokerigno/32/701_2.png) [@jokerigno](https://discourse.mopidy.com/u/jokerigno)\
**Post date:** [December 12, 2017, 4:34pm UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/13 "2017-12-12T16:34:58Z")

</div>

Yes, you’re right.

I installed chroot using a package made by synocommunity.

I have problem for setting pulseaudio for newtork streaming ☹

---

<div class="post-metadata">

**Author:** ![npull](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/npull/32/179_2.png) [@npull](https://discourse.mopidy.com/u/npull)\
**Post date:** [December 13, 2017, 7:40am UTC](https://discourse.mopidy.com/t/problem-with-running-mopidy-as-service-in-chroot-solved/744/14 "2017-12-13T07:40:44Z")

</div>

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.
