aboutsummaryrefslogtreecommitdiffstats
path: root/main/mpd/mpd.initd
blob: 4d279da902ce141aacf368f912e266239c6ca377 (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
#!/sbin/openrc-run

# init.d file for music player daemon

NAME=mpd
DAEMON=/usr/bin/$NAME
CONF=/etc/mpd.conf

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

checkconfig() {
	[ -f "$CONF" ] && return 0
	eerror "configuration file $CONF is missing"
	return 1
}

get_pidfile() {
	pidfile=$(awk '$1 == "pid_file" { print $2 }' "$CONF" | sed 's/"//')
	pidfile=${pidfile:-/var/run/mpd/$NAME.pid}
}

start() {
	checkconfig || return 1
	get_pidfile
	checkpath --owner ${M_USER:-mpd}:${M_GROUP:-audio} \
		--directory ${pidfile%/*}

	ebegin "Starting ${NAME}"
		start-stop-daemon --start --quiet \
			--exec ${DAEMON} -- ${MPD_OPTS}
	eend $?
}

stop() {
	get_pidfile
	ebegin "Stopping ${NAME}"
		mpd --kill
	eend $?
}

start_pre() {
	checkpath --directory --owner ${M_USER:-mpd} \
		--mode 0775 /var/run/$NAME"
}