rc.cygwinxp 3.12 KB
Newer Older
1
2
3
#!/bin/bash
#
# EMULAB-COPYRIGHT
Mike Hibler's avatar
Mike Hibler committed
4
# Copyright (c) 2004, 2005 University of Utah and the Flux Group.
5
6
# All rights reserved.
#
7
# rc.cygwinxp - CygWin-specific startup.  Run by rc.bootsetup on CygWin.
8

Russ Fish's avatar
Russ Fish committed
9
10
11
PATH=/usr/local/etc/emulab:/bin:$SYSTEMROOT/system32:$PATH
export PATH

12
# Enable logging.
Russ Fish's avatar
Russ Fish committed
13
logfile=/var/log/EmulabStartup.log
14
15
16
17
chmod -f g+w $logfile

# Enable WINDOWS() in libsetup.pm .
iscygwin=/etc/emulab/iscygwin
18
chmod -f g+w /etc/emulab
19
20
21
chmod -f g+w $iscygwin
uname -r > $iscygwin
chmod g+w $iscygwin
22
chmod -f g-w /etc/emulab
23
24

# Make sure the computer name is right, reboots to change it if necessary.
Russ Fish's avatar
Russ Fish committed
25
nodeid=`tmcc nodeid`
26
hostname=`/bin/hostname`
Russ Fish's avatar
Russ Fish committed
27
datehost="`date`: Host name '$hostname'"
Mike Hibler's avatar
Mike Hibler committed
28
if [ $nodeid = $hostname ]; then
Russ Fish's avatar
Russ Fish committed
29
30
31
    msg="$datehost matches nodeid '$nodeid'."
    echo "$msg" >> $logfile
    echo "$msg"
32
else
Russ Fish's avatar
Russ Fish committed
33
34
35
    msg="$datehost differs from nodeid '$nodeid'." >> $logfile
    echo "$msg" >> $logfile
    echo "$msg"
36
37
38

    # Change hostname and computername, rename My Computer, reboot on success.
    /usr/local/etc/emulab/WSName /N:$nodeid /REBOOT /MCN
39
40
41
    # Does WSName return to the shell?  Log it and give it a minute to take effect.
    datehost="`date`: Host name '$hostname'"
    newhost=`/bin/hostname`
Russ Fish's avatar
Russ Fish committed
42
    msg="$datehost WSName returned to shell as '$newhost' after WSName '$nodeid'."
43
44
45
    echo "$msg" >> $logfile
    echo "$msg"
    sleep 60
Russ Fish's avatar
Russ Fish committed
46

Mike Hibler's avatar
Mike Hibler committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#    # Should never get here!  Try /sbin/reboot.
#    datehost="`date`: Host name '$hostname'"
#    msg="$datehost didn't reboot changing to '$nodeid'!  Trying reboot."
#    echo "$msg" >> $logfile
#    echo "$msg"
#    /sbin/reboot
#    # Reboot returns to the shell.  Give it a few seconds to take effect.
#    sleep 10
#
#    # Should never get here either!!  Try /bin/shutdown.
#    datehost="`date`: Host name '$hostname'"
#    msg="$datehost didn't /sbin/reboot changing to '$nodeid'!  Trying shutdown."
#    echo "$msg" >> $logfile
#    echo "$msg"
#    /bin/shutdown -r -f now
#    # Shutdown returns to the shell.  Give it a few seconds to take effect.
#    sleep 10
Russ Fish's avatar
Russ Fish committed
64
65
66

    # Last resort!!!  tsshutdn
    datehost="`date`: Host name '$hostname'"
67
68
#    msg="$datehost didn't /bin/shutdown changing to '$nodeid'!  Trying tsshutdn."
    msg="$datehost didn't reboot changing to '$nodeid'!  Trying reboot."
Russ Fish's avatar
Russ Fish committed
69
70
71
72
73
    echo "$msg" >> $logfile
    echo "$msg"
    tsshutdn 1 /REBOOT /DELAY:1
    # Shutdown shouldn't return to the shell.  Give it a few seconds to take effect.
    sleep 10
Russ Fish's avatar
Russ Fish committed
74

75
    # Give up, log it, and go on.
Russ Fish's avatar
Russ Fish committed
76
    datehost="`date`: Host name '$hostname'"
Russ Fish's avatar
Russ Fish committed
77
    msg="$datehost failed to reboot changing to '$nodeid'."
Russ Fish's avatar
Russ Fish committed
78
79
    echo "$msg" >> $logfile
    echo "$msg"
80
fi
81
82
83
84
85
86

# Sometimes the network stack gets out of sync: 'ipconfig /all' reports different
# status on the interfaces than 'netsh interface show interface'.  This might help.
netsh interface reset all

# Windows DHCP doesn't make a /etc/resolv.h, which tmcc needs for bossinfo.
87
# Make one from ipconfig output.
88
89
90
ipconfig /all | awk \
    '/^ *Connection-specific DNS Suffix/{print "search", $NF} \
     /^ *DNS Servers/{print "nameserver", $NF}' > /etc/resolv.conf
Russ Fish's avatar
Russ Fish committed
91
92
93

# Start up the service which will deliver a SHUTDOWN state event on reboot.
cygrunsrv -S EmulabShutdown