#!/sbin/openrc-run

name="Music Player Daemon"
description="A daemon for playing music"

# M_USER and M_GROUP is for backward compatibility (Alpine <3.17)
: ${command_user:="${M_USER:-mpd}:${M_GROUP:-audio}"}

command=/usr/bin/mpd
# MPD_OPTS is for backward compatibility (Alpine <3.17)
command_args="${command_args:-$MPD_OPTS}"
command_args_foreground="--no-daemon"

# Allow mpd to configure real-time scheduling.
# See https://www.musicpd.org/doc/html/user.html#real-time-scheduling.
# (This is supported since OpenRC 0.45)
capabilities="^cap_sys_nice"

depend() {
	need localmount
	use net netmount nfsmount esound pulseaudio
	after firewall
} 

start_pre() {
	checkpath --directory --quiet \
		--owner "${command_user%:*}" --mode 0775 /run/mpd
}
