forked from cbsd/cbsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcconf.subr
83 lines (67 loc) · 2.69 KB
/
rcconf.subr
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
#v10.0.4
# this is a temporary wrapper for version 9.2.2 is intended to make the transition to sqlite3 version if rc.conf more painless
# required:
# strings.subr
#
# init_rcconf ( $jname must be not empty )
# ( $sqlfile - specify sqlfile in dbdir for searching data. If empty - local file is prefered )
init_rcconf()
{
local _JCOL _BCOL _A _ALLJCOL _ALLBCOL jname _sqlfile _datafile="local" i
[ -n "${2}" ] && _datafile="${2}"
_sqlfile="${dbdir}/${_datafile}.sqlite"
[ ! -f "${_sqlfile}" ] && return 0
. ${sharedir}/local-jails.schema
_JCOL="${MYCOL}"
#clean sqlite3 schema variables
for i in ${_JCOL}; do
unset ${i}
done
_ALLJCOL=$(echo ${_JCOL}|tr " " ",")
# empty string on remote node if cbsd version is mistmatch ( diff. jail schema )
_A=$( 2>/dev/null env sqldelimer="|" ${miscdir}/sqlcli ${_sqlfile} "SELECT ${_ALLJCOL} FROM jails WHERE jname=\"$1\"" )
[ -z "${_A}" ] && return 1
sqllist "${_A}" ${_JCOL}
if [ "${emulator}" = "bhyve" ]; then
. ${sharedir}/bhyve.conf
_BCOL="${MYCOL}"
# for i in ${_BCOL}; do
# unset ${i}
# done
jid=-1
_ALLBCOL=$(echo ${_BCOL}|tr " " ",")
_A=$( 2>/dev/null env sqldelimer="|" ${miscdir}/sqlcli ${_sqlfile} "SELECT ${_ALLBCOL} FROM bhyve WHERE jname=\"$1\"" )
sqllist "${_A}" ${_BCOL}
else
jid=0
fi
# sanity check that jid and status are similar to the real state, for localhost only
if [ "${_datafile}" = "local" -a "${emulator}" ]; then
get_jid
if [ "${emulator}" = "bhyve" ]; then
if [ -e "/dev/vmm/${jname}" ]; then
myjid="-1"
status="1"
else
status="0"
fi
fi
# check state when sqlite information is wrong and update it
[ ${myjid} -ne $jid ] && jid=${myjid} && ${miscdir}/sqlcli ${dbdir}/local.sqlite "UPDATE jails SET jid=\"${myjid}\" WHERE jname=\"${1}\""
# fix for status only for 0,1, not for slave or maintenace
if [ ${status} -eq 0 -o ${status} -eq 1 ]; then
[ ${myjid} -ne 0 -a ${status} -eq 0 ] && status=1 && ${miscdir}/sqlcli ${dbdir}/local.sqlite "UPDATE jails SET status=\"1\" WHERE jname=\"${1}\""
[ ${myjid} -eq 0 -a ${status} -ne 0 -a ${status} -ne 2 ] && status=0 && ${miscdir}/sqlcli ${dbdir}/local.sqlite "UPDATE jails SET status=\"0\" WHERE jname=\"${1}\""
fi
fi
# clean some variables if equal 0
[ "${basename}" = "0" ] && unset basename
[ "${slavenode}" = "0" ] && unset slavenode
[ "${masterhost}" = "0" ] && unset masterhost
[ "${exec_stop}" = "0" ] && unset ${exec_stop}
[ "${exec_poststart}" = "0" ] && unset ${exec_poststart}
[ "${exec_poststop}" = "0" ] && unset ${exec_poststop}
[ "${exec_prestart}" = "0" ] && unset ${exec_prestart}
[ "${exec_prestop}" = "0" ] && unset ${exec_prestop}
}
init_rcconf $jname $sqlfile