source: src-sh/warden/scripts/backend/stopjail.sh @ e50ac20

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since e50ac20 was e50ac20, checked in by Kris Moore <kris@…>, 19 months ago

Add support to warden CLI for editing and using a custom 'fstab'
for each jail. Will allow us to setup nullfs mounts, among others

  • Property mode set to 100755
File size: 3.4 KB
Line 
1#!/bin/sh
2# Script to stop a jail
3# Args $1 = jail-name
4#######################################################################
5
6# Source our functions
7PROGDIR="/usr/local/share/warden"
8
9# Source our variables
10. ${PROGDIR}/scripts/backend/functions.sh
11
12JAILNAME="${1}"
13if [ "${2}" = "FAST" ]
14then
15  FAST="Y"
16fi
17
18if [ -z "${JAILNAME}" ]
19then
20  echo "ERROR: No jail specified to delete!"
21  exit 5
22fi
23
24if [ -z "${JDIR}" ]
25then
26  echo "ERROR: JDIR is unset!!!!"
27  exit 5
28fi
29
30JAILDIR="${JDIR}/${JAILNAME}"
31
32if [ ! -d "${JAILDIR}" ]
33then
34  echo "ERROR: No jail located at ${JAILDIR}"
35  exit 5
36fi
37
38
39HOST="`cat ${JMETADIR}/host`"
40
41# End of error checking, now shutdown this jail
42##################################################################
43
44echo -e "Stopping the jail...\c"
45
46# Get the JailID for this jail
47JID="`jls | grep ${JAILDIR}$ | tr -s " " | cut -d " " -f 2`"
48
49echo -e ".\c"
50
51# Check if we need umount x mnts
52if [ -e "${JMETADIR}/jail-portjail" ] ; then umountjailxfs ${JAILNAME} ; fi
53
54jail_interfaces_down "${JID}"
55
56if [ -e "${JMETADIR}/jail-linux" ] ; then LINUXJAIL="YES" ; fi
57
58# Check for user-supplied mounts
59if [ -e "${JMETADIR}/fstab" ] ; then
60   echo "Unmounting user-supplied file-systems"
61   umount -a -F ${JMETADIR}/fstab
62fi
63
64if [ "$LINUXJAIL" = "YES" ] ; then
65  # If we have a custom stop script
66  if [ -e "${JMETADIR}/jail-stop" ] ; then
67    sCmd=`cat ${JMETADIR}/jail-stop`
68    echo "Stopping jail with: ${sCmd}"
69    if [ -n "${JID}" ] ; then
70      jexec ${JID} ${sCmd} 2>&1
71    fi
72  else
73    # Check for different init styles
74    if [ -e "${JAILDIR}/etc/init.d/rc" ] ; then
75      if [ -n "${JID}" ] ; then
76        jexec ${JID} /bin/sh /etc/init.d/rc 0 2>&1
77      fi
78    elif [ -e "${JAILDIR}/etc/rc" ] ; then
79      if [ -n "${JID}" ] ; then
80        jexec ${JID} /bin/sh /etc/rc 0 2>&1
81      fi
82    fi
83  fi
84  sleep 3
85
86  umount -f ${JAILDIR}/sys 2>/dev/null
87  umount -f ${JAILDIR}/dev/fd 2>/dev/null
88  umount -f ${JAILDIR}/dev 2>/dev/null
89  umount -f ${JAILDIR}/lib/init/rw 2>/dev/null
90else
91  # If we have a custom stop script
92  if [ -e "${JMETADIR}/jail-stop" ] ; then
93    if [ -n "${JID}" ] ; then
94      sCmd=`cat ${JMETADIR}/jail-stop`
95      echo "Stopping jail with: ${sCmd}"
96      jexec ${JID} ${sCmd} 2>&1
97    fi
98  else
99    if [ -n "${JID}" ] ; then
100      echo "Stopping jail with: /etc/rc.shutdown"
101      jexec ${JID} /bin/sh /etc/rc.shutdown >/dev/null 2>/dev/null
102    fi
103  fi
104fi
105
106umount -f ${JAILDIR}/dev >/dev/null 2>/dev/null
107
108echo -e ".\c"
109
110# Skip the time consuming portion if we are shutting down
111if [ "$FAST" != "Y" ]
112then
113
114# We asked nicely, so now kill the jail for sure
115killall -j ${JID} -TERM 2>/dev/null
116sleep 1
117killall -j ${JID} -KILL 2>/dev/null
118
119echo -e ".\c"
120
121# Check if we need to unmount the devfs in jail
122mount | grep "${JAILDIR}/dev" >/dev/null 2>/dev/null
123if [ "$?" = "0" ]
124then
125  # Setup a 60 second timer to try and umount devfs, since takes a bit
126  SEC="0"
127  while
128   i=1
129  do
130   sleep 2
131
132   # Try to unmount dev
133   umount -f "${JAILDIR}/dev" 2>/dev/null
134   if [ "$?" = "0" ]
135   then
136      break
137   fi
138
139   SEC="`expr $SEC + 2`"
140   echo -e ".\c"
141
142   if [ ${SEC} -gt 60 ]
143   then
144      break
145   fi
146
147  done
148fi
149
150# Check if we need to unmount any extra dirs
151mount | grep "${JAILDIR}/proc" >/dev/null 2>/dev/null
152if [ "$?" = "0" ]; then
153  umount -f "${JAILDIR}/proc"
154fi
155
156if [ -e "${JMETADIR}/jail-portjail" ] ; then
157  umountjailxfs
158fi
159
160fi # End of FAST check
161
162echo -e ".\c"
163
164if [ -n "${JID}" ] ; then
165  jail -r ${JID}
166fi
167
168echo -e "Done"
Note: See TracBrowser for help on using the repository browser.