| 1 |
drobbins |
2 |
#!/bin/bash
|
| 2 |
vapier |
880 |
# Copyright 1999-2005 Gentoo Foundation
|
| 3 |
azarah |
266 |
# Distributed under the terms of the GNU General Public License v2
|
| 4 |
azarah |
85 |
# $Header$
|
| 5 |
drobbins |
2 |
|
| 6 |
azarah |
144 |
trap ":" INT QUIT TSTP
|
| 7 |
azarah |
161 |
source /sbin/functions.sh
|
| 8 |
vapier |
560 |
# Only source this when this is a livecd booting ...
|
| 9 |
azarah |
456 |
[ -f /sbin/livecd-functions.sh ] && source /sbin/livecd-functions.sh
|
| 10 |
azarah |
85 |
umask 022
|
| 11 |
|
|
|
| 12 |
|
|
try() {
|
| 13 |
agriffis |
488 |
local errstr
|
| 14 |
azarah |
144 |
local retval=0
|
| 15 |
azarah |
359 |
|
| 16 |
agriffis |
485 |
if [ -c /dev/null ]; then
|
| 17 |
|
|
errstr="$((eval $*) 2>&1 >/dev/null)"
|
| 18 |
|
|
else
|
| 19 |
|
|
errstr="$((eval $*) 2>&1)"
|
| 20 |
|
|
fi
|
| 21 |
azarah |
144 |
retval=$?
|
| 22 |
agriffis |
488 |
if [ "${retval}" -ne 0 ]
|
| 23 |
azarah |
85 |
then
|
| 24 |
agriffis |
539 |
splash "critical" &
|
| 25 |
azarah |
422 |
|
| 26 |
azarah |
144 |
echo -e "${ENDCOL}${NORMAL}[${BAD} oops ${NORMAL}]"
|
| 27 |
azarah |
85 |
echo
|
| 28 |
azarah |
144 |
eerror "The \"${1}\" command failed with error:"
|
| 29 |
azarah |
85 |
echo
|
| 30 |
azarah |
144 |
echo "${errstr#*: }"
|
| 31 |
|
|
echo
|
| 32 |
|
|
eerror "Since this is a critical task, startup cannot continue."
|
| 33 |
|
|
echo
|
| 34 |
|
|
/sbin/sulogin ${CONSOLE}
|
| 35 |
azarah |
297 |
einfo "Unmounting filesystems"
|
| 36 |
agriffis |
485 |
if [ -c /dev/null ]; then
|
| 37 |
vapier |
703 |
/bin/mount -a -o remount,ro &>/dev/null
|
| 38 |
agriffis |
485 |
else
|
| 39 |
|
|
/bin/mount -a -o remount,ro
|
| 40 |
|
|
fi
|
| 41 |
azarah |
297 |
einfo "Rebooting"
|
| 42 |
azarah |
144 |
/sbin/reboot -f
|
| 43 |
|
|
fi
|
| 44 |
azarah |
359 |
|
| 45 |
azarah |
144 |
return ${retval}
|
| 46 |
azarah |
85 |
}
|
| 47 |
|
|
|
| 48 |
azarah |
441 |
# Check that $1 exists ...
|
| 49 |
azarah |
301 |
check_statedir() {
|
| 50 |
azarah |
441 |
[ -z "$1" ] && return 0
|
| 51 |
vapier |
1166 |
|
| 52 |
|
|
if [ ! -d "$1" ] ; then
|
| 53 |
|
|
if ! mkdir -p "$1" &>/dev/null ; then
|
| 54 |
agriffis |
539 |
splash "critical" &
|
| 55 |
azarah |
301 |
echo
|
| 56 |
vapier |
1166 |
eerror "For Gentoo to function properly, \"$1\" needs to exist."
|
| 57 |
|
|
if [[ ${RC_FORCE_AUTO} == "yes" ]] ; then
|
| 58 |
|
|
eerror "Attempting to create \"$1\" for you ..."
|
| 59 |
|
|
mount -o remount,rw /
|
| 60 |
|
|
mkdir -p "$1"
|
| 61 |
|
|
else
|
| 62 |
|
|
eerror "Please mount your root partition read/write, and execute:"
|
| 63 |
|
|
echo
|
| 64 |
|
|
eerror " # mkdir -p $1"
|
| 65 |
|
|
echo; echo
|
| 66 |
|
|
/sbin/sulogin ${CONSOLE}
|
| 67 |
|
|
fi
|
| 68 |
azarah |
301 |
einfo "Unmounting filesystems"
|
| 69 |
vapier |
703 |
/bin/mount -a -o remount,ro &>/dev/null
|
| 70 |
azarah |
301 |
einfo "Rebooting"
|
| 71 |
|
|
/sbin/reboot -f
|
| 72 |
|
|
fi
|
| 73 |
|
|
fi
|
| 74 |
azarah |
389 |
|
| 75 |
|
|
return 0
|
| 76 |
azarah |
301 |
}
|
| 77 |
|
|
|
| 78 |
azarah |
780 |
udev_version() {
|
| 79 |
|
|
local version=0
|
| 80 |
|
|
|
| 81 |
|
|
if [ -x "/sbin/udev" ]
|
| 82 |
|
|
then
|
| 83 |
|
|
version=$(/sbin/udev -V)
|
| 84 |
|
|
# We need it without a leading '0', else bash do the wrong thing
|
| 85 |
|
|
version="${version##0}"
|
| 86 |
|
|
# Older udev's will print nothing
|
| 87 |
|
|
[ -z "${version}" ] && version=0
|
| 88 |
|
|
fi
|
| 89 |
|
|
|
| 90 |
|
|
echo "${version}"
|
| 91 |
|
|
}
|
| 92 |
|
|
|
| 93 |
azarah |
446 |
populate_udev() {
|
| 94 |
azarah |
780 |
# Now populate /dev
|
| 95 |
agriffis |
486 |
/sbin/udevstart
|
| 96 |
azarah |
446 |
|
| 97 |
azarah |
459 |
# Not provided by sysfs but needed
|
| 98 |
|
|
ln -snf /proc/self/fd /dev/fd
|
| 99 |
|
|
ln -snf fd/0 /dev/stdin
|
| 100 |
|
|
ln -snf fd/1 /dev/stdout
|
| 101 |
|
|
ln -snf fd/2 /dev/stderr
|
| 102 |
|
|
ln -snf /proc/kcore /dev/core
|
| 103 |
|
|
|
| 104 |
agriffis |
550 |
# Create nodes that udev can't
|
| 105 |
vapier |
703 |
[ -x /sbin/dmsetup ] && /sbin/dmsetup mknodes &>/dev/null
|
| 106 |
|
|
[ -x /sbin/lvm ] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
|
| 107 |
agriffis |
550 |
|
| 108 |
agriffis |
486 |
# Create problematic directories
|
| 109 |
|
|
mkdir -p /dev/{pts,shm}
|
| 110 |
|
|
|
| 111 |
|
|
# Same thing as /dev/.devfsd
|
| 112 |
|
|
touch /dev/.udev
|
| 113 |
|
|
|
| 114 |
azarah |
446 |
return 0
|
| 115 |
|
|
}
|
| 116 |
|
|
|
| 117 |
azarah |
389 |
get_critical_services() {
|
| 118 |
|
|
local x=
|
| 119 |
|
|
CRITICAL_SERVICES=
|
| 120 |
|
|
|
| 121 |
|
|
if [ -f "/etc/runlevels/${BOOTLEVEL}/.critical" ]
|
| 122 |
|
|
then
|
| 123 |
|
|
for x in $(< /etc/runlevels/${BOOTLEVEL}/.critical)
|
| 124 |
|
|
do
|
| 125 |
|
|
CRITICAL_SERVICES="${CRITICAL_SERVICES} ${x##*/}"
|
| 126 |
|
|
done
|
| 127 |
|
|
else
|
| 128 |
vapier |
669 |
CRITICAL_SERVICES="checkroot hostname modules checkfs localmount clock"
|
| 129 |
azarah |
389 |
fi
|
| 130 |
|
|
|
| 131 |
|
|
export CRITICAL_SERVICES
|
| 132 |
|
|
|
| 133 |
|
|
return 0
|
| 134 |
|
|
}
|
| 135 |
|
|
|
| 136 |
azarah |
297 |
# Save $1
|
| 137 |
azarah |
247 |
argv1="$1"
|
| 138 |
azarah |
85 |
|
| 139 |
azarah |
297 |
# First time boot stuff goes here. Note that 'sysinit' is an internal runlevel
|
| 140 |
|
|
# used to bring up local filesystems, and should not be started with /sbin/rc
|
| 141 |
|
|
# directly ...
|
| 142 |
|
|
if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "sysinit" ]
|
| 143 |
azarah |
69 |
then
|
| 144 |
azarah |
297 |
# Setup initial $PATH just in case
|
| 145 |
azarah |
144 |
PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}"
|
| 146 |
|
|
|
| 147 |
vapier |
649 |
# Help users recover their systems incase these go missing
|
| 148 |
|
|
[ -c /dev/null ] && dev_null=1 || dev_null=0
|
| 149 |
|
|
[ -c /dev/console ] && dev_console=1 || dev_console=0
|
| 150 |
agriffis |
485 |
|
| 151 |
azarah |
85 |
echo
|
| 152 |
azarah |
377 |
echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; ${BRACKET}http://www.gentoo.org/${NORMAL}"
|
| 153 |
vapier |
1045 |
echo -e " Copyright 1999-2005 Gentoo Foundation; Distributed under the GPLv2"
|
| 154 |
azarah |
85 |
echo
|
| 155 |
|
|
|
| 156 |
azarah |
441 |
check_statedir /proc
|
| 157 |
|
|
|
| 158 |
azarah |
359 |
ebegin "Mounting proc at /proc"
|
| 159 |
vapier |
795 |
if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
|
| 160 |
|
|
mntcmd=$(get_mount_fstab /proc)
|
| 161 |
|
|
else
|
| 162 |
|
|
unset mntcmd
|
| 163 |
|
|
fi
|
| 164 |
vapier |
880 |
try mount -n ${mntcmd:--t proc proc /proc}
|
| 165 |
azarah |
85 |
eend $?
|
| 166 |
azarah |
144 |
|
| 167 |
azarah |
456 |
# Read off the kernel commandline to see if there's any special settings
|
| 168 |
|
|
# especially check to see if we need to set the CDBOOT environment variable
|
| 169 |
|
|
# Note: /proc MUST be mounted
|
| 170 |
azarah |
458 |
[ -f /sbin/livecd-functions.sh ] && livecd_read_commandline
|
| 171 |
azarah |
456 |
|
| 172 |
vapier |
795 |
if [ "$(get_KV)" -ge "$(KV_to_int '2.6.0')" ] ; then
|
| 173 |
|
|
if [[ -d /sys ]] ; then
|
| 174 |
vapier |
610 |
ebegin "Mounting sysfs at /sys"
|
| 175 |
vapier |
795 |
if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
|
| 176 |
|
|
mntcmd=$(get_mount_fstab /sys)
|
| 177 |
|
|
else
|
| 178 |
|
|
unset mntcmd
|
| 179 |
|
|
fi
|
| 180 |
vapier |
880 |
try mount -n ${mntcmd:--t sysfs sysfs /sys}
|
| 181 |
vapier |
610 |
eend $?
|
| 182 |
|
|
else
|
| 183 |
|
|
ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
|
| 184 |
|
|
fi
|
| 185 |
azarah |
336 |
fi
|
| 186 |
|
|
|
| 187 |
azarah |
441 |
check_statedir /dev
|
| 188 |
|
|
|
| 189 |
azarah |
297 |
# Fix weird bug where there is a /dev/.devfsd in a unmounted /dev
|
| 190 |
vapier |
644 |
devfs_automounted="no"
|
| 191 |
|
|
if [ -e "/dev/.devfsd" ]
|
| 192 |
azarah |
132 |
then
|
| 193 |
vapier |
644 |
mymounts="$(awk '($3 == "devfs") { print "yes"; exit 0 }' /proc/mounts)"
|
| 194 |
|
|
if [ "${mymounts}" != "yes" ]
|
| 195 |
|
|
then
|
| 196 |
|
|
rm -f /dev/.devfsd
|
| 197 |
|
|
else
|
| 198 |
|
|
devfs_automounted="yes"
|
| 199 |
|
|
fi
|
| 200 |
azarah |
132 |
fi
|
| 201 |
|
|
|
| 202 |
vapier |
610 |
# Try to figure out how the user wants /dev handled
|
| 203 |
|
|
# - check $RC_DEVICES from /etc/conf.d/rc
|
| 204 |
|
|
# - check boot parameters
|
| 205 |
|
|
# - make sure the required binaries exist
|
| 206 |
|
|
# - make sure the kernel has support
|
| 207 |
vapier |
649 |
if [ "${RC_DEVICES}" = "static" ]
|
| 208 |
azarah |
410 |
then
|
| 209 |
vapier |
610 |
ebegin "Using existing device nodes in /dev"
|
| 210 |
|
|
eend 0
|
| 211 |
|
|
else
|
| 212 |
|
|
fellback_to_devfs="no"
|
| 213 |
|
|
case "${RC_DEVICES}" in
|
| 214 |
|
|
devfs) devfs="yes"
|
| 215 |
|
|
udev="no"
|
| 216 |
|
|
;;
|
| 217 |
|
|
udev) devfs="yes"
|
| 218 |
|
|
udev="yes"
|
| 219 |
|
|
fellback_to_devfs="yes"
|
| 220 |
|
|
;;
|
| 221 |
|
|
auto|*) devfs="yes"
|
| 222 |
|
|
udev="yes"
|
| 223 |
|
|
;;
|
| 224 |
|
|
esac
|
| 225 |
|
|
|
| 226 |
|
|
# Check udev prerequisites and kernel params
|
| 227 |
vapier |
649 |
if [ "${udev}" = "yes" ]
|
| 228 |
azarah |
471 |
then
|
| 229 |
vapier |
610 |
if get_bootparam "noudev" || \
|
| 230 |
|
|
[ ! -x /sbin/udev -o -e "/dev/.devfsd" ] || \
|
| 231 |
|
|
[ "$(get_KV)" -lt "$(KV_to_int '2.6.0')" ]
|
| 232 |
|
|
then
|
| 233 |
|
|
udev="no"
|
| 234 |
|
|
fi
|
| 235 |
azarah |
471 |
fi
|
| 236 |
vapier |
610 |
|
| 237 |
|
|
# Check devfs prerequisites and kernel params
|
| 238 |
vapier |
649 |
if [ "${devfs}" = "yes" ]
|
| 239 |
azarah |
434 |
then
|
| 240 |
vapier |
649 |
if get_bootparam "nodevfs" || [ "${udev}" = "yes" ]
|
| 241 |
vapier |
610 |
then
|
| 242 |
|
|
devfs="no"
|
| 243 |
|
|
fi
|
| 244 |
|
|
fi
|
| 245 |
|
|
|
| 246 |
|
|
# Actually start setting up /dev now
|
| 247 |
vapier |
795 |
if [[ ${udev} = "yes" ]] ; then
|
| 248 |
vapier |
610 |
# Setup temporary storage for /dev
|
| 249 |
vapier |
730 |
ebegin "Mounting /dev for udev"
|
| 250 |
vapier |
795 |
if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
|
| 251 |
|
|
mntcmd=$(get_mount_fstab /dev)
|
| 252 |
|
|
else
|
| 253 |
|
|
unset mntcmd
|
| 254 |
|
|
fi
|
| 255 |
|
|
if [[ -n ${mntcmd} ]] ; then
|
| 256 |
uberlord |
768 |
try mount -n ${mntcmd}
|
| 257 |
vapier |
730 |
else
|
| 258 |
|
|
if egrep -qs tmpfs /proc/filesystems ; then
|
| 259 |
vapier |
1132 |
mntcmd="tmpfs"
|
| 260 |
vapier |
730 |
else
|
| 261 |
vapier |
1132 |
mntcmd="ramfs"
|
| 262 |
vapier |
730 |
fi
|
| 263 |
vapier |
1132 |
try mount -n -t ${mntcmd} udev /dev -o noexec,nosuid,mode=0755
|
| 264 |
vapier |
649 |
fi
|
| 265 |
vapier |
610 |
eend $?
|
| 266 |
|
|
|
| 267 |
vapier |
1094 |
# Selinux lovin; /selinux should be mounted by selinux-patched init
|
| 268 |
|
|
if [[ -x /sbin/restorecon ]] && [[ -c /selinux/null ]] ; then
|
| 269 |
|
|
restorecon /dev &> /selinux/null
|
| 270 |
|
|
fi
|
| 271 |
|
|
|
| 272 |
vapier |
610 |
# Actually get udev rolling
|
| 273 |
|
|
ebegin "Configuring system to use udev"
|
| 274 |
vapier |
784 |
if [[ ${RC_DEVICE_TARBALL} = "yes" ]] && [[ -s /lib/udev-state/devices.tar.bz2 ]]
|
| 275 |
vapier |
610 |
then
|
| 276 |
vapier |
681 |
einfo " Populating /dev with device nodes ..."
|
| 277 |
vapier |
610 |
try tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
|
| 278 |
|
|
fi
|
| 279 |
|
|
populate_udev
|
| 280 |
|
|
|
| 281 |
|
|
# Setup hotplugging (if possible)
|
| 282 |
vapier |
1166 |
if [ -e /proc/sys/kernel/hotplug ] ; then
|
| 283 |
|
|
if [ "$(udev_version)" -ge "48" ] ; then
|
| 284 |
azarah |
780 |
einfo " Setting /sbin/udevsend as hotplug agent ..."
|
| 285 |
|
|
echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
|
| 286 |
vapier |
1166 |
elif [ -x /sbin/hotplug ] ; then
|
| 287 |
azarah |
780 |
einfo " Using /sbin/hotplug as hotplug agent ..."
|
| 288 |
vapier |
610 |
else
|
| 289 |
vapier |
681 |
einfo " Setting /sbin/udev as hotplug agent ..."
|
| 290 |
vapier |
610 |
echo "/sbin/udev" > /proc/sys/kernel/hotplug
|
| 291 |
|
|
fi
|
| 292 |
|
|
fi
|
| 293 |
|
|
eend 0
|
| 294 |
|
|
|
| 295 |
|
|
# With devfs, /dev can be mounted by the kernel ...
|
| 296 |
vapier |
644 |
elif [ "${devfs}" = "yes" ]
|
| 297 |
vapier |
610 |
then
|
| 298 |
|
|
mymounts="$(awk '($2 == "devfs") { print "yes"; exit 0 }' /proc/filesystems)"
|
| 299 |
|
|
# Is devfs support compiled in?
|
| 300 |
|
|
if [ "${mymounts}" = "yes" ]
|
| 301 |
|
|
then
|
| 302 |
vapier |
644 |
if [ "${devfs_automounted}" = "no" ]
|
| 303 |
|
|
then
|
| 304 |
|
|
ebegin "Mounting devfs at /dev"
|
| 305 |
vapier |
880 |
try mount -n -t devfs devfs /dev
|
| 306 |
vapier |
644 |
eend $?
|
| 307 |
|
|
else
|
| 308 |
|
|
ebegin "Kernel automatically mounted devfs at /dev"
|
| 309 |
|
|
eend 0
|
| 310 |
|
|
fi
|
| 311 |
vapier |
610 |
ebegin "Starting devfsd"
|
| 312 |
vapier |
703 |
/sbin/devfsd /dev >/dev/null
|
| 313 |
vapier |
610 |
eend $? "Could not start /sbin/devfsd"
|
| 314 |
|
|
else
|
| 315 |
|
|
devfs="no"
|
| 316 |
|
|
fi
|
| 317 |
|
|
|
| 318 |
|
|
# Did the user want udev in the config file but for
|
| 319 |
|
|
# some reason, udev support didnt work out ?
|
| 320 |
vapier |
649 |
if [ "${fellback_to_devfs}" = "yes" ]
|
| 321 |
vapier |
610 |
then
|
| 322 |
|
|
ewarn "You wanted udev but support for it was not available!"
|
| 323 |
|
|
ewarn "Please review your system after it's booted!"
|
| 324 |
|
|
fi
|
| 325 |
azarah |
434 |
fi
|
| 326 |
azarah |
410 |
|
| 327 |
vapier |
610 |
# OK, if we got here, things are probably not right :)
|
| 328 |
vapier |
649 |
if [ "${devfs}" = "no" ] && [ "${udev}" = "no" ]
|
| 329 |
azarah |
85 |
then
|
| 330 |
|
|
clear
|
| 331 |
|
|
echo
|
| 332 |
vapier |
610 |
einfo "The Gentoo Linux system initialization scripts have detected that"
|
| 333 |
|
|
einfo "your system does not support DEVFS or UDEV. Since Gentoo Linux"
|
| 334 |
|
|
einfo "has been designed with these dynamic /dev managers in mind, it is"
|
| 335 |
|
|
einfo "highly suggested that you build support for it into your kernel."
|
| 336 |
|
|
einfo "Please read the Gentoo Handbook for more information!"
|
| 337 |
azarah |
85 |
echo
|
| 338 |
vapier |
610 |
einfo " http://www.gentoo.org/doc/en/handbook/"
|
| 339 |
azarah |
85 |
echo
|
| 340 |
vapier |
610 |
einfo "Thanks for using Gentoo! :)"
|
| 341 |
azarah |
85 |
echo
|
| 342 |
vapier |
681 |
read -t 15 -p "(hit Enter to continue or wait 15 seconds ...)"
|
| 343 |
azarah |
85 |
fi
|
| 344 |
|
|
fi
|
| 345 |
|
|
|
| 346 |
azarah |
350 |
# From linux-2.5.68 we need to mount /dev/pts again ...
|
| 347 |
|
|
if [ "$(get_KV)" -ge "$(KV_to_int '2.5.68')" ]
|
| 348 |
|
|
then
|
| 349 |
azarah |
359 |
have_devpts="$(awk '($2 == "devpts") { print "yes"; exit 0 }' /proc/filesystems)"
|
| 350 |
azarah |
350 |
|
| 351 |
|
|
if [ "${have_devpts}" = "yes" ]
|
| 352 |
|
|
then
|
| 353 |
vapier |
610 |
# Only try to create /dev/pts if we have /dev mounted dynamically,
|
| 354 |
azarah |
350 |
# else it might fail as / might be still mounted readonly.
|
| 355 |
vapier |
610 |
if [ ! -d /dev/pts ] && \
|
| 356 |
vapier |
649 |
[ "${devfs}" = "yes" -o "${udev}" = "yes" ]
|
| 357 |
azarah |
350 |
then
|
| 358 |
|
|
# Make sure we have /dev/pts
|
| 359 |
azarah |
441 |
mkdir -p /dev/pts &>/dev/null || \
|
| 360 |
|
|
ewarn "Could not create /dev/pts!"
|
| 361 |
azarah |
350 |
fi
|
| 362 |
|
|
|
| 363 |
vapier |
795 |
if [[ -d /dev/pts ]] ; then
|
| 364 |
azarah |
359 |
ebegin "Mounting devpts at /dev/pts"
|
| 365 |
vapier |
795 |
if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
|
| 366 |
|
|
mntcmd=$(get_mount_fstab /dev/pts)
|
| 367 |
|
|
else
|
| 368 |
|
|
unset mntcmd
|
| 369 |
|
|
fi
|
| 370 |
vapier |
880 |
try mount -n ${mntcmd:--t devpts -o gid=5,mode=0620 devpts /dev/pts}
|
| 371 |
azarah |
350 |
eend $?
|
| 372 |
|
|
fi
|
| 373 |
|
|
fi
|
| 374 |
|
|
fi
|
| 375 |
|
|
|
| 376 |
azarah |
388 |
# Swap needs to be activated *after* devfs has been mounted and *after*
|
| 377 |
|
|
# devfsd has been started, so that the fstab can be properly parsed
|
| 378 |
|
|
# and only if the server/Gentoo box is initialized ...
|
| 379 |
|
|
ebegin "Activating (possible) swap"
|
| 380 |
vapier |
880 |
/sbin/swapon -a
|
| 381 |
azarah |
388 |
eend 0
|
| 382 |
azarah |
238 |
|
| 383 |
azarah |
297 |
# Set the console loglevel to 1 for a cleaner boot
|
| 384 |
azarah |
241 |
# the logger should anyhow dump the ring-0 buffer at start to the
|
| 385 |
|
|
# logs, and that with dmesg can be used to check for problems
|
| 386 |
azarah |
85 |
/bin/dmesg -n 1
|
| 387 |
|
|
|
| 388 |
azarah |
388 |
# We set the forced softlevel from the kernel command line
|
| 389 |
|
|
# It needs to be run right after proc is mounted for the
|
| 390 |
|
|
# boot runlevel
|
| 391 |
azarah |
389 |
setup_defaultlevels
|
| 392 |
azarah |
388 |
|
| 393 |
azarah |
241 |
# $BOOT can be used by rc-scripts to test if it is the first time
|
| 394 |
azarah |
297 |
# the 'boot' runlevel is executed. Now also needed by some stuff in
|
| 395 |
|
|
# the 'sysinit' runlevel ...
|
| 396 |
azarah |
85 |
export BOOT="yes"
|
| 397 |
vapier |
668 |
|
| 398 |
azarah |
359 |
start_critical_service() {
|
| 399 |
azarah |
469 |
(
|
| 400 |
vapier |
668 |
local retval=
|
| 401 |
vapier |
791 |
local service=$1
|
| 402 |
azarah |
1054 |
# Needed for some addons like dm-crypt that starts in critical services
|
| 403 |
|
|
local myservice=$1
|
| 404 |
azarah |
359 |
|
| 405 |
vapier |
791 |
source "/etc/init.d/${service}" || eerror "Failed to source /etc/init.d/${service}"
|
| 406 |
vapier |
668 |
retval=$?
|
| 407 |
|
|
[ "${retval}" -ne 0 ] && return "${retval}"
|
| 408 |
vapier |
791 |
[ -e "/etc/conf.d/${service}" ] && source "/etc/conf.d/${service}"
|
| 409 |
vapier |
728 |
source /etc/rc.conf
|
| 410 |
vapier |
668 |
|
| 411 |
vapier |
791 |
start || eerror "Failed to start /etc/init.d/${service}"
|
| 412 |
vapier |
668 |
retval=$?
|
| 413 |
|
|
|
| 414 |
|
|
return "${retval}"
|
| 415 |
azarah |
469 |
)
|
| 416 |
azarah |
359 |
}
|
| 417 |
azarah |
388 |
|
| 418 |
vapier |
560 |
# We first try to find a locally defined list of critical services
|
| 419 |
|
|
# for a particular runlevel. If we cannot find it, we use the
|
| 420 |
azarah |
388 |
# defaults.
|
| 421 |
azarah |
389 |
get_critical_services
|
| 422 |
azarah |
388 |
|
| 423 |
agriffis |
539 |
splash "rc_init" "${argv1}"
|
| 424 |
|
|
|
| 425 |
azarah |
417 |
# We do not want to break compatibility, so we do not fully integrate
|
| 426 |
azarah |
297 |
# these into /sbin/rc, but rather start them by hand ...
|
| 427 |
azarah |
388 |
for x in ${CRITICAL_SERVICES}
|
| 428 |
azarah |
297 |
do
|
| 429 |
agriffis |
539 |
splash "svc_start" "${x}"
|
| 430 |
azarah |
419 |
|
| 431 |
azarah |
359 |
if ! start_critical_service "${x}"
|
| 432 |
azarah |
297 |
then
|
| 433 |
vapier |
703 |
splash "critical" &>/dev/null &
|
| 434 |
azarah |
419 |
|
| 435 |
azarah |
297 |
echo
|
| 436 |
|
|
eerror "One of more critical startup scripts failed to start!"
|
| 437 |
|
|
eerror "Please correct this, and reboot ..."
|
| 438 |
|
|
echo; echo
|
| 439 |
|
|
/sbin/sulogin ${CONSOLE}
|
| 440 |
|
|
einfo "Unmounting filesystems"
|
| 441 |
agriffis |
488 |
/bin/mount -a -o remount,ro &>/dev/null
|
| 442 |
azarah |
297 |
einfo "Rebooting"
|
| 443 |
|
|
/sbin/reboot -f
|
| 444 |
|
|
fi
|
| 445 |
agriffis |
539 |
|
| 446 |
|
|
splash "svc_started" "${x}" "0"
|
| 447 |
azarah |
297 |
done
|
| 448 |
vapier |
689 |
|
| 449 |
vapier |
1144 |
# have to run this after /var/run is mounted rw #85304
|
| 450 |
|
|
if [ -x /sbin/irqbalance -a "$(get_KV)" -ge "$(KV_to_int '2.5.0')" ]
|
| 451 |
|
|
then
|
| 452 |
|
|
ebegin "Starting irqbalance"
|
| 453 |
|
|
/sbin/irqbalance
|
| 454 |
|
|
eend $?
|
| 455 |
|
|
fi
|
| 456 |
|
|
|
| 457 |
azarah |
302 |
# Check that $svcdir exists ...
|
| 458 |
azarah |
441 |
check_statedir "${svcdir}"
|
| 459 |
azarah |
302 |
|
| 460 |
vapier |
689 |
# Should we use tmpfs/ramfs/ramdisk for caching dependency and
|
| 461 |
|
|
# general initscript data? Note that the 'gentoo=<fs>' kernel
|
| 462 |
|
|
# option should override any other setting ...
|
| 463 |
|
|
for fs in tmpfs ramfs ramdisk
|
| 464 |
|
|
do
|
| 465 |
|
|
if get_bootparam "${fs}"
|
| 466 |
|
|
then
|
| 467 |
|
|
svcmount="yes"
|
| 468 |
|
|
svcfstype="${fs}"
|
| 469 |
|
|
break
|
| 470 |
|
|
fi
|
| 471 |
|
|
done
|
| 472 |
vapier |
649 |
if [ "${svcmount}" = "yes" ]
|
| 473 |
azarah |
302 |
then
|
| 474 |
vapier |
689 |
ebegin "Mounting ${svcfstype} at ${svcdir}"
|
| 475 |
|
|
case "${svcfstype}" in
|
| 476 |
|
|
ramfs)
|
| 477 |
vapier |
880 |
try mount -n -t ramfs svcdir "${svcdir}" \
|
| 478 |
vapier |
1056 |
-o rw,mode=0755,size="${svcsize}"k
|
| 479 |
vapier |
689 |
;;
|
| 480 |
|
|
ramdisk)
|
| 481 |
|
|
try dd if=/dev/zero of=/dev/ram0 bs=1k count="${svcsize}"
|
| 482 |
|
|
try /sbin/mke2fs -i 1024 -vm0 /dev/ram0 "${svcsize}"
|
| 483 |
|
|
try mount -n -t ext2 /dev/ram0 "${svcdir}" -o rw
|
| 484 |
|
|
;;
|
| 485 |
|
|
tmpfs|*)
|
| 486 |
vapier |
880 |
try mount -n -t tmpfs svcdir "${svcdir}" \
|
| 487 |
vapier |
1056 |
-o rw,mode=0755,size="${svcsize}"k
|
| 488 |
vapier |
689 |
;;
|
| 489 |
|
|
esac
|
| 490 |
|
|
eend 0
|
| 491 |
azarah |
302 |
fi
|
| 492 |
|
|
|
| 493 |
azarah |
456 |
# If booting off CD, we want to update inittab before setting the runlevel
|
| 494 |
azarah |
458 |
if [ -f "/sbin/livecd-functions.sh" -a -n "${CDBOOT}" ]
|
| 495 |
azarah |
456 |
then
|
| 496 |
|
|
ebegin "Updating inittab"
|
| 497 |
|
|
livecd_fix_inittab
|
| 498 |
|
|
eend $?
|
| 499 |
|
|
/sbin/telinit q &>/dev/null
|
| 500 |
|
|
fi
|
| 501 |
|
|
|
| 502 |
azarah |
652 |
# Clear $svcdir from stale entries, but leave the caches around, as it
|
| 503 |
|
|
# should help speed things up a bit
|
| 504 |
|
|
rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
|
| 505 |
|
|
grep -ve '\(depcache\|deptree\|envcache\)')
|
| 506 |
azarah |
306 |
|
| 507 |
azarah |
297 |
# Update the dependency cache
|
| 508 |
vapier |
624 |
/sbin/depscan.sh -u
|
| 509 |
azarah |
297 |
|
| 510 |
|
|
# Now that the dependency cache are up to date, make sure these
|
| 511 |
|
|
# are marked as started ...
|
| 512 |
azarah |
389 |
(
|
| 513 |
|
|
# Needed for mark_service_started()
|
| 514 |
|
|
source "${svclib}/sh/rc-services.sh"
|
| 515 |
|
|
|
| 516 |
|
|
for x in ${CRITICAL_SERVICES}
|
| 517 |
|
|
do
|
| 518 |
|
|
mark_service_started "${x}"
|
| 519 |
|
|
done
|
| 520 |
|
|
)
|
| 521 |
azarah |
85 |
|
| 522 |
vapier |
649 |
# If the user's /dev/null or /dev/console are missing, we
|
| 523 |
|
|
# should help them out and explain how to rectify the situation
|
| 524 |
|
|
if [ ${dev_null} -eq 0 -o ${dev_console} -eq 0 ] \
|
| 525 |
|
|
&& [ -e /usr/share/baselayout/issue.devfix ]
|
| 526 |
|
|
then
|
| 527 |
|
|
# Backup current /etc/issue
|
| 528 |
|
|
if [ -e /etc/issue -a ! -e /etc/issue.devfix ]
|
| 529 |
|
|
then
|
| 530 |
|
|
mv /etc/issue /etc/issue.devfix
|
| 531 |
|
|
fi
|
| 532 |
|
|
|
| 533 |
|
|
cp /usr/share/baselayout/issue.devfix /etc/issue
|
| 534 |
|
|
fi
|
| 535 |
|
|
|
| 536 |
vapier |
611 |
# Setup login records ... this has to be done here because when
|
| 537 |
|
|
# we exit this runlevel, init will write a boot record to utmp
|
| 538 |
vapier |
630 |
# If /var/run is readonly, then print a warning, not errors
|
| 539 |
vapier |
703 |
if touch /var/run/utmp 2>/dev/null
|
| 540 |
vapier |
630 |
then
|
| 541 |
|
|
> /var/run/utmp
|
| 542 |
|
|
touch /var/log/wtmp
|
| 543 |
|
|
chgrp utmp /var/run/utmp /var/log/wtmp
|
| 544 |
|
|
chmod 0664 /var/run/utmp /var/log/wtmp
|
| 545 |
|
|
# Remove /var/run/utmpx (bug from the past)
|
| 546 |
|
|
rm -f /var/run/utmpx
|
| 547 |
|
|
else
|
| 548 |
|
|
ewarn "Skipping /var/run/utmp initialization (ro root?)"
|
| 549 |
|
|
fi
|
| 550 |
vapier |
611 |
|
| 551 |
azarah |
388 |
exit 0
|
| 552 |
agriffis |
539 |
fi # Sysinit ends here
|
| 553 |
azarah |
388 |
|
| 554 |
agriffis |
539 |
if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "boot" ]
|
| 555 |
azarah |
388 |
then
|
| 556 |
azarah |
389 |
setup_defaultlevels
|
| 557 |
azarah |
388 |
|
| 558 |
azarah |
389 |
if [ -n "${DEFAULTLEVEL}" -a "${DEFAULTLEVEL}" != "default" ]
|
| 559 |
azarah |
388 |
then
|
| 560 |
azarah |
389 |
# Setup our default runlevel runlevel that will be run
|
| 561 |
|
|
# the first time /sbin/rc is called with argv1 != sysinit|boot
|
| 562 |
|
|
echo "${DEFAULTLEVEL}" > "${svcdir}/ksoftlevel"
|
| 563 |
azarah |
388 |
fi
|
| 564 |
|
|
|
| 565 |
azarah |
297 |
# $BOOT can be used by rc-scripts to test if it is the first time
|
| 566 |
|
|
# the 'boot' runlevel is executed
|
| 567 |
|
|
export BOOT="yes"
|
| 568 |
azarah |
417 |
|
| 569 |
azarah |
388 |
# We reset argv1 to the bootlevel given on the kernel command line
|
| 570 |
vapier |
560 |
# if there is one
|
| 571 |
azarah |
388 |
argv1="${BOOTLEVEL}"
|
| 572 |
|
|
|
| 573 |
|
|
elif [ "${RUNLEVEL}" != "S" -a -e "${svcdir}/ksoftlevel" ]
|
| 574 |
azarah |
297 |
then
|
| 575 |
azarah |
388 |
argv1="$(< ${svcdir}/ksoftlevel)"
|
| 576 |
|
|
rm -f "${svcdir}/ksoftlevel"
|
| 577 |
azarah |
297 |
fi
|
| 578 |
|
|
|
| 579 |
azarah |
360 |
source "${svclib}/sh/rc-services.sh"
|
| 580 |
|
|
source "${svclib}/sh/rc-daemon.sh"
|
| 581 |
azarah |
359 |
|
| 582 |
azarah |
352 |
if [ -f "${svcdir}/softlevel" ]
|
| 583 |
|
|
then
|
| 584 |
|
|
# Set OLDSOFTLEVEL if we had a valid SOFTLEVEL
|
| 585 |
azarah |
359 |
export OLDSOFTLEVEL="$(< ${svcdir}/softlevel)"
|
| 586 |
azarah |
352 |
else
|
| 587 |
|
|
export OLDSOFTLEVEL=
|
| 588 |
|
|
fi
|
| 589 |
|
|
|
| 590 |
azarah |
144 |
if [ -z "${argv1}" ]
|
| 591 |
azarah |
85 |
then
|
| 592 |
azarah |
297 |
if [ -f "${svcdir}/softlevel" ]
|
| 593 |
azarah |
137 |
then
|
| 594 |
azarah |
359 |
export SOFTLEVEL="$(< ${svcdir}/softlevel)"
|
| 595 |
azarah |
137 |
else
|
| 596 |
azarah |
388 |
export SOFTLEVEL="${BOOTLEVEL}"
|
| 597 |
azarah |
137 |
fi
|
| 598 |
azarah |
69 |
else
|
| 599 |
azarah |
144 |
export SOFTLEVEL="${argv1}"
|
| 600 |
azarah |
69 |
fi
|
| 601 |
drobbins |
2 |
|
| 602 |
azarah |
297 |
if [ ! -f "${svcdir}/softlevel" ]
|
| 603 |
azarah |
157 |
then
|
| 604 |
azarah |
297 |
echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
|
| 605 |
azarah |
157 |
fi
|
| 606 |
|
|
|
| 607 |
azarah |
297 |
# For keeping a list of services that fails during boot/halt
|
| 608 |
|
|
if [ ! -d "${svcdir}/failed" ]
|
| 609 |
azarah |
137 |
then
|
| 610 |
azarah |
462 |
mkdir -p -m 0755 "${svcdir}/failed"
|
| 611 |
azarah |
137 |
else
|
| 612 |
azarah |
297 |
rm -rf "${svcdir}"/failed/*
|
| 613 |
azarah |
137 |
fi
|
| 614 |
|
|
|
| 615 |
agriffis |
539 |
splash "rc_init" "${argv1}"
|
| 616 |
|
|
|
| 617 |
azarah |
241 |
if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ]
|
| 618 |
drobbins |
2 |
then
|
| 619 |
azarah |
359 |
myscripts=
|
| 620 |
azarah |
346 |
|
| 621 |
azarah |
359 |
elif [ "${SOFTLEVEL}" = "single" ]
|
| 622 |
|
|
then
|
| 623 |
azarah |
389 |
get_critical_services
|
| 624 |
|
|
|
| 625 |
|
|
myscripts="${CRITICAL_SERVICES}"
|
| 626 |
azarah |
346 |
|
| 627 |
azarah |
297 |
elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ]
|
| 628 |
drobbins |
2 |
then
|
| 629 |
vapier |
681 |
eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting ..."
|
| 630 |
drobbins |
2 |
exit 1
|
| 631 |
|
|
else
|
| 632 |
azarah |
359 |
myscripts=
|
| 633 |
azarah |
388 |
if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
|
| 634 |
drobbins |
2 |
then
|
| 635 |
azarah |
297 |
# Normal runlevels *include* boot scripts
|
| 636 |
|
|
mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
|
| 637 |
azarah |
388 |
mylevels="${mylevels} $(dolisting /etc/runlevels/${BOOTLEVEL}/)"
|
| 638 |
drobbins |
2 |
else
|
| 639 |
azarah |
297 |
# Non-normal runlevels don't include boot scripts as default
|
| 640 |
|
|
mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
|
| 641 |
drobbins |
2 |
fi
|
| 642 |
azarah |
359 |
|
| 643 |
azarah |
388 |
[ "${OLDSOFTLEVEL}" = "${BOOTLEVEL}" -o "${OLDSOFTLEVEL}" = "single" ] \
|
| 644 |
azarah |
359 |
&& /bin/dmesg -n 1
|
| 645 |
|
|
|
| 646 |
azarah |
144 |
for x in ${mylevels}
|
| 647 |
drobbins |
2 |
do
|
| 648 |
azarah |
359 |
[ -L "${x}" ] && myscripts="${myscripts} ${x##*/}"
|
| 649 |
drobbins |
2 |
done
|
| 650 |
|
|
fi
|
| 651 |
|
|
|
| 652 |
azarah |
297 |
# The softscripts dir contains all scripts that belong to the
|
| 653 |
azarah |
241 |
# runlevel specified in ${svcdir}/softlevel
|
| 654 |
azarah |
297 |
# It needs to be a new directory, else when stopping the services
|
| 655 |
azarah |
241 |
# and the old directory is not intact, things get broken
|
| 656 |
drobbins |
2 |
|
| 657 |
azarah |
462 |
mkdir -p -m 0755 "${svcdir}/softscripts.new"
|
| 658 |
drobbins |
2 |
|
| 659 |
azarah |
1058 |
for x in ${myscripts} ; do
|
| 660 |
|
|
if [[ ! -e /etc/init.d/${x} ]] ; then
|
| 661 |
vapier |
681 |
ewarn "WARNING: /etc/init.d/${x} missing; skipping ..."
|
| 662 |
drobbins |
2 |
continue
|
| 663 |
|
|
fi
|
| 664 |
vapier |
560 |
# The -f eliminates a warning if the symlink already exists,
|
| 665 |
azarah |
241 |
# which can happen if a service is in both the boot level and
|
| 666 |
|
|
# the current "normal" runlevel
|
| 667 |
azarah |
297 |
ln -snf "/etc/init.d/${x}" "${svcdir}/softscripts.new/${x}"
|
| 668 |
drobbins |
2 |
done
|
| 669 |
|
|
|
| 670 |
azarah |
1058 |
get_stop_services() {
|
| 671 |
|
|
local x list
|
| 672 |
|
|
|
| 673 |
|
|
for x in $(dolisting "${svcdir}/started/") ; do
|
| 674 |
|
|
list="${list} ${x##*/}"
|
| 675 |
|
|
done
|
| 676 |
|
|
|
| 677 |
|
|
reverse_list $(trace_dependencies ${list})
|
| 678 |
|
|
}
|
| 679 |
|
|
|
| 680 |
azarah |
124 |
dep_stop() {
|
| 681 |
azarah |
1058 |
local x dep needsme depservice
|
| 682 |
|
|
local myservice=${1##*/}
|
| 683 |
azarah |
389 |
|
| 684 |
azarah |
1058 |
service_stopped "${myservice}" && return 0
|
| 685 |
azarah |
359 |
|
| 686 |
azarah |
1058 |
# Candidate for zapping ?
|
| 687 |
|
|
[[ ! -L ${svcdir}/softscripts.new/${myservice} ]] || \
|
| 688 |
|
|
return 0
|
| 689 |
|
|
|
| 690 |
|
|
# If this is a 'net' service, we do not want to stop it if it was
|
| 691 |
|
|
# not in the previous runlevel, and we are not shutting down,
|
| 692 |
|
|
# rebooting or going to single runlevel. This is because the user
|
| 693 |
|
|
# (or hotplut) might have started it (net.ppp?) ...
|
| 694 |
|
|
if net_service "${myservice}" && \
|
| 695 |
|
|
[[ ${SOFTLEVEL} != "reboot" && \
|
| 696 |
|
|
${SOFTLEVEL} != "shutdown" && \
|
| 697 |
|
|
${SOFTLEVEL} != "single" ]] ; then
|
| 698 |
|
|
if [[ -z ${OLDSOFTLEVEL} ]] || \
|
| 699 |
|
|
! in_runlevel "${myservice}" "${OLDSOFTLEVEL}"
|
| 700 |
azarah |
352 |
then
|
| 701 |
azarah |
1058 |
# This service is not in the previous runlevel, so
|
| 702 |
|
|
# do not stop it ...
|
| 703 |
|
|
return 0
|
| 704 |
azarah |
352 |
fi
|
| 705 |
azarah |
1058 |
fi
|
| 706 |
azarah |
124 |
|
| 707 |
azarah |
1058 |
# Should not work for 'use'
|
| 708 |
|
|
if [[ -z $(needsme "${myservice}") ]] ; then
|
| 709 |
|
|
# Nothing depends on me
|
| 710 |
|
|
stop_service "${myservice}"
|
| 711 |
|
|
else
|
| 712 |
|
|
# Something may depend on me
|
| 713 |
|
|
needsme=0
|
| 714 |
|
|
|
| 715 |
|
|
for dep in $(needsme "${myservice}") ; do
|
| 716 |
|
|
if service_started "${dep}" && \
|
| 717 |
|
|
[[ -L "${svcdir}/softscripts.new/${dep}" ]] ; then
|
| 718 |
|
|
# This dep is valid
|
| 719 |
|
|
needsme=1
|
| 720 |
|
|
|
| 721 |
|
|
break
|
| 722 |
drobbins |
2 |
fi
|
| 723 |
azarah |
1058 |
done
|
| 724 |
|
|
|
| 725 |
|
|
[[ ${needsme} -eq 0 ]] && stop_service "${myservice}"
|
| 726 |
drobbins |
2 |
fi
|
| 727 |
azarah |
124 |
}
|
| 728 |
|
|
|
| 729 |
azarah |
297 |
# Stop services
|
| 730 |
azarah |
1058 |
if [[ ${SOFTLEVEL} != "single" && \
|
| 731 |
|
|
${SOFTLEVEL} != "reboot" && \
|
| 732 |
vapier |
1166 |
${SOFTLEVEL} != "shutdown" ]]
|
| 733 |
|
|
then
|
| 734 |
azarah |
1058 |
for i in $(get_stop_services) ; do
|
| 735 |
azarah |
389 |
dep_stop "${i}"
|
| 736 |
|
|
done
|
| 737 |
|
|
else
|
| 738 |
|
|
get_critical_services
|
| 739 |
drobbins |
2 |
|
| 740 |
azarah |
389 |
is_critical_service() {
|
| 741 |
azarah |
1058 |
local x
|
| 742 |
|
|
local myservice=${1##*/}
|
| 743 |
azarah |
389 |
|
| 744 |
azarah |
1058 |
for x in ${CRITICAL_SERVICES} ${LOGGER_SERVICE} ; do
|
| 745 |
|
|
[[ ${myservice} == "${x}" ]] && return 0
|
| 746 |
azarah |
389 |
done
|
| 747 |
|
|
|
| 748 |
|
|
return 1
|
| 749 |
|
|
}
|
| 750 |
|
|
|
| 751 |
|
|
# First stop non critical services
|
| 752 |
azarah |
1058 |
for i in $(get_stop_services) ; do
|
| 753 |
azarah |
399 |
is_critical_service "${i}" || dep_stop "${i}"
|
| 754 |
azarah |
389 |
done
|
| 755 |
|
|
|
| 756 |
|
|
# Now stop the rest
|
| 757 |
azarah |
1058 |
for i in $(get_stop_services) ; do
|
| 758 |
azarah |
389 |
dep_stop "${i}"
|
| 759 |
|
|
done
|
| 760 |
|
|
fi
|
| 761 |
|
|
|
| 762 |
drobbins |
51 |
# Only change softlevel AFTER all the services have been stopped,
|
| 763 |
|
|
# else they will not get the depend's right (wrong SOFTLEVEL)
|
| 764 |
azarah |
85 |
|
| 765 |
azarah |
297 |
echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
|
| 766 |
drobbins |
2 |
|
| 767 |
azarah |
1058 |
if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then
|
| 768 |
azarah |
161 |
source /sbin/functions.sh
|
| 769 |
azarah |
419 |
|
| 770 |
azarah |
652 |
# Clear $svcdir from stale entries, but leave the caches around, as it
|
| 771 |
|
|
# should help speed things up a bit
|
| 772 |
|
|
rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
|
| 773 |
|
|
grep -ve '\(depcache\|deptree\|envcache\)')
|
| 774 |
azarah |
297 |
|
| 775 |
drobbins |
2 |
source /etc/init.d/halt.sh
|
| 776 |
azarah |
297 |
|
| 777 |
azarah |
1058 |
if [[ ${SOFTLEVEL} == "reboot" ]] ; then
|
| 778 |
vapier |
560 |
source /etc/init.d/reboot.sh
|
| 779 |
drobbins |
2 |
else
|
| 780 |
|
|
source /etc/init.d/shutdown.sh
|
| 781 |
|
|
fi
|
| 782 |
azarah |
359 |
|
| 783 |
azarah |
297 |
# Should never get here
|
| 784 |
azarah |
163 |
exit 0
|
| 785 |
drobbins |
2 |
fi
|
| 786 |
|
|
|
| 787 |
azarah |
297 |
# Move the old softscritps directory to a different one
|
| 788 |
azarah |
241 |
# and make the new softscripts directory the current
|
| 789 |
azarah |
85 |
|
| 790 |
azarah |
297 |
mv -f "${svcdir}/softscripts" "${svcdir}/softscripts.old"
|
| 791 |
|
|
mv -f "${svcdir}/softscripts.new" "${svcdir}/softscripts"
|
| 792 |
drobbins |
51 |
|
| 793 |
azarah |
1058 |
get_start_services() {
|
| 794 |
|
|
local x list
|
| 795 |
azarah |
359 |
|
| 796 |
azarah |
1058 |
get_critical_services
|
| 797 |
|
|
list=${CRITICAL_SERVICES}
|
| 798 |
azarah |
359 |
|
| 799 |
azarah |
1058 |
[[ -n ${LOGGER_SERVICE} && \
|
| 800 |
|
|
-L ${svcdir}/softscripts/${LOGGER_SERVICE} ]] && \
|
| 801 |
|
|
list="${list} ${LOGGER_SERVICE}"
|
| 802 |
azarah |
143 |
|
| 803 |
azarah |
1058 |
for x in $(dolisting "${svcdir}/softscripts/") ; do
|
| 804 |
|
|
list="${list} ${x##*/}"
|
| 805 |
|
|
done
|
| 806 |
azarah |
389 |
|
| 807 |
azarah |
1058 |
trace_dependencies ${list}
|
| 808 |
|
|
}
|
| 809 |
azarah |
389 |
|
| 810 |
azarah |
1058 |
dep_start() {
|
| 811 |
|
|
local myservice="${1##*/}"
|
| 812 |
azarah |
389 |
|
| 813 |
azarah |
1058 |
[[ ! -L ${svcdir}/softscripts/${myservice} ]] && continue
|
| 814 |
azarah |
389 |
|
| 815 |
azarah |
1058 |
# Only start a script if it isn't already running
|
| 816 |
|
|
service_started "${myservice}" || \
|
| 817 |
|
|
schedule_service_startup "${myservice}"
|
| 818 |
|
|
}
|
| 819 |
|
|
|
| 820 |
azarah |
297 |
# Start scripts
|
| 821 |
azarah |
1058 |
for i in $(get_start_services) ; do
|
| 822 |
azarah |
420 |
dep_start "${i##*/}"
|
| 823 |
drobbins |
2 |
done
|
| 824 |
|
|
|
| 825 |
azarah |
359 |
# Wait for any services that may still be running ...
|
| 826 |
|
|
[ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait
|
| 827 |
|
|
|
| 828 |
azarah |
297 |
# Clean the old runlevel
|
| 829 |
vapier |
703 |
rm -rf "${svcdir}/softscripts.old" &>/dev/null
|
| 830 |
azarah |
125 |
|
| 831 |
azarah |
297 |
# Depends gets nuked, so update them
|
| 832 |
azarah |
241 |
# (this problem should be solved now, but i think it will be a good idea
|
| 833 |
|
|
# to recreate the deps after a change in runlevel)
|
| 834 |
azarah |
85 |
|
| 835 |
azarah |
161 |
#/sbin/depscan.sh &>/dev/null
|
| 836 |
drobbins |
51 |
|
| 837 |
azarah |
297 |
# We want devfsd running after a change of runlevel (this is mostly if we return
|
| 838 |
azarah |
241 |
# from runlevel 'single')
|
| 839 |
azarah |
330 |
if [ -z "`ps --no-heading -C 'devfsd'`" -a \
|
| 840 |
vapier |
703 |
-n "`gawk '/\/dev devfs/ { print }' /proc/mounts 2>/dev/null`" ]
|
| 841 |
drobbins |
65 |
then
|
| 842 |
azarah |
396 |
if [ "${RC_DEVFSD_STARTUP}" != "no" ]
|
| 843 |
|
|
then
|
| 844 |
vapier |
703 |
/sbin/devfsd /dev &>/dev/null
|
| 845 |
azarah |
396 |
fi
|
| 846 |
drobbins |
65 |
fi
|
| 847 |
|
|
|
| 848 |
azarah |
297 |
# Runlevel end, so clear stale fail list
|
| 849 |
vapier |
703 |
rm -rf "${svcdir}/failed" &>/dev/null
|
| 850 |
azarah |
137 |
|
| 851 |
azarah |
297 |
# If we were in the boot runlevel, it is done now ...
|
| 852 |
azarah |
144 |
[ -n "${BOOT}" ] && unset BOOT
|
| 853 |
azarah |
71 |
|
| 854 |
agriffis |
539 |
splash "rc_exit"
|
| 855 |
azarah |
419 |
|
| 856 |
azarah |
144 |
# vim:ts=4
|