source: src-sh/warden/scripts/backend/listjails.sh @ a68c384

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since a68c384 was a68c384, checked in by Kris Moore <kris@…>, 18 months ago

Add some extra checks when we import old jails -> new format

Make sure IPV4 ends up with a /24 at the end

Also check at jail startup, in case somehow user imported jail with wrong config

  • Property mode set to 100755
File size: 3.5 KB
Line 
1#!/bin/sh
2# Prints a listing of the installed jails
3######################################################################
4
5# Source our functions
6PROGDIR="/usr/local/share/warden"
7
8# Source our variables
9. ${PROGDIR}/scripts/backend/functions.sh
10
11# Check if we have any jails
12if [ ! -d "${JDIR}" ]
13then
14  echo "Error: No jails found!"
15  exit 4
16fi
17
18line()
19{
20  len="${1}"
21
22  i=0
23  while [ "${i}" -lt "${len}" ] ; do
24    i=`expr ${i} + 1`
25    echo -n '-' 
26  done
27  echo 
28}
29
30lineline=0
31VERBOSE="NO"
32JAILS=
33while [ "$#" -gt "0" ] ; do
34  case "$1" in
35    -v) VERBOSE="YES" ;;
36     *) JAILS="${JAILS} .$1.meta" ;;
37  esac
38  shift
39done
40
41if [ "${VERBOSE}" != "YES" ] ; then
42# Prints a listing of the available jails
43  printf "%-24s%-12s%-12s%-12s\n" ID AUTOSTART STATUS TYPE
44  line "75"
45fi
46
47cd ${JDIR}
48if [ -z "${JAILS}" ] ; then
49  JAILS=`ls -d .*.meta 2>/dev/null`
50fi
51
52for i in ${JAILS}
53do
54  AUTO="Disabled" 
55  STATUS="<unknown>"
56
57  if [ ! -e "${i}/id" ] ; then 
58     # Check if its an old-style jail
59     if [ ! -e "${i}/ip" ] ; then
60        continue
61     fi
62     # This is an old style jail, lets convert it
63     cp ${i}/ip ${i}/ipv4
64     oIP=`cat ${i}/ipv4`
65     echo "${oIP}/24" > ${i}/ipv4
66
67     # Get next unique ID
68     META_ID=0
69     for iDir in `ls -d ${JDIR}/.*.meta 2>/dev/null`
70     do
71       if [ ! -e "${iDir}/id" ] ; then continue ; fi
72       id=`cat ${iDir}/id`
73       if [ "${id}" -gt "${META_ID}" ] ; then
74          META_ID="${id}"
75       fi
76     done
77     : $(( META_ID += 1 ))
78     echo "$META_ID" > ${i}/id
79
80  fi
81
82  ID="`cat ${i}/id 2>/dev/null`"
83  HOST="`cat ${i}/host 2>/dev/null`"
84
85  #
86  # IPv4 networking
87  #
88  IPS4=
89  IP4=`cat ${i}/ipv4 2>/dev/null`
90  if [ -e "${i}/alias-ipv4" ] ; then
91    while read line
92    do
93      IPS4="${IPS4} ${line}" 
94    done < "${i}/alias-ipv4"
95  fi
96
97  BRIDGEIPS4=
98  BRIDGEIP4=`cat ${i}/bridge-ipv4 2>/dev/null`
99  if [ -e "${i}/alias-bridge-ipv4" ] ; then
100    while read line
101    do
102      BRIDGEIPS4="${BRIDGEIPS4} ${line}" 
103    done < "${i}/alias-bridge-ipv4"
104  fi
105
106  GATEWAY4=`cat ${i}/defaultrouter-ipv4 2>/dev/null`
107
108  #
109  # IPv6 networking
110  #
111  IPS6=
112  IP6=`cat ${i}/ipv6 2>/dev/null`
113  if [ -e "${i}/alias-ipv6" ] ; then
114    while read line
115    do
116      IPS6="${IPS6} ${line}" 
117    done < "${i}/alias-ipv6"
118  fi
119
120  BRIDGEIPS6=
121  BRIDGEIP6=`cat ${i}/bridge-ipv6 2>/dev/null`
122  if [ -e "${i}/alias-bridge-ipv6" ] ; then
123    while read line
124    do
125      BRIDGEIPS6="${BRIDGEIPS6} ${line}" 
126    done < "${i}/alias-bridge-ipv6"
127  fi
128
129  GATEWAY6=`cat ${i}/defaultrouter-ipv6 2>/dev/null`
130
131  # Check if we are autostarting this jail
132  if [ -e "${i}/autostart" ] ; then
133    AUTO="Enabled"
134  fi
135 
136  # Figure out the type of jail
137  if [ -e "${i}/jail-portjail" ] ; then
138    TYPE="portjail"
139  elif [ -e "${i}/jail-pluginjail" ] ; then
140    TYPE="pluginjail"
141  elif [ -e "${i}/jail-linux" ] ; then
142    TYPE="linuxjail"
143  else
144    TYPE="standard"
145  fi
146
147  JAILNAME=`echo ${i}|sed 's|.meta$||'|sed 's|^.||'`
148
149  ${PROGDIR}/scripts/backend/checkstatus.sh ${JAILNAME} 2>/dev/null
150  if [ "$?" = "0" ]
151  then
152    STATUS="Running"
153  else
154    STATUS="Stopped"
155  fi
156
157  if [ "${VERBOSE}" = "YES" ] ; then
158    cat<<__EOF__
159
160id: ${ID}
161host: ${HOST}
162ipv4: ${IP4}
163alias-ipv4: ${IPS4}
164bridge-ipv4: ${BRIDGEIP4}
165alias-bridge-ipv4: ${BRIDGEIPS4}
166defaultrouter-ipv4: ${GATEWAY4}
167ipv6: ${IP6}
168alias-ipv6: ${IPS6}
169bridge-ipv6: ${BRIDGEIP6}
170alias-bridge-ipv6: ${BRIDGEIPS6}
171defaultrouter-ipv6: ${GATEWAY6}
172autostart: ${AUTO}
173status: ${STATUS}
174type: ${TYPE}
175
176__EOF__
177
178  else
179    printf "%-24s%-12s%-12s%-12s\n" ${JAILNAME} ${AUTO} ${STATUS} ${TYPE}
180  fi
181done
182
Note: See TracBrowser for help on using the repository browser.