summaryrefslogtreecommitdiff
path: root/media-video/noad/files/pre-shutdown-15-noad.sh
blob: 476741e7bac716d96f3b0bf543b51b2589a2c257 (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
#
# pre-shutdown script to abort shutdown in case noad is running

check_runtime() {
	local PID="$1"

	# Max runtime of 30m = 1800s
	local NOAD_MAX_TIME=1800
	local NOW="$(date +%s)"
	local START="$(stat --format "%Z" /proc/${PID}/)"
	local DIFF=$(( $NOW - $START ))
	if [ "${DIFF}" -ge "${NOAD_MAX_TIME}" ]; then
		kill ${PID}
		sleep 2
		kill -9 ${PID}
		return 0
	else
		# There still is a running noad process
		return 1
	fi
}

check_noad() {
	local PIDOF=pidof
	local NOAD=/usr/bin/noad

	local PIDS=$(${PIDOF} ${NOAD})
	local PID
	local still_running=0
	for PID in $PIDS; do
		check_runtime "${PID}"
		[ "$?" = "1" ] && still_running=1
	done

	if [ "${still_running}" -gt "0" ]; then
		# stop shutdown
		shutdown_abort_can_force "noad is running"
	fi
}

check_noad