__mpd_host="${MPD_HOST:-mpd.$(dnsdomainname)}"
__mpd_port="${MPD_PORT:-6600}"
[ "$__mpd_host" != 'mpd.' ] || return 0

__mpd_ssh_command='ssh'
if [ "$(command -v autossh)" ]
then
  __mpd_ssh_command='autossh -M 0'
fi
__mpd_ssh_arguments="-N -L localhost:6600:localhost:$__mpd_port $__mpd_host"

if ! pgrep -f "/$__mpd_ssh_command *$__mpd_ssh_arguments$" > '/dev/null'
then
  $__mpd_ssh_command -f $__mpd_ssh_arguments
fi