source: src-sh/pbi-manager/pbime/pbimount @ f1dc8cf

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since f1dc8cf was f1dc8cf, checked in by Kris Moore <kris@…>, 10 months ago

Slow down the pace of nullfs mounts when starting a PBI, seems to fix some odd hangs

  • Property mode set to 100755
File size: 4.2 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4
5is_mounted() {
6   if [ ! -d "${1}" ] ; then return 1; fi
7   # Slow down the pace of nullfs mounts, this seems to fix the odd panic / hang
8   sleep 0.1
9   mount | grep -q "on ${1} (" 
10   return $?
11}
12
13check_pbidir() {
14  if [ -d "${1}/pbimeta" ] ; then return ; fi
15  echo "Error: Invalid PBI: ${1}"
16  exit 1
17}
18
19get_pdir() {
20  pDir="${1}"
21  if [ ! -d "${pDir}/virtbase" ] ; then
22    mkdir -p ${pDir}/virtbase
23  fi
24  if [ ! -d "${pDir}/run" ] ; then
25    mkdir -p ${pDir}/run
26  fi
27}
28
29mount_pbifile() {
30   if [ ! -d "$pDir" ] ; then
31      mkdir -p "${pDir}"
32   else
33      # Check to see if it is already mounted
34      mount | grep -q "on ${pDir} (ufs,"
35      if [ $? -eq 0 ] ; then return; fi
36   fi
37   MD=`mdconfig -a -t vnode -f ${1}`
38   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
39}
40
41mount_dirs() {
42   is_mounted "${pDir}/virtbase" || $NULLFS / "${pDir}/virtbase"
43   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
44   is_mounted "${pDir}/virtbase/usr/local" || $NULLFS ${1}/local "${pDir}/virtbase/usr/local"
45   is_mounted "${pDir}/virtbase/var/run" || $NULLFS ${pDir}/run "${pDir}/virtbase/var/run"
46   is_mounted "${pDir}/virtbase/compat/linux" || $NULLFS ${1}/linux "${pDir}/virtbase/compat/linux"
47   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
48      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || $NULLFS /usr/local/etc/fonts "${pDir}/virtbase/usr/local/etc/fonts"
49   fi
50   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
51      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || $NULLFS /usr/local/lib/X11/fonts "${pDir}/virtbase/usr/local/lib/X11/fonts"
52   fi
53   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
54      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || $NULLFS /usr/local/lib/X11/icons "${pDir}/virtbase/usr/local/lib/X11/icons"
55   fi
56   is_mounted "${pDir}/virtbase/tmp" || $NULLFS /tmp "${pDir}/virtbase/tmp"
57   is_mounted "${pDir}/virtbase/usr/home" || $NULLFS /usr/home "${pDir}/virtbase/usr/home"
58
59   # Check if we need to mount linprocfs
60   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
61      is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linproc "${pDir}/virtbase/compat/linux/proc"
62   fi
63
64   for i in `ls -d /usr/home/* 2>/dev/null`
65   do
66      is_mounted "${i}" 
67      if [ $? -eq 0 ] ;then
68         is_mounted "${pDir}/virtbase${i}" || $NULLFS ${i} "${pDir}/virtbase${i}"
69      fi
70
71   done
72
73   sync
74   cp /usr/pbi/.ldconfig "${pDir}/virtbase/var/run/ldconfig"
75   chroot "${pDir}/virtbase" /var/run/ldconfig start >/dev/null 2>/dev/null
76   sleep 1
77   sync
78}
79
80umount_pbidir() {
81   is_mounted "${pDir}/virtbase/usr/local/etc/fonts" && umount ${pDir}/virtbase/usr/local/etc/fonts
82   is_mounted "${pDir}/virtbase/usr/local/etc" && umount ${pDir}/virtbase/usr/local/etc
83   is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" && umount ${pDir}/virtbase/usr/local/lib/X11/fonts
84   is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" && umount ${pDir}/virtbase/usr/local/lib/X11/icons
85   is_mounted "${pDir}/virtbase/usr/local" && umount ${pDir}/virtbase/usr/local
86   is_mounted "${pDir}/virtbase/tmp" && umount ${pDir}/virtbase/tmp
87   is_mounted "${pDir}/virtbase/dev" && umount ${pDir}/virtbase/dev
88   is_mounted "${pDir}/virtbase/var/run" && umount ${pDir}/virtbase/var/run
89   is_mounted "${pDir}/virtbase/compat/linux/proc" && umount ${pDir}/virtbase/compat/linux/proc
90   is_mounted "${pDir}/virtbase/compat/linux" && umount ${pDir}/virtbase/compat/linux
91   for i in `ls -d ${pDir}/virtbase/usr/home/* 2>/dev/null`
92   do
93      is_mounted "${i}" && umount ${i}
94   done
95   is_mounted "${pDir}/virtbase/usr/home" && umount ${pDir}/virtbase/usr/home
96   is_mounted "${pDir}/virtbase" && umount ${pDir}/virtbase
97}
98
99
100# Doing an unmount?
101if [ "$1" = "umount" ] ; then
102   get_pdir "$2"
103   umount_pbidir "$2"
104   exit 0
105fi
106
107if [ -z "$1" -o -z "$2" ] ; then
108   echo "Missing args: mountdir / pbidir"
109   exit 1
110fi
111
112MNTBASEDIR="`dirname $2`"
113
114if [ ! -d "$MNTBASEDIR" ] ; then
115   mkdir -p ${MNTBASEDIR}
116   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
117fi
118
119# Lets begin the mount process
120get_pdir "$1"
121check_pbidir "${2}"
122mount_dirs "${2}"
123mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.