From: Greg Ercolano <erco@(email surpressed)>
Subject: [Q+A] Rush not starting on boot due to errors: "localhost" / 127.0.0.1
   Date: Tue, 23 Jun 2015 15:46:07 -0400
Msg# 2394
View Complete Thread (1 article) | All Threads
Last Next
> The rush service doesn't start after reboot on some of our machines (windows),
> sometimes giving errors in the Rushd.log about:
>
>     o The machine's localhost being "localhost" (instead of its actual hostname)
>     o The machine's IP address being 169.x.x.x (instead of its actual network IP)
>     o The machine's IP address being 127.0.0.1 (instead of its actual network IP)
>
> We have a mix of windows machines using workgroups + static ip's (which don't have this problem)
> and some machines either managed by a Windows Domain or DHCP with static IPs locked to MACs.
> We just restart the service and it works fine, wondering if there's a better solution.

    Yes, this happens when the network interface isn't fully "up", but Windows
    has started the Rushd service anyway.

    When rush installs, it tries to configure itself to be dependent on Window's networking
    being fully up, but it sometimes doesn't prevent the issue, causing Rushd to start and fail
    when it realizes there's a non-network IP or hostname.

    In Rush 103, you can setup a 'bootcheck' script that is run just before Rushd initializes
    to first make sure the state of the machine is ready.

    The script does this by looping until all problems have cleared, e.g. checking the
    machine's hostname + IP. It can also check if drives are mounted or mapped, and
    can run commands to attempt to fix problems if possible. The script should simply
    loop until the machine is ready, and exit(0) when all the problems have cleared.

    To set up a bootcheck script in rush 103:



        1) Edit the existing example bootcheck script that is in:

            WINDOWS: c:\rush\etc\bootcheck
            UNIX: /usr/local/rush/etc/bootcheck

           Add any logic you want that checks the machine's state, and to loop
           until the machine is "ready".

           See an example script (below) that checks to make sure the machine's
           IP and hostname are valid.

        2) Verify the script works by running it interactively.

           e.g. from a DOS or unix shell, run:


                WINDOWS: perl c:/rush/etc/bootcheck
                   UNIX: perl /usr/local/rush/etc/bootcheck

           The script should simply exit(0) if everything is fine.
           Any error messages should be redirected to a log, preferably
           the rushd.log. (See the example below for how to do this)

           NOTE: The script does NOT have to be a perl script, it can be
           python, ruby, bash, sh, or any scripting language. Just be sure
           to change the bootcheck_cmd accordingly.

        3) Push the modified bootcheck script to the network by running:

                rush -push bootcheck +any

        4) Enable this script in the rush.conf file.
           Just uncomment these two lines:

#os=windows bootcheck_cmd "perl c:/rush/etc/bootcheck"
#os=unix    bootcheck_cmd "perl /usr/local/rush/etc/bootcheck"

           ..and then run 'rush -checkconf' to make sure your changes
           to the rush.conf file didn't break anything.

           NOTE: If you decided to write a python script, change "perl"
           in the above lines to "python" instead. Or ruby, bash, DOS Batch..
           whatever is appropriate.

        5) Push the changed rush.conf file to the network. Use:

           
      rush -push rush.conf +any



Now when a machine reboots, it will run the bootcheck script before rush starts.
Any messages your script prints should appear in the rushd.log file.

What follows is an example bootcheck script that makes sure the machine's hostname
and IP are valid. Feel free to change to taste. This example should work on both Windows
and Unix equally:


#!/usr/bin/perl

# BOOT CHECK SCRIPT
#
#    This script is run just before rushd initializes itself.
#    Configure this script to run via the rush.conf file's 'bootcheck_cmd':
#    http://seriss.com/rush.103.00/rush/rush-bootcheck.html
#
#    This example checks to make sure the machine has a valid network IP
#    and hostname, looping until any problems self-correct.
#

use Socket;    # inet_ntoa()


# RETURN LOCAL MACHINE'S HOSTNAME
sub GetHostname() {
    my $hostname = `hostname`; chomp($hostname);
    return $hostname;
}

# RETURN IP ADDRESS STRING FOR GIVEN HOSTNAME
#    May return "" if none.
#
sub Hostname2IP($) {
    my $hostname = $_[0];
    ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($hostname);
    if ( $#addrs == -1 ) { return(""); }
    return inet_ntoa($addrs[0]);
}

### MAIN

# REDIRECT STDIO TO RUSHD.LOG
if ( -d "c:/" ) {    # WINDOWS
    open STDOUT, '>>', "c:/rush/var/rushd.log";
    open STDERR, '>>', "c:/rush/var/rushd.log";
} else {             # UNIX
    open STDOUT, '>>', "/usr/local/rush/var/rushd.log";
    open STDERR, '>>', "/usr/local/rush/var/rushd.log";
}
while ( 1 ) {
    # GET LOCAL HOSTNAME
    my $hostname = GetHostname();
    print "--- BOOTCHECK: HOSTNAME: '$hostname'\n";

    # GET LOCAL HOST'S IP ADDRESS
    my $ip = Hostname2IP($hostname);
    print "--- BOOTCHECK:  IP ADDR: '$ip'\n";

    # CHECK FOR PROBLEMS..
    if ( $hostname =~ /^localhost/i || $hostname eq "" ) {
        print "--- BOOTCHECK: Waiting 3 secs for proper hostname\n";
        sleep(3);
        next;
    }
    if ( $ip eq "127.0.0.1" || $ip =~ "^169\." ) {
        print "--- BOOTCHECK: Waiting 3 secs for proper network IP address\n";
        sleep(3);
        next;
    }

    # PASSED
    last;
}

print "--- BOOTCHECK: DONE/OK\n";
exit(0);




Last Next