Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DietPi-Software | MPD: Can't find conf file after upgrade from 6.10 --> 6.19 #2378

Closed
mfeif opened this issue Dec 29, 2018 · 7 comments
Closed
Labels
Milestone

Comments

@mfeif
Copy link

mfeif commented Dec 29, 2018

Creating a bug report/issue:

MPD can no longer start, because it can't find its conf file:

#mpd
exception: No configuration file found

/etc/mpd.conf is in place
/lib/systemd/system/mpd.service has some conflicting info. Note that it's forcing the binary to see /etc/mpd.conf but ALSO is telling it to look in /etc/default/mpd (which has its own configuration about where to put the conf file). Also, I think that those directories in /var/run/mpd maybe shouldn't be messed with every time... since the service here claims that mpd will change its user in a fork, but the chown might wreck that.

[Unit]
Description=Music Player Daemon
After=network.target sound.target

[Service]
#User=root #forks its own process under user set in /etc/mpd.conf (mpd)
Type=simple
LimitRTPRIO=infinity
RuntimeDirectory=/var/run/mpd
EnvironmentFile=/etc/default/mpd
ExecStartPre=/bin/mkdir -p /var/run/mpd
ExecStartPre=/bin/chown -R root:dietpi /var/run/mpd
ExecStart=/usr/local/bin/mpd --no-daemon /etc/mpd.conf

[Install]
WantedBy=multi-user.target

Here's /etc/default/mpd:

#Even though we declare the conf location in our service, MPD will fail to start if this file does not exist.
## The configuration file location for mpd:
MPDCONF=/etc/mpd.conf

But anyway, if you ignore the systemctl version and just try and run it, it still doesn't work:

# /usr/local/bin/mpd
exception: No configuration file found

Required Information:

  • DietPi version
#!/bin/bash
G_DIETPI_VERSION_CORE=6
G_DIETPI_VERSION_SUB=19
G_DIETPI_VERSION_RC=7
G_GITBRANCH=master
G_GITOWNER=Fourdee
  • Distro version | 9.6
  • Kernel version | Linux PiFi 3.10.38 #22 SMP PREEMPT Fri Dec 22 10:45:41 IST 2017 armv7l GNU/Linux
  • SBC device | Sparky SBC (armv7l)

Additional Information (if applicable):

  • Software title | (EG: MPD)
  • Was the software title installed freshly or updated/migrated? updated
  • Can this issue be replicated on a fresh installation of DietPi? Unknown; fresh update.

Steps to reproduce:

See above.

Extra details:

So there are some weird things going on. First, if one forces mpd to use /etc/mpd.conf it DOES find it. If you just run it, it doesn't, though the file is there, and so on.

@MichaIng
Copy link
Owner

MichaIng commented Dec 29, 2018

@mfeif
Thanks for your report.

/lib/systemd/system/mpd.service has some conflicting info. Note that it's forcing the binary to see /etc/mpd.conf but ALSO is telling it to look in /etc/default/mpd (which has its own configuration about where to put the conf file).

Jep indeed this is somehow confusing. However the comment in /etc/default/mpd states that it is meant to be like that. I will just retry if really the environment file is required, if EnvironmentFile=/etc/default/mpd is removed from systemd unit as well.


Also, I think that those directories in /var/run/mpd maybe shouldn't be messed with every time... since the service here claims that mpd will change its user in a fork, but the chown might wreck that.

This is only a failsafe thing and should not break anything, since only group is changed. Actually all this should be not required. PID files and runtime dirs are created automatically by systemd and since the service runs as root, there should be no access issues at all. Even if sub processes spawn as different users, those should not require access to the runtime dir.

Perhaps I find some time to clean the above up, however as I am not sure about the reasons and done testing, there might be reasons for it, so intense testing is required which take much time. And since it should not cause any issues...


# /usr/local/bin/mpd
exception: No configuration file found

Note that the configuration file is a non optional argument of the mpd command:
€: Ah it's not, working without given config file on default Debian repo install!

root@VM-Stretch:~# mpd --help
Usage:
  mpd [OPTION...] [path/to/mpd.conf]

Music Player Daemon - a daemon for playing music.

Options:
  -h, --help        show help options
  --kill            kill the currently running mpd session
  --no-config       don't read from config
  --no-daemon       don't detach from console
  --stderr          print messages to stderr
  -v, --verbose     verbose logging
  -V, --version     print version number
  • Try to use /usr/local/bin/mpd /etc/mpd.conf instead or simply: mpd /etc/mpd.conf

