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

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

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100755
File size: 3.2 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
58if [ "$LINUXJAIL" = "YES" ] ; then
59  # If we have a custom stop script
60  if [ -e "${JMETADIR}/jail-stop" ] ; then
61    sCmd=`cat ${JMETADIR}/jail-stop`
62    echo "Stopping jail with: ${sCmd}"
63    if [ -n "${JID}" ] ; then
64      jexec ${JID} ${sCmd} 2>&1
65    fi
66  else
67    # Check for different init styles
68    if [ -e "${JAILDIR}/etc/init.d/rc" ] ; then
69      if [ -n "${JID}" ] ; then
70        jexec ${JID} /bin/sh /etc/init.d/rc 0 2>&1
71      fi
72    elif [ -e "${JAILDIR}/etc/rc" ] ; then
73      if [ -n "${JID}" ] ; then
74        jexec ${JID} /bin/sh /etc/rc 0 2>&1
75      fi
76    fi
77  fi
78  sleep 3
79
80  umount -f ${JAILDIR}/sys 2>/dev/null
81  umount -f ${JAILDIR}/dev/fd 2>/dev/null
82  umount -f ${JAILDIR}/dev 2>/dev/null
83  umount -f ${JAILDIR}/lib/init/rw 2>/dev/null
84else
85  # If we have a custom stop script
86  if [ -e "${JMETADIR}/jail-stop" ] ; then
87    if [ -n "${JID}" ] ; then
88      sCmd=`cat ${JMETADIR}/jail-stop`
89      echo "Stopping jail with: ${sCmd}"
90      jexec ${JID} ${sCmd} 2>&1
91    fi
92  else
93    if [ -n "${JID}" ] ; then
94      echo "Stopping jail with: /etc/rc.shutdown"
95      jexec ${JID} /bin/sh /etc/rc.shutdown >/dev/null 2>/dev/null
96    fi
97  fi
98fi
99
100umount -f ${JAILDIR}/dev >/dev/null 2>/dev/null
101
102echo -e ".\c"
103
104# Skip the time consuming portion if we are shutting down
105if [ "$FAST" != "Y" ]
106then
107
108# We asked nicely, so now kill the jail for sure
109killall -j ${JID} -TERM 2>/dev/null
110sleep 1
111killall -j ${JID} -KILL 2>/dev/null
112
113echo -e ".\c"
114
115# Check if we need to unmount the devfs in jail
116mount | grep "${JAILDIR}/dev" >/dev/null 2>/dev/null
117if [ "$?" = "0" ]
118then
119  # Setup a 60 second timer to try and umount devfs, since takes a bit
120  SEC="0"
121  while
122   i=1
123  do
124   sleep 2
125
126   # Try to unmount dev
127   umount -f "${JAILDIR}/dev" 2>/dev/null
128   if [ "$?" = "0" ]
129   then
130      break
131   fi
132
133   SEC="`expr $SEC + 2`"
134   echo -e ".\c"
135
136   if [ ${SEC} -gt 60 ]
137   then
138      break
139   fi
140
141  done
142fi
143
144# Check if we need to unmount any extra dirs
145mount | grep "${JAILDIR}/proc" >/dev/null 2>/dev/null
146if [ "$?" = "0" ]; then
147  umount -f "${JAILDIR}/proc"
148fi
149
150if [ -e "${JMETADIR}/jail-portjail" ] ; then
151  umountjailxfs
152fi
153
154fi # End of FAST check
155
156echo -e ".\c"
157
158if [ -n "${JID}" ] ; then
159  jail -r ${JID}
160fi
161
162echo -e "Done"
Note: See TracBrowser for help on using the repository browser.