Changed Daemon User in /etc/init.d/mopidy But Still Running As Mopidy

I am trying to change Mopidy to run as root when it is ran as a service.

I have edited /etc/init.d/mopidy to have: DAEMON_USER=root
however when I run Mopidy either by restarting or doing whole dance of:
sudo service mopidy stop
sudo service mopidy start

Mopidy still starts with the mopidy user.
Which I can tell by doing: ps aux | grep -i mopidy
mopidy 10409 41.4 7.6 256864 72604 ? Ssl 17:17 0:14 /usr/bin/python /usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf

What operating system are you using?

I’m guessing that you’re on a Debian based system that is now running systemd, not sysvinit. Thus /etc/init.d/mopidy is unused because /lib/systemd/system/mopidy.service is used instead.

If I’m right, don’t change the file in /lib/systemd/... but create a new empty file in /etc/systemd/... with the same name. In it, you can override the parts of the /lib/systemd/... file you want, while still get the future improvements to the systemd service file when you upgrade the mopidy package.

I think something like this in /etc/systemd/system/mopidy.service should work:

[Service]
User=root

I am running on a Raspberry Pi 2 running Raspbian Jessie.

I tried creating the file: /etc/systemd/system/mopidy.service like you suggested but it did’t work.

Sorry, I can’t help you based on “it didn’t work”.

I was figuring it was because of the OS, and giving my OS would be of more help.
When I created the file you said and then started up, nothing different happened.
It does work if I modify /lib/systemd/system/mopidy.service but to your point the ideal way would be to not edit that file.
Unfortunately I am not sure what more I can say then it simply didn’t work.

Try running sudo systemctl status mopidy.

With the /etc/systemd/system/mopidy.service file running sudo systemctl status mopidy gives me:

● mopidy.service
Loaded: error (Reason: Invalid argument)
Active: inactive (dead) since Tue 2016-02-09 05:40:23 MST; 37min ago
Main PID: 5281 (code=killed, signal=HUP)

Feb 09 06:17:26 musicbox systemd[1]: mopidy.service lacks ExecStart setting. Refusing.

The contents of the file are:
[Service]
User=root

I added that exec line from the main file, did a reload and its working!

Thanks all!

It didn’t work the first time because @jodal was trying to define a systemd ‘Drop-in snippet’ where you only override the specific settings you want to change and leave everything untouched. The benefit of this being that if/when there is a new version of Mopidy released which requires a different ExecStart setting then you’ll get this change automatically.

For a ‘Drop-in snippet’ to work it seems you actually need to create the file /etc/systemd/system/mopidy.service.d/my-override.conf. What you’ve done now will work, but in theory it may become a problem in the future.