aboutsummaryrefslogtreecommitdiff
blob: b8ca248b917a4e66e01c0833cfe5aca07832a6e3 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/sbin/runscript
# Distributed under the terms of the GNU General Public License v2
# $Id$

opts="${opts} watchdogrestart"

source /usr/share/vdr/inc/functions.sh
include rc-functions

depend() {
	use lircd net coldplug
	after checkroot
}

start() {
	INIT_PHASE=start
	cd /
	local exitcode

	init_vdr_start_log

	einfo "Preparing start of vdr:"
	init_params
	init_daemonctrl_params

	[[ -z "${VDR_BIN}" ]] && VDR_BIN=/usr/bin/vdr

	add_daemonctrl_param --start --chdir ~vdr --exec ${VDR_BIN}

	
	load_addons_prefixed pre-start || return 1

	ebegin "Starting ${VDRNAME}"

	#
	# finally start vdr
	# 
	unset MAIL

	vdr_home=/var/vdr

	export LOGNAME=vdr
	export USER=vdr
	export HOME=${vdr_home}

	cd ${vdr_home}

	einfo_level2 "  CMDLINE:" start-stop-daemon $(quote_parameters "${daemonctrl_opts[@]}" "--" "${vdr_opts[@]}")

	if [[ -z "${TERMINAL}" ]]; then
		start-stop-daemon "${daemonctrl_opts[@]}" \
			-- --daemon "${vdr_opts[@]}"
		exitcode=$?
	else
		TERMINAL=${TERMINAL/\/dev\/tty/}
		TERMINAL_DEVICE=/dev/tty${TERMINAL}
		{
			clear
			einfo "Starting vdr"
		} >${TERMINAL_DEVICE}

		# strange commandline, to be fixed in next versions
		openvt_opts=""
		if [[ "${SWITCH_TO_TERMINAL}" == "yes" ]]; then
			openvt_opts="${openvt_opts} -s"
		fi
		openvt -c ${TERMINAL} ${openvt_opts} -- \
			start-stop-daemon "${daemonctrl_opts[@]}" \
			-- "${vdr_opts[@]}"
		exitcode=$?
	fi
	eend $exitcode "Failed to start vdr."

	if [[ "${exitcode}" == "0" ]]; then
		load_addons_prefixed post-start
		if [[ "$?" != "0" ]]; then
			exitcode=1
		fi
	fi
	finish_vdr_start_log
	return $exitcode
}

stop() {
	INIT_PHASE=stop
	cd /
	load_addons_prefixed pre-stop

	ebegin "Stopping ${VDRNAME}"

	# Use --name here to allow us to kill vdr even after a new emerge
	start-stop-daemon --stop --quiet --retry 15 --name vdr
	eend $? "Failed to stop vdr."

	load_addons_prefixed post-stop
}

# gets called by watchdog to restart vdr
# and possibly reload modules
watchdogrestart() {
	cd /

	export WATCHDOG_RESTART="1"
	/etc/init.d/vdr pause
	sleep 2
	test_vdr_process && /bin/killall -9 vdr
	sleep 1

	/etc/init.d/vdr zap

	load_addons_prefixed watchdog-restart

	/etc/init.d/vdr start
	unset WATCHDOG_RESTART
}