3 # sys-chroots Starts and stops services in chroots
5 # chkconfig: 2345 99 01
6 # description: This shell script starts and stops services in chroots
8 [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system
9 [ -n "$2" ] && SYSTEM_CHROOTS="$2"
11 if [ -z "$SYSTEM_CHROOTS" ]; then
24 export runlevel previous
26 [ -z "$runlevel" -o -z "$previous" -o "$runlevel" = "$previous" ] && exit 0
28 # Source function library.
29 . /etc/rc.d/init.d/functions
32 if [ "$previous" = "N" ]; then
35 export runlevel previous
38 if [ -f /var/lock/subsys/sys-chroots ]; then
39 msg_already_running "System chroots services"
43 msg_starting "System chroots services"; started
45 for dir in $SYSTEM_CHROOTS; do
46 [ ! -x "$dir/etc/rc.d/rc" ] && continue
47 msg_starting "System chroots services for $dir"; started
49 # Cleaning part, keep in sync with rc.sysinit
52 . /etc/rc.d/init.d/functions
55 [ -f /etc/cryptomtab ] && > /etc/cryptomtab
57 # Remove stale backups
58 rm -f /etc/mtab~ /etc/mtab~~ /etc/cryptomtab~ /etc/cryptomtab~~
61 # I would d use find, but /usr may not be mounted.
62 for afile in /var/lock/* /var/run/*; do
63 bafile=$(basename $afile)
64 if [ -d "$afile" ]; then
65 [ "$bafile" != "news" -a "$bafile" != "sudo" -a "$bafile" != "mon" ] && rm -rf $afile/*
67 [ "$bafile" != "hwprofile" ] && rm -f $afile 2> /dev/null
71 rm -f /var/lib/rpm/__db* /var/spool/postoffice/.pid.* /tmp/.X*-lock \
72 /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*
73 rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
74 /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \
75 /tmp/scrollkeeper-* /tmp/ssh-*
80 if [ -e /var/log/wtmpx ]; then
81 if [ -e /var/log/wtmp ]; then
84 mv /var/log/wtmpx /var/log/wtmp
88 chown root:utmp /var/run/utmp /var/log/wtmp
89 chmod 0664 /var/run/utmp /var/log/wtmp
91 if is_yes "$CLEAN_TMP"; then
92 rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
99 chroot $dir mount -o gid=17 -t proc proc /proc
100 # usbfs, if available
101 if [ -f /proc/bus/usb/devices ]; then
102 chroot $dir mount -t usbfs usbfs /proc/bus/usb
104 # sysfs is also needed before any other things (under kernel > 2.5)
105 if grep -q sysfs /proc/filesystems ; then
106 chroot $dir mount -t sysfs sysfs /sys
109 if grep -q selinuxfs /proc/filesystems ; then
110 chroot $dir mount -t selinuxfs selinuxfs /selinux
114 [ -f /var/lock/subsys/network ] && touch $dir/var/lock/subsys/network
116 chroot $dir /sbin/chkconfig single off
117 rm -f $dir/etc/rc.d/rc*.d/K*single
119 chroot $dir /etc/rc.d/rc $runlevel chroot
122 touch /var/lock/subsys/sys-chroots
127 if [ "$previous" = "N" ]; then
130 export runlevel previous
133 if [ ! -f /var/lock/subsys/sys-chroots ]; then
134 msg_not_running "System chroots services"
138 msg_stopping "System chroots services"; started
139 for dir in $SYSTEM_CHROOTS; do
140 [ ! -x "$dir/etc/rc.d/rc" ] && continue
141 msg_stopping "System chroots services for $dir"; started
142 rm -f $dir/var/lock/subsys/network
143 chroot $dir /etc/rc.d/rc $runlevel chroot
144 chroot $dir sh -c "grep -q selinuxfs /proc/filesystems && umount /selinux"
145 chroot $dir sh -c "grep -q sysfs /proc/filesystems && umount /sys"
146 chroot $dir umount -a
147 chroot $dir umount /proc
149 rm -f /var/lock/subsys/sys-chroots >/dev/null 2>&1
153 # See how we were called.
166 # TODO: running each service with status parameter
167 for dir in $SYSTEM_CHROOTS; do
168 echo "System chroots services for $dir"
169 chroot $dir /sbin/chkconfig --list
174 msg_usage "$0 {start|stop|restart|status}"