Difference between revisions of "Music Player Daemon"

From ArchWiki
Jump to: navigation, search
(Fixed poor English)
(database =/= db)
(32 intermediate revisions by 16 users not shown)
Line 1: Line 1:
 
[[Category:Player]]
 
[[Category:Player]]
[[Category:Daemons and system services]]
 
 
[[de:Music Player Daemon]]
 
[[de:Music Player Daemon]]
 
[[es:Music Player Daemon]]
 
[[es:Music Player Daemon]]
Line 27: Line 26:
 
=== Stable version ===
 
=== Stable version ===
 
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].
 
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].
 +
 +
You may also want to install [https://github.com/GutenYe/systemd-units/tree/master/mpd mpd-systemd].
 +
 
=== Git version ===
 
=== Git version ===
 
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.
 
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.
Line 36: Line 38:
  
 
For a comfortable use, it is sensible to provide MPD access to the following files and directories:
 
For a comfortable use, it is sensible to provide MPD access to the following files and directories:
mpd.db   # The music database
+
* mpd.db - The music database
mpd.pid   # The file where mpd stores its process ID
+
* mpd.pid The file where mpd stores its process ID
mpd.log   # mpd logs here
+
* mpd.log - mpd logs here
mpdstate # mpd's current state is noted here
+
* mpdstate - mpd's current state is noted here
playlists # the folder where playlists are saved into
+
* playlists - the folder where playlists are saved into
  
 
In order for MPD to be able to play back audio, [[ALSA]], [[PulseAudio]] or [[OSS]] needs to be setup and working.
 
In order for MPD to be able to play back audio, [[ALSA]], [[PulseAudio]] or [[OSS]] needs to be setup and working.
 +
 +
=== Local Configuration (per user) ===
 +
MPD does not need to be run globally as a daemon and can rather work per user. The usual method to configure MPD globally is because the listed files and folders in the default configuration file point to directories owned by root (the {{ic|/var}} directory).
 +
 +
A less used (but perhaps more sensible) method is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:
 +
 +
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/username}}) that will contain all the MPD configuration files.
 +
* Easier to avoid unforeseen read/write permission errors.
 +
 +
{{Note|This approach will not work with multiple users to having access to MPD at the same time.}}
 +
 +
Begin the setup by creating a directory for the required files and the playlists:
 +
 +
{{bc|mkdir -p ~/.mpd/playlists}}
 +
 +
Copy the contents of the default MPD configuration file in {{ic|/usr/share/mpd/mpd.conf.example}} to the target user's home directory:
 +
 +
{{bc|cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf}}
 +
 +
Create all of the requisite files:
 +
 +
{{bc|<nowiki>touch ~/.mpd/{database,log,pid,state}</nowiki>}}
 +
 +
Edit {{ic|~/.mpdconf}} to specify these files:
 +
 +
{{hc|~/.mpdconf|
 +
music_directory    "/home/USER/music"            # Keep commented if your XDG directory already points to it
 +
playlist_directory "/home/USER/.mpd/playlists"
 +
db_file            "/home/USER/.mpd/database"
 +
log_file          "/home/USER/.mpd/log"
 +
pid_file          "/home/USER/.mpd/pid"
 +
state_file        "/home/USER/.mpd/state"
 +
}}
 +
 +
