How to run systemctl service as user

9,897

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.

Share:
9,897

Related videos on Youtube

Kristoffer Nolgren
Author by

Kristoffer Nolgren

Just some random dude....

Updated on September 18, 2022

Comments

  • Kristoffer Nolgren
    Kristoffer Nolgren 3 months

    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
    Kristoffer Nolgren over 5 years
    What user should I use then? The same as the owner of the files? Pi in this case?
  • Kristoffer Nolgren
    Kristoffer Nolgren over 5 years
    Also, can I just create ./local and it's subfolders if they are not there?
  • yuki_is_bored over 5 years
    ~/.local not ~/local. In case you're not aware, ~ means your home folder which is /home/<username> or /home/pi in this case.
  • Kristoffer Nolgren
    Kristoffer Nolgren over 5 years
    yeah, sorry, I meant /.local (/home/pi/local), it's not there, tried cd .local and ls -a, only folder is .ssh.
  • yuki_is_bored over 5 years
    Yeah, just create it if it doesn't exist.
  • Kristoffer Nolgren
    Kristoffer Nolgren over 5 years
    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.