minix/etc/usr/rc

203 lines
4.2 KiB
Text
Raw Normal View History

2005-04-25 15:50:26 +02:00
# /usr/etc/rc - continued system initialization.
2005-08-02 17:46:24 +02:00
RANDOM_FILE=/usr/adm/random.dat
LOCAL_FILE=/usr/etc/rc.local
2005-08-02 17:46:24 +02:00
2005-04-25 15:50:26 +02:00
case "$#:$1" in
1:start|1:stop|1:down)
action=$1
;;
*) echo >&2 "Usage: $0 start|stop|down"
exit 1
esac
if [ -f "$LOCAL_FILE" ]
then . "$LOCAL_FILE" $1
fi
disabled()
{
ifs="$IFS"; IFS=,
2005-08-04 19:00:18 +02:00
for skip in `sysenv disable`
do
2005-08-04 19:00:18 +02:00
if [ "$skip" = "$1" ]
then
IFS="$ifs"; unset ifs
return 0
fi
done
IFS="$ifs"; unset ifs
return 1
}
2005-04-25 15:50:26 +02:00
daemonize()
{
# Function to start a daemon, if it exists.
local IFS=':'
local name="$1"
test "$1" = tcpd && name="$2"
for dir in $PATH
do
if [ -f "$dir/$1" ]
then
# check if this service is disabled at the boot monitor.
if disabled $name; then return; fi
2005-04-25 15:50:26 +02:00
echo -n " $name"
"$@" &
return
fi
done
}
2005-08-02 17:46:24 +02:00
up()
{
upopt " " "$@"
}
upopt()
{
opt=$1
shift
2005-08-02 17:46:24 +02:00
service=$1
2005-11-28 16:39:01 +01:00
shift
2005-08-02 17:46:24 +02:00
# Function to dynamically start a system service
# First check if this service is disabled at the boot monitor.
if disabled $service; then return; fi
2005-08-02 17:46:24 +02:00
# Service is not disabled. Try to bring it up.
echo -n " $service"
service $opt up /usr/sbin/$service "$@"
2005-08-02 17:46:24 +02:00
}
DAEMONS=/etc/rc.daemons
2005-04-25 15:50:26 +02:00
case $action in
start)
# Select console font.
test -f /etc/font && loadfont /etc/font </dev/console
# Cleanup.
rm -rf /tmp/. /usr/run/. /usr/spool/lpd/. /usr/spool/locks/.
# Start servers and drivers set at the boot monitor.
2005-08-11 15:22:31 +02:00
echo -n "Starting services:"
upopt -n random -dev /dev/random -devstyle STYLE_DEVA -period 3HZ
2005-08-03 17:22:41 +02:00
# load random number generator
if [ -f $RANDOM_FILE ]
then
cat < $RANDOM_FILE >/dev/random
# overwrite $RANDOM_FILE. We don't want to use this data again
dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
fi
# start only network drivers that are in use
for driver in lance rtl8139 rtl8169 fxp e1000 dpeth dp8390 orinoco atl2 dec21140A
do
if grep " $driver " /etc/inet.conf > /dev/null 2>&1
then
eval arg=\$${driver}_arg
2005-11-28 16:39:01 +01:00
if [ ! -z "$arg" ]; then arg="-args \"$arg\""; fi
eval up $driver $arg -period 5HZ
fi
done
upopt -n inet -script /etc/rs.inet -dev /dev/ip -devstyle STYLE_CLONE
upopt -n printer -dev /dev/lp -period 10HZ
upopt -n ipc
2005-08-02 17:46:24 +02:00
echo .
2005-04-25 15:50:26 +02:00
# Network initialization.
(: </dev/tcp) 2>/dev/null && net=t # Is there a TCP/IP server?
echo -n "Starting daemons:"
daemonize update
# Ugly error message when starting cron from CD.
# (and cron unnecessary then so..)
if [ ! -f /CD ]
2006-04-04 15:44:23 +02:00
then daemonize cron
2006-04-04 15:31:56 +02:00
else mkdir /tmp/log
2006-04-04 15:44:23 +02:00
rm -f /var/log || true
2006-04-04 15:31:56 +02:00
ln -s /tmp/log /var/log || true
. /etc/rc.cd
fi
2006-04-04 18:12:08 +02:00
# syslogd has not been started yet
2006-04-05 11:29:18 +02:00
rm -f /var/run/syslogd.pid
daemonize syslogd
echo .
2005-04-25 15:50:26 +02:00
if [ "$net" ]
then
if [ -f /etc/rc.net ]
then
# Let a customized TCP/IP initialization script figure it out.
. /etc/rc.net
else
# Standard network daemons.
echo -n "Starting networking:"
if grep -s 'psip0.*default' /etc/inet.conf
then ifconfig -h 10.0.0.1
Driver refactory for live update and crash recovery. SYSLIB CHANGES: - DS calls to publish / retrieve labels consider endpoints instead of u32_t. VFS CHANGES: - mapdriver() only adds an entry in the dmap table in VFS. - dev_up() is only executed upon reception of a driver up event. INET CHANGES: - INET no longer searches for existing drivers instances at startup. - A newtwork driver is (re)initialized upon reception of a driver up event. - Networking startup is now race-free by design. No need to waste 5 seconds at startup any more. DRIVER CHANGES: - Every driver publishes driver up events when starting for the first time or in case of restart when recovery actions must be taken in the upper layers. - Driver up events are published by drivers through DS. - For regular drivers, VFS is normally the only subscriber, but not necessarily. For instance, when the filter driver is in use, it must subscribe to driver up events to initiate recovery. - For network drivers, inet is the only subscriber for now. - Every VFS driver is statically linked with libdriver, every network driver is statically linked with libnetdriver. DRIVER LIBRARIES CHANGES: - Libdriver is extended to provide generic receive() and ds_publish() interfaces for VFS drivers. - driver_receive() is a wrapper for sef_receive() also used in driver_task() to discard spurious messages that were meant to be delivered to a previous version of the driver. - driver_receive_mq() is the same as driver_receive() but integrates support for queued messages. - driver_announce() publishes a driver up event for VFS drivers and marks the driver as initialized and expecting a DEV_OPEN message. - Libnetdriver is introduced to provide similar receive() and ds_publish() interfaces for network drivers (netdriver_announce() and netdriver_receive()). - Network drivers all support live update with no state transfer now. KERNEL CHANGES: - Added kernel call statectl for state management. Used by driver_announce() to unblock eventual callers sendrecing to the driver.
2010-04-08 15:41:35 +02:00
else
daemonize dhcpd
fi
2006-04-11 15:42:58 +02:00
daemonize nonamed -L
if [ -f "$DAEMONS" ]
then . "$DAEMONS"
fi
# The last daemon has been started, so close the list:
echo .
2005-04-25 15:50:26 +02:00
fi
fi
if [ "$net" ]
then
# Get the nodename from the DNS and set it.
trap '' 2
intr -t 20 hostaddr -h
2005-04-25 15:50:26 +02:00
trap 2
fi
# Recover files being edited when the system crashed.
test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
# Run the daily cleanup on systems that are not on at night.
test -f /usr/etc/daily && sh /usr/etc/daily boot &
;;
stop|down)
# Save random data, if /usr is mounted rw.
if grep ' \/usr .*rw' /etc/mtab >/dev/null
then
if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
then
mv $RANDOM_FILE.new $RANDOM_FILE
else
echo 'Failed to save random data.'
fi
fi
2005-04-25 15:50:26 +02:00
esac
d=/usr/local/etc/rc.d
# Let packages run their own scripts
if [ -d "$d" ]
then if cd $d
then
2006-02-20 16:11:41 +01:00
echo -n "Local packages ($action): "
for f in *
do
if [ -x "$f" ]
then echo -n "$f "
sh "$f" "$action"
fi
done
echo " done."
fi
fi