summaryrefslogtreecommitdiff
blob: 0604c61c78a4e68dfc64edbbd58e8465ec15b5e3 (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
#!/sbin/openrc-run
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_started_commands="checkconfig reload"

CRD=/opt/google/chrome-remote-desktop/chrome-remote-desktop

depend() {
	need net
	use logger
}

checkconfig() {
	local ret=0
	if [ -z "${CHROME_REMOTING_USERS}" ] ; then
		eerror "You must set CHROME_REMOTING_USERS in /etc/conf.d/${SVCNAME} first"
		ret=1
	else
		local user
		for user in ${CHROME_REMOTING_USERS} ; do
			if ! id "${user}" >/dev/null ; then
				eerror "Invalid user found in CHROME_REMOTING_USERS: ${user}"
				ret=1
			fi
		done
	fi
	return ${ret}
}

for_users() {
	local user ret msg log
	msg=$1; shift

	: ${CHROME_REMOTE_DESKTOP_LOG_DIR:=/var/log}

	for user in ${CHROME_REMOTING_USERS} ; do
		ebegin "${msg} ${SVCNAME} for ${user}"

		log="${CHROME_REMOTE_DESKTOP_LOG_DIR}/${SVCNAME}.${user}.log"
		checkpath -f -m 0600 -o "${user}" "${log}"

		# We need to background the app as it won't fork until the network
		# (including DNS) is available.
		start-stop-daemon \
			-b \
			-u "${user}" \
			-x "${CRD}" \
			-e "CHROME_REMOTE_DESKTOP_LOG_FILE=${log}" \
			-- \
			${OPTIONS} \
			"$@"
		eend $?
		: $(( ret |= $? ))
	done

	return ${ret}
}

start() {
	checkconfig || return
	for_users Starting --start
}

stop() {
	for_users Stopping --stop
}

reload() {
	for_users Reloading --reload
}