or you can use
 +
{{bc|sed "s/var\/lib\/mpd\/music/home\/$USER\/music/;
 +
    s/var\/lib\/mpd/home\/$USER\/.mpd/;
 +
    s/var\/run\/mpd/home\/$USER\/.mpd/;
 +
    s/var\/log\/mpd/home\/$USER\/.mpd/" /etc/mpd.conf > ~/.mpd/mpd.conf}}
 +
 +
MPD can now be started by typing {{ic|mpd}} on the command line.
 +
 +
To start MPD with the X server, add
 +
{{bc|mpd ~/.mpdconf}}
 +
to either [[xprofile]] or [[xinitrc]]
 +
 +
==== Start MPD per user with systemd ====
 +
 +
As recommended above, it is best to use MPD as a service per user. In this case, we will use {{ic|~/.mpd/mpd.conf}} and not start mpd.service as a daemon for the whole system and all users.
 +
We will NOT use the {{ic|/usr/lib/systemd/system/mpd.service}} which is intended to start the mpd.service as root and for all users.
 +
If you already enabled it, just disable it first:
 +
{{bc| # systemctl disable mpd.service}}
 +
 +
If you used to start mpd inside your {{ic|~/.xinitrc}}, comment or delete the line
 +
{{bc|mpd ~/.mpdconf}}
 +
 +
Then, edit a new file ~/.config/systemd/user/mpd.service
 +
{{hc|~/.config/systemd/user/mpd.service|
 +
[Unit]
 +
Description &#61; Music Player Daemon
 +
 +
[Service]
 +
ExecStart &#61; /usr/bin/mpd --no-daemon
 +
Restart &#61; always
 +
 +
[Install]
 +
WantedBy &#61; default.target
 +
}}
 +
 +
Then, add this line to [[xinitrc|.xinitrc]] before any exec <session-command>
 +
{{hc|~/.xinitrc|
 +
#run systemd as user instance
 +
systemd --user &
 +
}}
 +
 +
Log out, log in your xsession.
 +
Let's first check mpd is not running. If yes, just kill it. If not, continue to the next step.
 +
{{bc|$ ps -ef &#124; grep mpd}}
 +
 +
Now, enable and start mpd.service as per user
 +
$ systemctl --user enable mpd
 +
$ systemctl --user start mpd
 +
 +
Check the mpd status and see if mpd.service is correctly enabled and started
 +
{{bc|$ systemctl --user status mpd}}
 +
 +
==== Scripted Configuration ====
 +
Rasi has written a script that will create the proper directory structure, configuration files and prompt for the location of the user's Music directory; it can be downloaded [http://karif.server-speed.net/~carnager/mpdsetup.tar here].
  
 
=== Global Configuration ===
 
=== Global Configuration ===
Line 50: Line 140:
 
MPD comes with an example configuration file, available at {{ic|/usr/share/doc/mpd/mpdconf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values.
 
MPD comes with an example configuration file, available at {{ic|/usr/share/doc/mpd/mpdconf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values.
  
Normally,{{ic|/etc/mpd.conf}} have been created when installing mpd. If not, copy the included example file to {{ic|/etc/mpd.conf}}.
+
Normally,{{ic|/etc/mpd.conf}} is created when installing mpd. If not, copy the included example file to {{ic|/etc/mpd.conf}}.
 
  # cp /usr/share/doc/mpd/mpdconf.example /etc/mpd.conf
 
  # cp /usr/share/doc/mpd/mpdconf.example /etc/mpd.conf
  
Line 68: Line 158:
 
# port                  "6600"
 
# port                  "6600"
 
}}
 
}}
Now change permissions for mpd to write to {{ic|/var/log/mpd/mpd.log}}, otherwise mpd will returns an error when started. Best is to make the {{ic|/var/log/mpd/mpd.log}} belongs to mpd [[Users and Groups#Group management|user]].
+
Now change permissions for mpd to write to {{ic|/var/log/mpd/mpd.log}}, otherwise mpd will return an error when it is started. The best way is to make the {{ic|/var/log/mpd/mpd.log}} belong to the mpd [[Users and Groups#Group management|user]].
 
   # chown -R mpd /var/log/mpd   
 
   # chown -R mpd /var/log/mpd   
also, run this to create the /run/mpd dir:
+
Run this to create the /run/mpd dir:
   # systemd-tmpfiles --create
+
   # systemd-tmpfiles --create mpd.conf
To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:
+
To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:
  
 
{{hc|/etc/mpd.conf|
 
{{hc|/etc/mpd.conf|
Line 97: Line 187:
 
Changing the group that MPD runs as may result in errors like "output: Failed to open "My ALSA Device"" "[alsa]: Failed to open ALSA device "default": No such file or directory" "player_thread: problems opening audio device while playing "Song Name.mp3""
 
Changing the group that MPD runs as may result in errors like "output: Failed to open "My ALSA Device"" "[alsa]: Failed to open ALSA device "default": No such file or directory" "player_thread: problems opening audio device while playing "Song Name.mp3""
  
This is because by default MPD runs as member of '''audio''' group and the sound devices under {{Ic|/dev/snd/}} are owned by this group.
+
This is because by default MPD runs as member of '''audio''' group and the sound devices under {{Ic|/dev/snd/}} are owned by this group, so add user {{Ic|mpd}} to group {{Ic|audio}}.
 +
# gpasswd -a mpd audio
  
 
===== Music directory =====
 
===== Music directory =====
Line 105: Line 196:
 
  # echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab
 
  # echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab
 
  # mount -a
 
  # mount -a
  # rc.d restart mpd
+
  # systemctl restart mpd.service
See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]
+
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this forum thread.]
  
 
An additional solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.
 
An additional solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.
 
  # mkdir /var/lib/mpd/music
 
  # mkdir /var/lib/mpd/music
 
  # ln -s MUSIC_FOLDER /var/lib/mpd/music/
 
  # ln -s MUSIC_FOLDER /var/lib/mpd/music/
  # rc.d restart mpd
+
  # systemctl restart mpd.service
  
 
If the music collection is contained under multiple directories, create symbolic links under the main music directory in {{ic|/var/lib/mpd}}. Remember to set permissions accordingly on the directories being linked.
 
If the music collection is contained under multiple directories, create symbolic links under the main music directory in {{ic|/var/lib/mpd}}. Remember to set permissions accordingly on the directories being linked.
Line 122: Line 213:
 
  # touch /var/lib/mpd/{mpd.db,mpdstate}  
 
  # touch /var/lib/mpd/{mpd.db,mpdstate}  
  
Usually the init-script should properly create {{ic|/run/mpd/}} when starting. The deamon will use this directory to create {{ic|mpd.pid}} in it. However, when running mpd as a different user, requires an update to the tmpfiles.d: In {{ic|/usr/lib/tmpfiles.d/mpd.conf}}:
+
Usually the init-script should properly create {{ic|/run/mpd/}} when starting. The daemon will use this directory to create {{ic|mpd.pid}} in it. However, when running mpd as a different user, requires an update to the tmpfiles.d: copy {{ic|/usr/lib/tmpfiles.d/mpd.conf}} to {{ic|/etc/tmpfiles.d/mpd.conf}}:
 
Change:
 
Change:
 
  d /run/mpd 0755 mpd mpd
 
  d /run/mpd 0755 mpd mpd
Line 132: Line 223:
  
 
==== Create database ====
 
==== Create database ====
Creating the database is now accomplished via the update feature of the client, for example {{ic|mpc update}}.  
+
Creating the database is now accomplished via the update feature of the client, for example {{ic|mpc update}}. You'll need to install the mpc package for this. It is in the official repositories
 
{{Box RED | Note: | Creating the MPD database as root using {{ic|# mpd --create-db}} is deprecated.}}
 
{{Box RED | Note: | Creating the MPD database as root using {{ic|# mpd --create-db}} is deprecated.}}
  
Line 138: Line 229:
 
To depict when MPD drops its superuser privileges and assumes those of the user set in the configuration, the timeline of a normal MPD startup is listed here:
 
To depict when MPD drops its superuser privileges and assumes those of the user set in the configuration, the timeline of a normal MPD startup is listed here:
  
# MPD is started on boot by {{ic|/etc/rc.conf}}, by including it in the {{ic|DAEMONS}} array. (Or, this can be done manually each session by running {{ic|rc.d start mpd}} with root privileges).
+
# Since MPD is started as root by systemd, it first reads the {{ic|/etc/mpd.conf}} file.
# Since MPD is now started as root, it first reads the {{ic|/etc/mpd.conf}} file.
+
 
# MPD reads the user variable in the {{ic|/etc/mpd.conf}} file, and changes from root to this user.
 
# MPD reads the user variable in the {{ic|/etc/mpd.conf}} file, and changes from root to this user.
 
# MPD then reads the contents of the {{ic|/etc/mpd.conf}} file and configures itself accordingly.
 
# MPD then reads the contents of the {{ic|/etc/mpd.conf}} file and configures itself accordingly.
Line 146: Line 236:
 
This way, uses of {{ic|~}} in the configuration file point correctly to the home user's directory, and not root's directory.  
 
This way, uses of {{ic|~}} in the configuration file point correctly to the home user's directory, and not root's directory.  
 
It may be worthwhile to change all uses of {{ic|~}} to {{ic|/home/username}} to avoid any confusion over this aspect of MPD's behavior.
 
It may be worthwhile to change all uses of {{ic|~}} to {{ic|/home/username}} to avoid any confusion over this aspect of MPD's behavior.
 
=== Local Configuration (per user) ===
 
MPD does not need to be run globally as a daemon and can rather work per user. The usual method to configure MPD globally is because the listed files and folders in the default configuration file point to directories owned by root (the {{ic|/var}} directory).
 
 
A less used (but perhaps more sensible) method is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:
 
 
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/username}}) that will contain all the MPD configuration files.
 
* Easier to avoid unforeseen read/write permission errors.
 
 
{{Note|This approach will not work with multiple users to having access to MPD at the same time.}}
 
 
Begin the setup by creating a directory for the required files and the playlists:
 
 
{{bc|mkdir -p ~/.mpd/playlists}}
 
 
Copy the contents of the default MPD configuration file in {{ic|/usr/share/mpd/mpd.conf.example}} to the target user's home directory:
 
 
{{bc|cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf}}
 
 
Create all of the requisite files:
 
 
{{bc|<nowiki>touch ~/.mpd/{mpd.db,mpd.log,mpd.pid,mpdstate}</nowiki>}}
 
 
Edit {{ic|~/.mpdconf}} to specify these files:
 
 
{{hc|~/.mpdconf|
 
music_directory    "/home/USER/music"            # Keep commented if your XDG directory already points to it
 
playlist_directory "/home/USER/.mpd/playlists"
 
db_file            "/home/USER/.mpd/mpd.db"
 
log_file          "/home/USER/.mpd/mpd.log"
 
pid_file          "/home/USER/.mpd/mpd.pid"
 
state_file        "/home/USER/.mpd/mpdstate"
 
}}
 
 
MPD can now be started by typing {{ic|mpd}} on the command line.
 
 
To have MPD start with the X server add it to [[xprofile]].
 
 
==== Scripted Configuration ====
 
Rasi has written a script that will create the proper directory structure, configuration files and prompt for the location of the user's Music directory; it can be downloaded [http://karif.server-speed.net/~carnager/mpdsetup.tar here].
 
  
 
=== Multi-mpd setup ===
 
=== Multi-mpd setup ===
Line 198: Line 248:
 
*{{App|mpc|Simple KISS client. All basic functionality available|http://mpd.wikia.com/wiki/Client:Mpc|{{Pkg|mpc}}}}
 
*{{App|mpc|Simple KISS client. All basic functionality available|http://mpd.wikia.com/wiki/Client:Mpc|{{Pkg|mpc}}}}
 
*{{App|ncmpc|A NCurses client for mpd|http://mpd.wikia.com/wiki/Client:Ncmpc|{{Pkg|ncmpc}}}}
 
*{{App|ncmpc|A NCurses client for mpd|http://mpd.wikia.com/wiki/Client:Ncmpc|{{Pkg|ncmpc}}}}
*{{App|ncmpcpp|An almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)|http://unkart.ovh.org/ncmpcpp/|{{Pkg|ncmpcpp}}}}
+
*{{App|[[ncmpcpp]]|An almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)|http://unkart.ovh.org/ncmpcpp/|{{Pkg|ncmpcpp}}}}
 
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}
 
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}
 +
 
=== Graphical ===
 
=== Graphical ===
 
*{{App|Ario|A very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}
 
*{{App|Ario|A very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}

Revision as of 01:46, 26 December 2012

Summary help replacing me
Installation, configuration and basic troubleshooting of MPD.
Required software
Music Player Daemon
Related Articles
MPD/Tips and Tricks
MPD/Troubleshooting
Other sources
Wikipedia article

MPD (music player daemon) is an audio player that has a server-client architecture. It plays audio files, organizes playlists and maintains a music database all while using very few resources. In order to interface with it, a separate client is needed.

Installation

Stable version

The latest stable version of mpd is available in the official repositories.

You may also want to install mpd-systemd.

Git version

Should users wish to run an experimental version, the AUR offers several from which to choose. For example, mpd-gitAUR.

Setup

MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances. The way of setting up mpd depends on the way it is intended to be used. A local configuration may prove more useful on a desktop system than on a system that is used by several people simultaneously.

For a comfortable use, it is sensible to provide MPD access to the following files and directories:

  • mpd.db - The music database
  • mpd.pid - The file where mpd stores its process ID
  • mpd.log - mpd logs here
  • mpdstate - mpd's current state is noted here
  • playlists - the folder where playlists are saved into

In order for MPD to be able to play back audio, ALSA, PulseAudio or OSS needs to be setup and working.

Local Configuration (per user)

MPD does not need to be run globally as a daemon and can rather work per user. The usual method to configure MPD globally is because the listed files and folders in the default configuration file point to directories owned by root (the /var directory).

A less used (but perhaps more sensible) method is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:

  • A single directory ~/.mpd (or any other directory under /home/username) that will contain all the MPD configuration files.
  • Easier to avoid unforeseen read/write permission errors.
Note: This approach will not work with multiple users to having access to MPD at the same time.

Begin the setup by creating a directory for the required files and the playlists:

mkdir -p ~/.mpd/playlists

Copy the contents of the default MPD configuration file in /usr/share/mpd/mpd.conf.example to the target user's home directory:

cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf

Create all of the requisite files:

touch ~/.mpd/{database,log,pid,state}

Edit ~/.mpdconf to specify these files:

~/.mpdconf
music_directory    "/home/USER/music"            # Keep commented if your XDG directory already points to it
playlist_directory "/home/USER/.mpd/playlists"
db_file            "/home/USER/.mpd/database"
log_file           "/home/USER/.mpd/log"
pid_file           "/home/USER/.mpd/pid"
state_file         "/home/USER/.mpd/state"

or you can use

sed "s/var\/lib\/mpd\/music/home\/$USER\/music/;
     s/var\/lib\/mpd/home\/$USER\/.mpd/;
     s/var\/run\/mpd/home\/$USER\/.mpd/;
     s/var\/log\/mpd/home\/$USER\/.mpd/" /etc/mpd.conf > ~/.mpd/mpd.conf

MPD can now be started by typing mpd on the command line.

To start MPD with the X server, add

mpd ~/.mpdconf

to either xprofile or xinitrc

Start MPD per user with systemd

As recommended above, it is best to use MPD as a service per user. In this case, we will use ~/.mpd/mpd.conf and not start mpd.service as a daemon for the whole system and all users. We will NOT use the /usr/lib/systemd/system/mpd.service which is intended to start the mpd.service as root and for all users. If you already enabled it, just disable it first:

 # systemctl disable mpd.service

If you used to start mpd inside your ~/.xinitrc, comment or delete the line

mpd ~/.mpdconf

Then, edit a new file ~/.config/systemd/user/mpd.service

~/.config/systemd/user/mpd.service
[Unit]
Description = Music Player Daemon

[Service]
ExecStart = /usr/bin/mpd --no-daemon
Restart = always

[Install]
WantedBy = default.target

Then, add this line to .xinitrc before any exec <session-command>

~/.xinitrc
#run systemd as user instance
systemd --user &

Log out, log in your xsession. Let's first check mpd is not running. If yes, just kill it. If not, continue to the next step.

$ ps -ef | grep mpd

Now, enable and start mpd.service as per user

$ systemctl --user enable mpd
$ systemctl --user start mpd

Check the mpd status and see if mpd.service is correctly enabled and started

$ systemctl --user status mpd

Scripted Configuration

Rasi has written a script that will create the proper directory structure, configuration files and prompt for the location of the user's Music directory; it can be downloaded here.

Global Configuration

Note: For user-specific permissions, change the "user" line above to reflect one of the system users.
Warning: Users of PulseAudio with a local mpd have to implement a workaround in order to run mpd as its own user!

MPD comes with an example configuration file, available at /usr/share/doc/mpd/mpdconf.example. This file holds an abundance of information on MPD configuration, and holds default mixer values.

Normally,/etc/mpd.conf is created when installing mpd. If not, copy the included example file to /etc/mpd.conf.

# cp /usr/share/doc/mpd/mpdconf.example /etc/mpd.conf

Editing mpd.conf

The default Arch install keeps the setup in /var/lib/mpd and uses "mpd" as default user.

Edit /etc/mpd.conf to reflect as such:

/etc/mpd.conf
music_directory       "/home/user/music"
playlist_directory    "/var/lib/mpd/playlists"
db_file               "/var/lib/mpd/mpd.db"
log_file              "/var/log/mpd/mpd.log"
pid_file              "/run/mpd/mpd.pid"
state_file            "/var/lib/mpd/mpdstate"
user                  "mpd"
# bind_to_address       "127.0.0.1"
# port                  "6600"

Now change permissions for mpd to write to /var/log/mpd/mpd.log, otherwise mpd will return an error when it is started. The best way is to make the /var/log/mpd/mpd.log belong to the mpd user.

  # chown -R mpd /var/log/mpd   

Run this to create the /run/mpd dir:

  # systemd-tmpfiles --create mpd.conf

To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:

/etc/mpd.conf
mixer_type			"software"

Users of PulseAudio will need to make the following modification:

/etc/mpd.conf
audio_output {
        type                    "pulse"
        name                    "pulse audio"
}

Users of ALSA will want to have the following device definition, which allows software volume control in the MPD client to control the volume separately from other applications.

/etc/mpd.conf
audio_output {
        type            "alsa"
        name            "My Sound Card"
        mixer_type      "software"      # optional
}

Changing the group that MPD runs as may result in errors like "output: Failed to open "My ALSA Device"" "[alsa]: Failed to open ALSA device "default": No such file or directory" "player_thread: problems opening audio device while playing "Song Name.mp3""

This is because by default MPD runs as member of audio group and the sound devices under /dev/snd/ are owned by this group, so add user mpd to group audio.

# gpasswd -a mpd audio
Music directory

MPD needs to have +x permissions on all parent directories to the music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home directories to 1700 drwx------. Thus users will most likely need to remount the music directory under a directory that mpd has access to -- this only applies if running as the 'mpd' user.

# mkdir /var/lib/mpd/music
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab
# mount -a
# systemctl restart mpd.service

Also see this forum thread.

An additional solution would be to just create a symbolic link into /var/lib/mpd/music.

# mkdir /var/lib/mpd/music
# ln -s MUSIC_FOLDER /var/lib/mpd/music/
# systemctl restart mpd.service

If the music collection is contained under multiple directories, create symbolic links under the main music directory in /var/lib/mpd. Remember to set permissions accordingly on the directories being linked.

Creating the required files

Now, having finished configuring MPD, the files and directories for MPD to write in need to be created:

Create the directories and files specified in /etc/mpd.conf:

# mkdir -p /var/lib/mpd/playlists 
# touch /var/lib/mpd/{mpd.db,mpdstate} 

Usually the init-script should properly create /run/mpd/ when starting. The daemon will use this directory to create mpd.pid in it. However, when running mpd as a different user, requires an update to the tmpfiles.d: copy /usr/lib/tmpfiles.d/mpd.conf to /etc/tmpfiles.d/mpd.conf: Change:

d /run/mpd 0755 mpd mpd

to:

d /run/mpd 0755 username groupname

Change the file's permissions so that the daemon can modify them.

# chown -R mpd /var/lib/mpd

Create database

Creating the database is now accomplished via the update feature of the client, for example mpc update. You'll need to install the mpc package for this. It is in the official repositories

Note: Creating the MPD database as root using # mpd --create-db is deprecated.

Timeline of MPD startup

To depict when MPD drops its superuser privileges and assumes those of the user set in the configuration, the timeline of a normal MPD startup is listed here:

  1. Since MPD is started as root by systemd, it first reads the /etc/mpd.conf file.
  2. MPD reads the user variable in the /etc/mpd.conf file, and changes from root to this user.
  3. MPD then reads the contents of the /etc/mpd.conf file and configures itself accordingly.

Notice that MPD changes the running user from root to the one named in the /etc/mpd.conf file. This way, uses of ~ in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of ~ to /home/username to avoid any confusion over this aspect of MPD's behavior.

Multi-mpd setup

Useful if running an icecast server.

For a second MPD (e.g., with icecast output to share music over the network) using the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., /home/username/.mpd/config-icecast), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., mpd-icecast.log, mpd-icecast.error, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd would use the same music collection as the first one e.g., creating and editing a playlist under the first daemon would affect the second daemon as well. Users do not have to create the same playlists all over again for the second daemon. Call this second daemon the same way from ~/.xinitrc above. (Just be sure to have a different port number, so as to not conflict with the first mpd daemon).

Clients

A separate client is needed to control mpd. Popular options are:

Console

  • mpc — Simple KISS client. All basic functionality available
http://mpd.wikia.com/wiki/Client:Mpc || mpc
  • ncmpc — A NCurses client for mpd
http://mpd.wikia.com/wiki/Client:Ncmpc || ncmpc
  • ncmpcpp — An almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)
http://unkart.ovh.org/ncmpcpp/ || ncmpcpp
  • pms — Highly configurable and accessible ncurses client
http://pms.sourceforge.net/ || pmusAUR

Graphical

  • Ario — A very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox
http://ario-player.sourceforge.net/ || ario
  • QmpdClient — A GUI client written with Qt 4.x
http://bitcheese.net/wiki/QMPDClient || qmpdclient
  • Sonata — An elegant Python GTK+ client
http://sonata.berlios.de/ || sonata
  • gmpc — GNOME Client
http://gmpc.wikia.com/wiki/Gnome_Music_Player_Client || gmpc
  • Dmpc — Dmenu-based MPC client with a playlist manager and state-saving on playlist changes
http://wintervenom.mine.nu/ || dmpcAUR

Web

  • Patchfork — web client for MPD written in PHP and Ajax
http://mpd.wikia.com/wiki/Client:Pitchfork || patchfork-gitAUR.

See a long list of clients at the mpd wiki.

External links