How to run systemctl service as user

1

I'm trying to get mpd running as a server. When I ncpmpc, I see no songs. This is probably because mpd does not have access to my music folder.

Here is my folder:

drwxrwxrwx  4 pi            pi                4096 Jun  2 01:23 Music

Here is some of it's content

-rwxrwxrwx 1 pi            pi            10624841 Jun  2 01:23 Coldplay - Adventure Of A Lifetime .mp3
drwxr-xr-x 2 pi            pi                4096 Jun  2 01:19 Coldplay - The Best Songs (2016)

Mpd is running as a service, I have tried running sudo mpd but then I get this error

socket: Failed to bind to '0.0.0.0:6600': Address already in use

I'm thinking it's because mpd is already running. I also tried this, to stop it:

sudo systemctl stop mpd

but get this, so maybe that's what stopping sudo mpd from running.

Warning: Stopping mpd.service, but it can still be activated by:
  mpd.socket

This is all a bit confusing for me. I would prefer to run mpd as a service, but don't know what the permissions has to be for that to work. And how to set them up.

Kristoffer Nolgren

Posted 2017-06-03T09:16:07.180

Reputation: 111

Answers

1

What you can do is to make it into a "user service" by creating an mpd.service in ~/.local/share/systemd/user/ and you can enable and start the service by running the following commands without root:

$ systemctl --user enable mpd.service
$ systemctl --user start mpd.service

The service will start running as your user.

yuki_is_bored

Posted 2017-06-03T09:16:07.180

Reputation: 56

What user should I use then? The same as the owner of the files? Pi in this case? – Kristoffer Nolgren – 2017-06-03T10:53:30.180

Also, can I just create ./local and it's subfolders if they are not there? – Kristoffer Nolgren – 2017-06-03T10:59:25.917

1~/.local not ~/local. In case you're not aware, ~ means your home folder which is /home/<username> or /home/pi in this case. – yuki_is_bored – 2017-06-03T11:19:34.733

yeah, sorry, I meant /.local (/home/pi/local), it's not there, tried cd .local and ls -a, only folder is .ssh. – Kristoffer Nolgren – 2017-06-03T11:22:25.320

Yeah, just create it if it doesn't exist. – yuki_is_bored – 2017-06-03T11:37:05.893

okay and what should the content mpd.service look like? Also I tried setting the ueser to mpd for the music folder, sudo chown -R mpd Music, didn't work though. – Kristoffer Nolgren – 2017-06-03T13:26:23.187