aboutsummaryrefslogtreecommitdiff
path: root/net/vncreflector/files/vncreflector.in
blob: 7b27250947134624756039444524807c928715c4 (plain) (blame)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
# $FreeBSD$

# PROVIDE: vncreflector
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown

_etcdir="%%PREFIX%%/etc/vncreflector"

# Define these vncreflector_* variables in one of these files:
#       /etc/rc.conf
#       /etc/rc.conf.local
#       /etc/rc.conf.d/vncreflector
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
vncreflector_enable=${vncreflector_enable-"NO"}
vncreflector_hostinfofile=${vncreflector_hostinfofile-"${_etcdir}/hostinfo"}
vncreflector_passwdfile=${vncreflector_passwdfile-"${_etcdir}/passwd"}
vncreflector_ports=${vncreflector_ports-"5999"}
vncreflector_requirepasswdfile=${vncreflector_requirepasswdfile-"YES"}
vncreflector_flags=${vncreflector_flags-"-q"}
vncreflector_pidfile=${vncreflector_pidfile-"/var/run/vncreflector.pid"}
vncreflector_logfile=${vncreflector_logfile-"/var/log/vncreflector.log"}
vncreflector_activefile=${vncreflector_logfile-"/var/log/vncreflector.log"}
vncreflector_addr=${vncreflector_addr-""}
#vncreflector_addr_5999=

. /etc/rc.subr

name="vncreflector"
rcvar=vncreflector_enable
start_cmd="vncreflector_start"
stop_cmd="vncreflector_stop"
command="%%PREFIX%%/bin/${name}"
# Disconnect from host, reread host file, reconnect.
sig_reload=USR2

vncreflector_start()
{
	_started=0

	echo -n "starting ${name}:"

	rc_flags=${vncreflector_flags}

	for _port in ${vncreflector_ports}; do
		echo -n " ${_port}"
		pidfile="${vncreflector_pidfile}.${_port}"
		rc_pid=$(check_pidfile $pidfile $command)
		if [ -z "$rc_fast" -a -n "$rc_pid" ]; then
			echo -n "!"
			continue
		fi

		_hostinfofile=""
		_passwdfile=""
		# if we only have one port, try the bare hostinfo
		# before appending the port number.
		if [ "${vncreflector_ports}" = "${_port}" -a \
		    -r "${vncreflector_hostinfofile}" ]; then
			_hostinfofile=${vncreflector_hostinfofile}
			# if we found a bare hostinfo file, we'll also
			# look for a bare passwd file
			if [ -r "${vncreflector_passwdfile}" ]; then
				_passwdfile=${vncreflector_passwdfile}
			fi
		fi
		if [ -z "${_hostinfofile}" ]; then
			_hostinfofile="${vncreflector_hostinfofile}.${_port}"
		fi
		if [ ! -r "${_hostinfofile}" ]; then
			echo -n "!hostfile"
			continue
		fi
		# if we don't have a passwdfile yet, try to use a
		# port-specific one and fall back to trying a global one
		if [ -z "${_passwdfile}" ]; then
			_passwdfile=${vncreflector_passwdfile}
			if [ -r ${_passwdfile}.${_port} ]; then
				_passwdfile="${_passwdfile}.${_port}"
			fi
		fi
		if [ -r "${_passwdfile}" ]; then
			_passwdarg="-p${_passwdfile}"
		else
			if checkyesno vncreflector_requirepasswdfile; then
				if [ -z "$rc_force" ]; then
					warn "missing passwd file for ${_port}."
					return 1
				else 
					echo -n "!passwdfile"
					continue
				fi
			fi
			_passwdarg=""
		fi
		if [ -z "${vncreflector_logfile}" ]; then
			_logfile="/dev/null"
		else
			_logfile="${vncreflector_logfile}.${_port}"
		fi
		eval _addr=\$vncreflector_addr_${port}
		if [ -z "${_addr}" ]; then
			_addr=${vncreflector_addr}
		fi
		if [ -z "${_addr}" ]; then
			unset _addr
		fi

		_doit="\
${command} ${rc_flags} \
-i ${vncreflector_pidfile} \
-l ${_port} \
-g ${_logfile} \
${_addr+-l $_addr }${_passwdfile+-p $_passwdfile } \
${_hostinfofile}"
		debug "vncreflector_start: _doit: $_doit"
		eval $_doit
		_started=`expr 1 + ${_started}`
	done
	if [ $_started -lt 1 ]; then
		return 1
	fi
	echo "."
}

vncreflector_stop()
{
	echo -n "stopping ${name}: "

	_pids=""

	for _port in ${vncreflector_ports}; do
		echo -n " ${_port}"
		pidfile="${vncreflector_pidfile}.${_port}"
		rc_pid=$(check_pidfile $pidfile $command)
		if [ -n "$rc_pid" ]; then
			kill $sig_stop $rc_pid
			_pids="${_pids} ${rc_pid}"
		else
			warn "no server for port ${_port}"
		fi
	done
	echo "."
	wait_for_pids $_pids
}

load_rc_config $name
run_rc_command $*