summaryrefslogtreecommitdiff
path: root/media-sound/mpd/files/mpd-0.23.15.init
blob: 8a0a18af9b215df4eec6648b9d545f0fad541be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/sbin/openrc-run
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

: CFGFILE=${CFGFILE:=/etc/mpd.conf}

depend() {
	need localmount
	use net netmount alsasound esound pulseaudio
	config ${CFGFILE}
}

get_config() {
	x=$1
	test -e ${CFGFILE} || return 1
	sed -n \
		-e '/^[ \t]*'${x}'/{s:^[ \t]*'${x}'[ \t]\+"\?\([^#"]\+\)[^"]*"\?$:\1: ; p }' \
		${CFGFILE}
}

extra_started_commands='reload'
# Required by io_uring
rc_ulimit="-l 65535"
command=/usr/bin/mpd
command_args=${CFGFILE}
mpd_user="$(get_config user)"
mpd_group="$(get_config group)"
required_files=${CFGFILE}
pidfile=$(get_config pid_file)
description="Music Player Daemon"

check_config() {
	if [ -z "$(get_config pid_file)" ]; then
		die "pid_file must be set in ${CFGFILE}!"
	fi
	if [ -z "$(get_config user)" ]; then
		die "user must be set in ${CFGFILE}!"
	fi
	if [ -z "$(get_config group)" ]; then
		die "group must be set in ${CFGFILE}!"
	fi
}

start_pre() {
	check_config
	
	local pid_dir="$(dirname "${pidfile}")"
	checkpath -d -m 700 -o "${mpd_user}:${mpd_group}" "${pid_dir}"

	local log_file="$(get_config log_file)"
	if [ -n "${log_file}" ]; then
		local log_dir="$(dirname "${log_file}")"
		checkpath -d -m 755 -o "${mpd_user}:${mpd_group}" "${log_dir}"
	fi
}

reload() {
	ebegin "Reloading ${RC_SVCNAME}"
	start-stop-daemon --pidfile ${pidfile} --signal HUP
	eend $?
}