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

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 365dfc2 was 365dfc2, checked in by Kris Moore <kris@…>, 15 months ago
  • Fix a bug converting jails to new meta format, use unique IDs
  • Property mode set to 100755
File size: 3.4 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
65     # Get next unique ID
66     META_ID=0
67     for iDir in `ls -d ${JDIR}/.*.meta 2>/dev/null`
68     do
69       if [ ! -e "${iDir}/id" ] ; then continue ; fi
70       id=`cat ${iDir}/id`
71       if [ "${id}" -gt "${META_ID}" ] ; then
72          META_ID="${id}"
73       fi
74     done
75     : $(( META_ID += 1 ))
76     echo "$META_ID" > ${i}/id
77
78  fi
79
80  ID="`cat ${i}/id 2>/dev/null`"
81  HOST="`cat ${i}/host 2>/dev/null`"
82
83  #
84  # IPv4 networking
85  #
86  IPS4=
87  IP4=`cat ${i}/ipv4 2>/dev/null`
88  if [ -e "${i}/alias-ipv4" ] ; then
89    while read line
90    do
91      IPS4="${IPS4} ${line}" 
92    done < "${i}/alias-ipv4"
93  fi
94
95  BRIDGEIPS4=
96  BRIDGEIP4=`cat ${i}/bridge-ipv4 2>/dev/null`
97  if [ -e "${i}/alias-bridge-ipv4" ] ; then
98    while read line
99    do
100      BRIDGEIPS4="${BRIDGEIPS4} ${line}" 
101    done < "${i}/alias-bridge-ipv4"
102  fi
103
104  GATEWAY4=`cat ${i}/defaultrouter-ipv4 2>/dev/null`
105
106  #
107  # IPv6 networking
108  #
109  IPS6=
110  IP6=`cat ${i}/ipv6 2>/dev/null`
111  if [ -e "${i}/alias-ipv6" ] ; then
112    while read line
113    do
114      IPS6="${IPS6} ${line}" 
115    done < "${i}/alias-ipv6"
116  fi
117
118  BRIDGEIPS6=
119  BRIDGEIP6=`cat ${i}/bridge-ipv6 2>/dev/null`
120  if [ -e "${i}/alias-bridge-ipv6" ] ; then
121    while read line
122    do
123      BRIDGEIPS6="${BRIDGEIPS6} ${line}" 
124    done < "${i}/alias-bridge-ipv6"
125  fi
126
127  GATEWAY6=`cat ${i}/defaultrouter-ipv6 2>/dev/null`
128
129  # Check if we are autostarting this jail
130  if [ -e "${i}/autostart" ] ; then
131    AUTO="Enabled"
132  fi
133 
134  # Figure out the type of jail
135  if [ -e "${i}/jail-portjail" ] ; then
136    TYPE="portjail"
137  elif [ -e "${i}/jail-pluginjail" ] ; then
138    TYPE="pluginjail"
139  elif [ -e "${i}/jail-linux" ] ; then
140    TYPE="linuxjail"
141  else
142    TYPE="standard"
143  fi
144
145  JAILNAME=`echo ${i}|sed 's|.meta$||'|sed 's|^.||'`
146
147  ${PROGDIR}/scripts/backend/checkstatus.sh ${JAILNAME} 2>/dev/null
148  if [ "$?" = "0" ]
149  then
150    STATUS="Running"
151  else
152    STATUS="Stopped"
153  fi
154
155  if [ "${VERBOSE}" = "YES" ] ; then
156    cat<<__EOF__
157
158id: ${ID}
159host: ${HOST}
160ipv4: ${IP4}
161alias-ipv4: ${IPS4}
162bridge-ipv4: ${BRIDGEIP4}
163alias-bridge-ipv4: ${BRIDGEIPS4}
164defaultrouter-ipv4: ${GATEWAY4}
165ipv6: ${IP6}
166alias-ipv6: ${IPS6}
167bridge-ipv6: ${BRIDGEIP6}
168alias-bridge-ipv6: ${BRIDGEIPS6}
169defaultrouter-ipv6: ${GATEWAY6}
170autostart: ${AUTO}
171status: ${STATUS}
172type: ${TYPE}
173
174__EOF__
175
176  else
177    printf "%-24s%-12s%-12s%-12s\n" ${JAILNAME} ${AUTO} ${STATUS} ${TYPE}
178  fi
179done
180
Note: See TracBrowser for help on using the repository browser.