fb6bd596bf
Change-Id: I46e335d5dac49104028d7cb0706b3e85de752bfe
86 lines
1.6 KiB
Bash
Executable file
86 lines
1.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# Recovery script for INET/lwip. It restarts daemons dependent on it in order
|
|
# to recover TCP state.
|
|
|
|
kill_by_name()
|
|
{
|
|
label="$1"
|
|
pid=`ps ax | grep "$label" | grep -v grep | sed 's,[ ]*\([0-9]*\).*,\1,'`
|
|
if [ X"$pid" = X ]
|
|
then
|
|
return 1 # No such process
|
|
fi
|
|
echo "killing pid $pid for $label"
|
|
kill -9 $pid
|
|
}
|
|
|
|
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
|
|
|
|
echo -n " $name"
|
|
"$@" &
|
|
return
|
|
fi
|
|
done
|
|
}
|
|
|
|
disabled()
|
|
{
|
|
ifs="$IFS"; IFS=,
|
|
for skip in `sysenv disable`
|
|
do
|
|
if [ "$skip" = "$1" ]
|
|
then
|
|
IFS="$ifs"; unset ifs
|
|
return 0
|
|
fi
|
|
done
|
|
IFS="$ifs"; unset ifs
|
|
return 1
|
|
}
|
|
|
|
exec > /dev/console
|
|
echo "Arguments: $@"
|
|
|
|
restarts=$(grep restarts /proc/service/$1 |cut -d: -f2)
|
|
restarts=$(( $restarts + 1 ))
|
|
service down "$1"
|
|
kill_by_name dhcpd
|
|
kill_by_name nonamed
|
|
kill_by_name syslogd
|
|
|
|
# Wait a moment to let daemons clean themselves up
|
|
sleep 3
|
|
if [ X`/bin/sysenv lwip` = Xyes ]
|
|
then
|
|
service up /service/lwip -script /etc/rs.inet -dev /dev/ip -restarts $restarts
|
|
dhcpd --lwip &
|
|
else
|
|
service up /service/inet -script /etc/rs.inet -dev /dev/ip -restarts $restarts
|
|
daemonize dhcpd
|
|
fi
|
|
daemonize nonamed -L
|
|
daemonize syslogd
|
|
|
|
# Restart SSH daemon if installed and running
|
|
if [ -f /usr/pkg/etc/rc.d/sshd ]
|
|
then
|
|
/usr/pkg/etc/rc.d/sshd status | grep -v not > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
/usr/pkg/etc/rc.d/sshd restart
|
|
fi
|
|
fi
|