@MichaIng
Copy link
Owner

MichaIng commented Dec 29, 2018

Actually no issue here with removing /etc/default/mpd and EnvironmentFile= in systemd unit.

It is possible to use the default Stretch systemd unit with additional hardenings, only binary needs to be adjusted to /usr/local/bin:

[Unit]
Description=Music Player Daemon
After=network.target sound.target

[Service]
EnvironmentFile=/etc/default/mpd
ExecStart=/usr/local/bin/mpd --no-daemon $MPDCONF

# allow MPD to use real-time priority 50
LimitRTPRIO=50
LimitRTTIME=infinity

# disallow writing to /usr, /bin, /sbin, ...
ProtectSystem=yes

# more paranoid security settings
NoNewPrivileges=yes
ProtectKernelTunables=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
# AF_NETLINK is required by libsmbclient, or it will exit() .. *sigh*
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
RestrictNamespaces=yes

[Install]
WantedBy=multi-user.target
Also=mpd.socket

Ah and RuntimeDirectory NEEDS to be pre-created and chowned to run user defined in /etc/mpd.conf. The default Debian repo install creates it with mpd:audio owner. However on DietPi it would be good, if mpd could access files within /mnt/dietpi_userdata so should be in dietpi group. And to be failsafe it makes sense to pre-create and chown the runtime dir with this just on service start.


Only thing:

  • For security reasons it actually makes sense to not run mpd as root user.
    @Fourdee do you remember why we still run it as root?

Testing above config file on Jessie:

Dec 29 22:22:03 VM-Jessie systemd[1]: [/lib/systemd/system/mpd.service:21] Unknown lvalue 'ProtectKernelTunables' in section 'Service'
Dec 29 22:22:03 VM-Jessie systemd[1]: [/lib/systemd/system/mpd.service:22] Unknown lvalue 'ProtectControlGroups' in section 'Service'
Dec 29 22:22:03 VM-Jessie systemd[1]: [/lib/systemd/system/mpd.service:23] Unknown lvalue 'ProtectKernelModules' in section 'Service'
Dec 29 22:22:03 VM-Jessie systemd[1]: [/lib/systemd/system/mpd.service:26] Unknown lvalue 'RestrictNamespaces' in section 'Service'
Dec 29 22:22:05 VM-Jessie systemd[1]: Starting Music Player Daemon...
Dec 29 22:22:06 VM-Jessie systemd[1]: Started Music Player Daemon.
  • However unsupported values are just ignored, so we could even ignore it.

@MichaIng
Copy link
Owner

I opened a PR to address the above: https://github.com/Fourdee/DietPi/pull/2381

I have not yet a clue, why on default Debian package install, the "mpd" command finds the config file automatically and when our manually compiled package is installed, it does not.
Perhaps this is also something that can be set/changed when compiling?

@MichaIng MichaIng changed the title MPD can't find conf file after upgrade from 6.10 --> 6.19 DietPi-Software | MPD: Can't find conf file after upgrade from 6.10 --> 6.19 Dec 30, 2018
@Fourdee
Copy link
Collaborator

Fourdee commented Dec 31, 2018

@MichaIng

@MichaIng
Copy link
Owner

@Fourdee
Jep, I also found that. However dietpi group should be now sufficient since we mount samba drives as dietpi group now with 77X permissions?

mount -t cifs -o username="$samba_clientuser",password="$samba_clientpassword",uid=dietpi,gid=dietpi,file_mode=0770,dir_mode=0770...

@MichaIng
Copy link
Owner

MichaIng commented Jan 3, 2019

@mfeif @Fourdee
I found the reason for the file-not-found error:

  • Since our mpd on Jessie is a custom build, it is installed to /usr/local/bin and from there by default looks into /usr/local/etc/mpd.conf instead of /etc/mpd.conf.
  • This is not documented and since it by default looks into several locations for mpd.conf one could call it design issue, that /etc is skipped for custom builds:

mpd.conf is the configuration file for mpd(1). If not specified on the command line, MPD first searches for it at $XDG_CONFIG_HOME/mpd/mpd.conf then at ~/.mpdconf then at ~/.mpd/mpd.conf and then in /etc/mpd.conf.

To resolve:

mkdir -p /usr/local/etc
ln -sf /etc/mpd.conf /usr/local/etc/mpd.conf

Fixed with: Fourdee@10efc06
Changelog: Fourdee@ac7c477

@mfeif
Copy link
Author

mfeif commented Jan 21, 2019

Nice work guys! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants