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
34 if [ "$previous" = "N" ]; then
37 export runlevel previous
40 if [ -f /var/lock/subsys/sys-chroots ]; then
41 msg_already_running "System chroots services"
45 msg_starting "System chroots services"; started
47 for dir in $SYSTEM_CHROOTS; do
48 [ ! -x "$dir/etc/rc.d/rc" ] && continue
49 msg_starting "System chroots services for $dir"; started
51 # Cleaning part, keep in sync with rc.sysinit
54 . /etc/rc.d/init.d/functions
57 [ -f /etc/cryptomtab ] && > /etc/cryptomtab
59 # Remove stale backups
60 rm -f /etc/mtab~ /etc/mtab~~ /etc/cryptomtab~ /etc/cryptomtab~~
63 # I would d use find, but /usr may not be mounted.
64 for afile in /var/lock/* /var/run/*; do
65 bafile=$(basename $afile)
66 if [ -d "$afile" ]; then
67 [ "$bafile" != "news" -a "$bafile" != "sudo" -a "$bafile" != "mon" ] && rm -rf $afile/*
69 [ "$bafile" != "hwprofile" ] && rm -f $afile 2> /dev/null
73 rm -f /var/lib/rpm/__db* /var/spool/postoffice/.pid.* /tmp/.X*-lock \
74 /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*
75 rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
76 /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \
77 /tmp/scrollkeeper-* /tmp/ssh-*
82 if [ -e /var/log/wtmpx ]; then
83 if [ -e /var/log/wtmp ]; then
86 mv /var/log/wtmpx /var/log/wtmp
90 chown root:utmp /var/run/utmp /var/log/wtmp
91 chmod 0664 /var/run/utmp /var/log/wtmp
93 if is_yes "$CLEAN_TMP"; then
94 rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
101 chroot $dir mount -o gid=17 -t proc proc /proc
102 # usbfs, if available
103 if [ -f /proc/bus/usb/devices ]; then
104 chroot $dir mount -t usbfs usbfs /proc/bus/usb
106 # sysfs is also needed before any other things (under kernel > 2.5)
107 if grep -q sysfs /proc/filesystems ; then
108 chroot $dir mount -o gid=17 -t sysfs sysfs /sys
111 if grep -q selinuxfs /proc/filesystems ; then
112 chroot $dir mount -o gid=17 -t selinuxfs selinuxfs /selinux
116 [ -f /var/lock/subsys/network ] && touch $dir/var/lock/subsys/network
118 chroot $dir /sbin/chkconfig single off
119 rm -f $dir/etc/rc.d/rc*.d/K*single
121 chroot $dir /etc/rc.d/rc $runlevel chroot
124 touch /var/lock/subsys/sys-chroots
129 if [ "$previous" = "N" ]; then
132 export runlevel previous
135 if [ ! -f /var/lock/subsys/sys-chroots ]; then
136 msg_not_running "System chroots services"
140 msg_stopping "System chroots services"; started
141 for dir in $SYSTEM_CHROOTS; do
142 [ ! -x "$dir/etc/rc.d/rc" ] && continue
143 msg_stopping "System chroots services for $dir"; started
144 rm -f $dir/var/lock/subsys/network
145 chroot $dir /etc/rc.d/rc $runlevel chroot
146 chroot $dir sh -c "grep -q selinuxfs /proc/filesystems && umount /selinux"
147 chroot $dir sh -c "grep -q sysfs /proc/filesystems && umount /sys"
148 chroot $dir umount -a
149 chroot $dir umount /proc
151 rm -f /var/lock/subsys/sys-chroots >/dev/null 2>&1
155 # See how we were called.
168 # TODO: running each service with status parameter
169 for dir in $SYSTEM_CHROOTS; do
170 echo "System chroots services for $dir"
171 chroot $dir /sbin/chkconfig --list
176 msg_usage "$0 {start|stop|restart|status}"