• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Changing IP address post fog install is problematic

Scheduled Pinned Locked Moved Solved
Bug Reports
5
27
11.8k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    Tom Elliott @george1421
    last edited by Dec 22, 2015, 1:22 PM

    @george1421 The impact would be more that if you have multiple storage nodes (multiple ip address and what not) how will we know which one to update?

    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

    Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

    Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

    G 1 Reply Last reply Dec 22, 2015, 3:12 PM Reply Quote 0
    • G
      george1421 Moderator @Tom Elliott
      last edited by george1421 Dec 22, 2015, 9:14 AM Dec 22, 2015, 3:12 PM

      @Tom-Elliott The probably the easiest solution is to create a procedure (wiki page) that if you need to update your fog server you need to do:

      1. Update the settings in the /opt/fog/.fogsettings
      2. Rerun the installer
      3. Update the IP address for the storage node on the FOG system where you changed the IP address
      4. Update the IP address on a any master storage node that may reference this FOG server
      5. Update the FOG_WEB_HOST value
      6. update the FOG_TFTP_HOST value

      I can I’ll marked this as addressed (Solved), since its not a technical solution but a procedural one that resolves the issue.
      [Edit] I would, but it appears I can no longer mark topics as solved[/Edit]

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

      W 1 Reply Last reply Jan 19, 2016, 4:42 AM Reply Quote 1
      • W
        Wayne Workman @george1421
        last edited by Wayne Workman Jan 18, 2016, 10:40 PM Dec 22, 2015, 5:05 PM

        @george1421 said:

        However this could be also addressed with a wiki page.

        I’m actually working on this. Here’s links for future readers:
        https://wiki.fogproject.org/wiki/index.php?title=Change_FOG_Server_IP_Address

        I’m going to work on that and a few other articles over my 2 week x-mas vacation. 🙂

        wiki

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
        Daily Clean Installation Results:
        https://fogtesting.fogproject.us/
        FOG Reporting:
        https://fog-external-reporting-results.fogproject.us/

        1 Reply Last reply Reply Quote 1
        • S
          sudburr
          last edited by sudburr Dec 22, 2015, 3:13 PM Dec 22, 2015, 8:46 PM

          In its simplest form that we run, some of our FOG servers are stationary, others move around. For us to have a single solution build that works for any location, all of our FOG servers are configured to grab an IP via external DHCP reservation.

          I copy and paste the following to the CLI to edit rc.local:

          cp -f /etc/rc.local /etc/rc.local.old
          if [ -f /etc/centos-release ]; then
          echo ' ' >> /etc/rc.local
          echo 'make_fog_portable' >> /etc/rc.local
          echo ' ' >> /etc/rc.local
          else
          sed -i "s|exit 0|make_fog_portable &|g" /etc/rc.local
          echo ' ' >> /etc/rc.local
          echo 'exit 0' >> /etc/rc.local
          fi
          chmod 755 /etc/rc.local
          echo '#!/bin/bash' > /bin/make_fog_portable
          echo '#' >> /bin/make_fog_portable
          echo '# make_fog_portable &' >> /bin/make_fog_portable
          echo '#' >> /bin/make_fog_portable
          echo '# This script is expected to be run as a job from /etc/rc.local' >> /bin/make_fog_portable
          echo '# It will wait until an IP address is found, then use that IP' >> /bin/make_fog_portable
          echo '# address to configure the FOG Server for that site.' >> /bin/make_fog_portable
          echo '#' >> /bin/make_fog_portable
          echo ' ' >> /bin/make_fog_portable
          echo 'exit 0' >> /bin/make_fog_portable
          chmod 755 /bin/make_fog_portable
          vim /bin/make_fog_portable
          

          At the now open file ‘make_fog_portable’ Insert the following, before “exit 0” ; [ESC]:wq to write/quit

          # Wait for an IP address
          IP=`ip addr list eth0 | grep "inet " |cut -d" " -f6|cut -d/ -f1`
          while [ -z $IP ]
          do
          	echo "Waiting :05 for an IP Address" > /dev/kmsg
          	sleep 5
          	IP=`ip addr list eth0 | grep "inet " |cut -d" " -f6|cut -d/ -f1`
          done
          
          # Make FOG Server Portable
          sleep 6
          echo "Updating IP address for FOG_TFTP_HOST to be $IP [`date`]" > /dev/kmsg
          mysql --user=root -e "UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_TFTP_HOST';" fog
          echo "Updating IP address for FOG_WEB_HOST to be $IP [`date`]" > /dev/kmsg
          mysql --user=root -e "UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WEB_HOST';" fog
          echo "Updating IP address for FOG_WOL_HOST to be $IP [`date`]" > /dev/kmsg
          mysql --user=root -e "UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WOL_HOST';" fog
          echo "Updating IP address for Storage Node DefaultMember to be $IP [`date`]" > /dev/kmsg
          mysql --user=root -e "UPDATE \`nfsGroupMembers\` SET \`ngmHostname\` = '$IP' WHERE \`ngmMemberName\` ='DefaultMember';" fog
          echo "Updating IP address in file .fogsettings to be $IP [`date`]" > /dev/kmsg
          sed -i "s|ipaddress=\".*\"|ipaddress=\"$IP\"|" /opt/fog/.fogsettings
          echo "Updating IP address in file default.ipxe to be $IP [`date`]" > /dev/kmsg
          sed -i "s|http://\([^/]\+\)/|http://$IP/|" /tftpboot/default.ipxe
          sed -i "s|http:///|http://$IP/|" /tftpboot/default.ipxe
          
          echo "Sleeping 10 seconds before releasing script [`date`]" > /dev/kmsg
          sleep 10
          echo "releasing script [`date`]" > /dev/kmsg
          

          Complete the generalization with this; you will also need to run this after any FOG trunk update:

          if [ -f /etc/debian_version ]; then
          cd /var/www/fog/lib/fog
          fi
          
          if [ -f /etc/centos-release ]; then
          cd /var/www/html/fog/lib/fog
          fi
          
          cp -f config.class.php config.class.php.old
          sed -i "s|\".*\..*\..*\..*\"|\$_SERVER['SERVER_ADDR']|" config.class.php
          reboot
          

          Why a job at startup? In the case of a power failure, the FOG server itself whether it be physical or virtual will almost invariably be available long before the site’s switches finish their POSTs and the network is available again. The loop to check for an IP prevents the FOG server coming up without an IP or in the case of a mobile server, forces the new IP into FOG’s configuration before it has a chance to start.

          This solution even allows us to change the subnet entirely and the server will always, automatically reconfigure itself according to the new DHCP reservation.

          Works like a charm.

          This works on Ubuntu 14-, 15+, Debian 8+ and CentOS 7.

          It is into this make_fog_portable job that I would also add any code for restarting critical services:

          
          # Ubuntu 14-
          sleep 6
          echo "Restarting tftpd-hpa [`date`]" > /dev/kmsg
          service tftpd-hpa restart
          sleep 6
          echo "Restarting mysql [`date`]" > /dev/kmsg
          service mysql restart
          sleep 6
          echo "Restarting FOGMulticastManager [`date`]" > /dev/kmsg
          service FOGMulticastManager restart
          
          # Debian 8+, Ubuntu 15+
          if [ -f /etc/debian_version ]; then
          echo "Restarting Critical FOG Services [`date`]" > /dev/kmsg
          systemctl restart tftp* mysql* FOG* apache*
          fi
          

          [ Standing in between extinction in the cold and explosive radiating growth ]

          W 1 Reply Last reply Dec 22, 2015, 10:26 PM Reply Quote 3
          • W
            Wayne Workman @sudburr
            last edited by Wayne Workman Dec 22, 2015, 4:28 PM Dec 22, 2015, 10:26 PM

            @sudburr now that is sweet! This is great work. It would have taken me several long hours to get to the point where you’ve come to. From here, it’s a hop, skip, and a jump to mix this with dnsmasq.

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
            Daily Clean Installation Results:
            https://fogtesting.fogproject.us/
            FOG Reporting:
            https://fog-external-reporting-results.fogproject.us/

            1 Reply Last reply Reply Quote 0
            • G
              george1421 Moderator
              last edited by george1421 Dec 22, 2015, 6:09 PM Dec 23, 2015, 12:00 AM

              I agree this is great! I’m glad we have the community involvement in the FOG community to help everyone solve these basic problems. Well done @sudburr !!

              The only thing that jumps out that may be an issue in the script is that for the Centos 7 OS the ethernet adapters are no longer just eth0, eth1 and so on. The Intel NUC I’m working on the default ethernet adapter is enp3s0.

              I just checked and this value interface="enp3s0" can be extracted from the /opt/fog/.fogsettings file. This would then tie into what interface FOG is using too. There may be a case where there is a system with one or more network interfaces that the script would have to take into account.

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

              W 1 Reply Last reply Dec 23, 2015, 3:44 AM Reply Quote 0
              • W
                Wayne Workman @george1421
                last edited by Dec 23, 2015, 3:44 AM

                @george1421 said:

                The only thing that jumps out that may be an issue in the script is that for the Centos 7 OS the ethernet adapters are no longer just eth0, eth1 and so on. The Intel NUC I’m working on the default ethernet adapter is enp3s0.

                If the interface name is known, you can use this to get the IP in CentOS 7.

                interface1ip="$(/sbin/ip addr show | grep $interface1name | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*")"

                This is a piece from a little project I’m working on:
                https://sourceforge.net/p/openvpnrouter/code/HEAD/tree/identifyInterfaces.sh#l26

                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                Daily Clean Installation Results:
                https://fogtesting.fogproject.us/
                FOG Reporting:
                https://fog-external-reporting-results.fogproject.us/

                1 Reply Last reply Reply Quote 0
                • W
                  Wayne Workman
                  last edited by Wayne Workman Dec 22, 2015, 10:31 PM Dec 23, 2015, 4:29 AM

                  I’m going to take a stab at making all of that below into one single cron-friendly script - and have it run via Cron every 5 minutes.

                  I’ll add logic to it so that it’ll only run if the IP has changed since the last run. It’ll use settings set in the FOG config file where appropriate.

                  I’ll also work dnsmasq into it as well, along with service restarts for dnsmasq.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                  Daily Clean Installation Results:
                  https://fogtesting.fogproject.us/
                  FOG Reporting:
                  https://fog-external-reporting-results.fogproject.us/

                  1 Reply Last reply Reply Quote 0
                  • W
                    Wayne Workman
                    last edited by Wayne Workman Dec 23, 2015, 5:49 PM Dec 23, 2015, 6:24 AM

                    100% NOT tested 🙂 👍

                    #---- Notes ----#
                    
                    # This script is for changing the FOG Server's IP address and configure dnsmasq automatically.
                    
                    # Thanks to forums.fogproject.org @sudburr for doing a ton of initial work.
                    
                    # Updated by forums.fogproject.org @Wayne-Workman
                    
                    # This is an early copy, stay tuned for updates.
                    
                    # December 22th, 2015.
                    
                    
                    #---- Get interface name and last IP from .fogsettings ---#
                    
                    interface="$(/usr/bin/grep 'interface=' /opt/fog/.fogsettings | /usr/share/awk -F'"' '{$0=$2}1')"
                    fogsettingsIP="$(/usr/bin/grep 'ipaddress=' /opt/fog/.fogsettings | /usr/share/awk -F'"' '{$0=$2}1')"
                    
                    
                    #---- Wait for an IP address ----#
                    
                    IP=`/sbin/ip addr list ${interface} | /usr/bin/grep "inet " |/usr/bin/cut -d" " -f6|/usr/bin/cut -d/ -f1`
                    
                    while [ -z $IP ]
                    
                    do
                        sleep 5
                        IP=`ip addr list ${interface} | grep "inet " |cut -d" " -f6|cut -d/ -f1`
                    done
                    
                    
                    
                    
                    if [[ "$IP" != "$fogsettingsIP" ]]; then
                    #If the actual IP doesn't match the .fogsettings IP
                    
                            #Update .fogsettings IP
                            sed -i "s|ipaddress=\".*\"|ipaddress=\"$IP\"|" /opt/fog/.fogsettings
                    
                            #Get MySQL credentials
                            snmysqluser="$(/usr/bin/grep 'snmysqluser=' /opt/fog/.fogsettings | /usr/share/awk -F'"' '{$0=$2}1')"
                            snmysqlpass="$(/usr/bin/grep 'snmysqlpass=' /opt/fog/.fogsettings | /usr/bin/cut -d \' -f2 )"
                    
                            #---- SQL ----#
                    
                            #These are the SQL statements to run against the DB
                            statement1="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_TFTP_HOST';"
                            statement2="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WOL_HOST';"
                            statement3="UPDATE \`nfsGroupMembers\` SET \`ngmHostname\` = '$IP' WHERE \`ngmMemberName\` ='DefaultMember';"
                    
                            if [ "$snmysqlpass" != "" ]; then
                                    #If there is a password set
                                    /usr/bin/mysql --user=$snmysqluser --password=$snmysqlpass --database='fog'  << EOF
                                    $statement1
                                    $statement2
                                    $statement3
                                    EOF
                    
                            elif [ "$snmysqluser != "" ]; then
                                    #If there is a user set but no password
                                    /usr/bin/mysql --user $snmysqluser --database='fog' << EOF
                                    $statement1
                                    $statement2
                                    $statement3
                                    EOF
                    
                            else
                                    #If there is no user or password set
                                    /usr/bin/mysql --database='fog' << EOF
                                    $statement1
                                    $statement2
                                    $statement3
                                    EOF
                    
                            fi
                    
                    
                            #Updating IP address in file default.ipxe
                            sed -i "s|http://\([^/]\+\)/|http://$IP/|" /tftpboot/default.ipxe
                            sed -i "s|http:///|http://$IP/|" /tftpboot/default.ipxe
                    
                    
                            #---- Backup config.class.php and then updae IP ----#
                            cp -f /var/www/html/fog/lib/fog/config.class.php /var/www/html/fog/lib/fog/config.class.php.old
                            sed -i "s|\".*\..*\..*\..*\"|\$_SERVER['SERVER_ADDR']|" /var/www/html/fog/lib/fog/config.class.php
                    
                    
                    
                    fi
                    

                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                    Daily Clean Installation Results:
                    https://fogtesting.fogproject.us/
                    FOG Reporting:
                    https://fog-external-reporting-results.fogproject.us/

                    G 1 Reply Last reply Dec 23, 2015, 6:08 PM Reply Quote 0
                    • G
                      george1421 Moderator @Wayne Workman
                      last edited by george1421 Dec 23, 2015, 12:09 PM Dec 23, 2015, 6:08 PM

                      @Wayne-Workman This is going to be a critical review of the code. Don’t take it personally (my guys hate me when I do this type of review, but the finished product is generally better).

                      Some lines use the full path to the application and some only use the application name. (i.e. /usr/share/awk)

                      Since you are using the full path to the application you assume that is the proper location. I just checked on my ubuntu based system awk is in /usr/bin/awk under Centos 7 its again /usr/bin/awk but in your script it references /usr/share/awk which I assume would cause your script to fail on these systems.

                      What would happen if interface or fogsettingsIP returned nothing instead of a value what would happen to your script?

                      The same question if the mysql credentials were not returned.

                      In sudburr’s post also references a wol host field to be updated, is this important?

                      What happens if config.class.php.old already exists when the script is run a second or third time. Will anything important be lost?

                      Do any running fog services maintain a cached copy of the server’s IP address or do the fog services need to be stopped when you update these settings to make them stick?

                      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                      W 1 Reply Last reply Dec 23, 2015, 6:20 PM Reply Quote 0
                      • W
                        Wayne Workman @george1421
                        last edited by Dec 23, 2015, 6:20 PM

                        @george1421 All great points - The paths in there are for Fedora 23.

                        I’ll see about using the $PATH variable instead of hard coded paths - and I’ll work on better variable handling.

                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                        Daily Clean Installation Results:
                        https://fogtesting.fogproject.us/
                        FOG Reporting:
                        https://fog-external-reporting-results.fogproject.us/

                        G 1 Reply Last reply Dec 23, 2015, 6:49 PM Reply Quote 0
                        • G
                          george1421 Moderator @Wayne Workman
                          last edited by george1421 Dec 23, 2015, 1:18 PM Dec 23, 2015, 6:49 PM

                          @Wayne-Workman

                          Some other things I just thought of while walking about.

                          How does dhcp lease time come into play in regards to script execution. Especially if this will be a cron job. Consider what is a shortest duration lease and a typical duration lease time.

                          should the physical location of this script be location in a fog related directory like /opt/fog/utils?

                          Is there any way to trap an interface going up/down and then to call your script? hint: http://www.cyberciti.biz/tips/how-do-i-run-firewall-script-as-soon-as-eth0-interface-brings-up.html

                          Does the interface go down and then up on a dhcp renewal.

                          We would assume that the path statement points correctly for bash to run without full paths on the called applications especially if they are system type applications.

                          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                          W 2 Replies Last reply Dec 23, 2015, 6:55 PM Reply Quote 0
                          • W
                            Wayne Workman @george1421
                            last edited by Dec 23, 2015, 6:55 PM

                            @george1421 My thought was just to setup a cron job that runs every 5 minutes.

                            If the actual IP is the same as what’s in .fogsettings then nothing is done - and to find that out, it’s not much resources used.

                            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                            Daily Clean Installation Results:
                            https://fogtesting.fogproject.us/
                            FOG Reporting:
                            https://fog-external-reporting-results.fogproject.us/

                            1 Reply Last reply Reply Quote 0
                            • M
                              mrayzies
                              last edited by Dec 23, 2015, 7:31 PM

                              @Wayne-Workman
                              I think there should be an option in .fogsettings to skip this altogether, not because of system resources, but occasionally I might want to poke at the system (e.g. add a temporary VIP for testing something else) and unless the coding is air-tight, it might kick off some horrible changes.

                              W 1 Reply Last reply Dec 23, 2015, 7:38 PM Reply Quote 0
                              • W
                                Wayne Workman @mrayzies
                                last edited by Wayne Workman Dec 23, 2015, 1:39 PM Dec 23, 2015, 7:38 PM

                                @mrayzies Are you talking about the cron job? We can add a simple setting into the .fogsettings file like keepIPupdated="1" / "0"

                                What I’m working on is a total custom thing - it’ll likely never be implemented into FOG Trunk officially.

                                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                                Daily Clean Installation Results:
                                https://fogtesting.fogproject.us/
                                FOG Reporting:
                                https://fog-external-reporting-results.fogproject.us/

                                1 Reply Last reply Reply Quote 0
                                • M
                                  mrayzies
                                  last edited by Dec 23, 2015, 7:43 PM

                                  I was talking about the CRON job.

                                  And OK – sorry to barge in on the conversation.

                                  W 1 Reply Last reply Dec 23, 2015, 9:04 PM Reply Quote 0
                                  • W
                                    Wayne Workman @mrayzies
                                    last edited by Dec 23, 2015, 9:04 PM

                                    @mrayzies By all means, give your thoughts and even contribute. 🙂 FOG is a community project.

                                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                                    Daily Clean Installation Results:
                                    https://fogtesting.fogproject.us/
                                    FOG Reporting:
                                    https://fog-external-reporting-results.fogproject.us/

                                    1 Reply Last reply Reply Quote 1
                                    • W
                                      Wayne Workman @george1421
                                      last edited by Wayne Workman Dec 23, 2015, 5:49 PM Dec 23, 2015, 11:37 PM

                                      @george1421 This script should knock your socks right off.

                                      It dynamically finds the paths for all the called programs by searching through the directories in $PATH. The result is CRON friendly commands that are easy to type. 🙂

                                      Still 100% untested, I’ve not even run this script myself yet.

                                      #---- Notes ----#
                                      
                                      # This script is for changing the FOG Server's IP address and configure dnsmasq automatically.
                                      
                                      # Thanks to forums.fogproject.org @sudburr for doing a ton of initial work.
                                      
                                      # Updated by forums.fogproject.org @Wayne-Workman
                                      
                                      # This is an early copy, stay tuned for updates.
                                      
                                      # December 23th, 2015.
                                      
                                      
                                      
                                      
                                      #---- Set Command Paths ----#
                                      
                                      ( IFS=:
                                        for p in $PATH; do
                                      
                                              #Get grep path
                                              if [[ -f $p/grep ]]; then
                                                      grep=$p/grep
                                              fi
                                      
                                              #Get awk path
                                              if [[ -f $p/awk ]]; then
                                                      awk=$p/awk
                                              fi
                                      
                                              #Get cut path
                                              if [[ -f $p/cut ]]; then
                                                      cut=$p/cut
                                              fi
                                      
                                              #Get ip path
                                              if [[ -f $p/ip ]]; then
                                                      ip=$p/ip
                                              fi
                                      
                                              #Get sed path
                                              if [[ -f $p/sed ]]; then
                                                      sed=$p/sed
                                              fi
                                      
                                              #Get mysql path
                                              if [[ -f $p/mysql ]]; then
                                                      mysql=$p/mysql
                                              fi
                                      
                                              #Get cp path
                                              if [[ -f $p/cp ]]; then
                                                      cp=$p/cp
                                              fi
                                      
                                        done
                                      )
                                      
                                      
                                      #---- Get interface name and last IP from .fogsettings ---#
                                      
                                      interface="$($grep 'interface=' /opt/fog/.fogsettings | $awk -F'"' '{$0=$2}1')"
                                      fogsettingsIP="$($grep 'ipaddress=' /opt/fog/.fogsettings | $awk -F'"' '{$0=$2}1')"
                                      
                                      
                                      #---- Wait for an IP address ----#
                                      
                                      IP=`$ip addr list ${interface} | $grep "inet " |$cut -d" " -f6|$cut -d/ -f1`
                                      
                                      while [ -z $IP ]
                                      
                                      do
                                          sleep 5
                                          IP=`$ip addr list ${interface} | $grep "inet " |$cut -d" " -f6|$cut -d/ -f1`
                                      done
                                      
                                      
                                      
                                      
                                      if [[ "$IP" != "$fogsettingsIP" ]]; then
                                      #If the actual IP doesn't match the .fogsettings IP
                                      
                                              #Update .fogsettings IP
                                              $sed -i "s|ipaddress=\".*\"|ipaddress=\"$IP\"|" /opt/fog/.fogsettings
                                      
                                              #Get MySQL credentials
                                              snmysqluser="$($grep 'snmysqluser=' /opt/fog/.fogsettings | $awk -F'"' '{$0=$2}1')"
                                              snmysqlpass="$($grep 'snmysqlpass=' /opt/fog/.fogsettings | $cut -d \' -f2 )"
                                      
                                              #---- SQL ----#
                                      
                                              #These are the SQL statements to run against the DB
                                              statement1="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_TFTP_HOST';"
                                              statement2="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WOL_HOST';"
                                              statement3="UPDATE \`nfsGroupMembers\` SET \`ngmHostname\` = '$IP' WHERE \`ngmMemberName\` ='DefaultMember';"
                                      
                                              if [ "$snmysqlpass" != "" ]; then
                                                      #If there is a password set
                                                      $mysql --user=$snmysqluser --password=$snmysqlpass --database='fog'  << EOF
                                                      $statement1
                                                      $statement2
                                                      $statement3
                                                      EOF
                                      
                                              elif [ "$snmysqluser != "" ]; then
                                                      #If there is a user set but no password
                                                      $mysql --user $snmysqluser --database='fog' << EOF
                                                      $statement1
                                                      $statement2
                                                      $statement3
                                                      EOF
                                      
                                              else
                                                      #If there is no user or password set
                                                      $mysql --database='fog' << EOF
                                                      $statement1
                                                      $statement2
                                                      $statement3
                                                      EOF
                                      
                                              fi
                                      
                                      
                                              #Updating IP address in file default.ipxe
                                              $sed -i "s|http://\([^/]\+\)/|http://$IP/|" /tftpboot/default.ipxe
                                              $sed -i "s|http:///|http://$IP/|" /tftpboot/default.ipxe
                                      
                                      
                                              #---- Backup config.class.php and then updae IP ----#
                                              $cp -f /var/www/html/fog/lib/fog/config.class.php /var/www/html/fog/lib/fog/config.class.php.old
                                              $sed -i "s|\".*\..*\..*\..*\"|\$_SERVER['SERVER_ADDR']|" /var/www/html/fog/lib/fog/config.class.php
                                      
                                      
                                      
                                      fi
                                      

                                      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                                      Daily Clean Installation Results:
                                      https://fogtesting.fogproject.us/
                                      FOG Reporting:
                                      https://fog-external-reporting-results.fogproject.us/

                                      1 Reply Last reply Reply Quote 0
                                      • W
                                        Wayne Workman
                                        last edited by Wayne Workman Dec 23, 2015, 8:20 PM Dec 24, 2015, 2:18 AM

                                        This changes all fog settings and the “defaultmember” storage node to whatever the current IP of the fog server is. I’ve tested it, it works.

                                        I’ve added extensive fail-safes as @george1421 was talking about - if anything isn’t right, it just quits.

                                        I’ll work on adding dnsmasq now and the earlier check to run the cron event or not from @mrayzies

                                        #---- Notes ----#
                                        
                                        # This script is for changing the FOG Server's IP address and configure dnsmasq automatically.
                                        # It's intended to run as a cron event every 5 minutes, should work fine on Red Hat and RH variants. 
                                        # Thanks to forums.fogproject.org @sudburr for doing a ton of initial work.
                                        # Updated by forums.fogproject.org @Wayne-Workman
                                        # Version 4.
                                        
                                        
                                        #check for .fogsettings existence, if it isn't there, exit the script.
                                        if ! [[ -f /opt/fog/.fogsettings ]]; then
                                                exit
                                        fi
                                        
                                        #---- Set Command Paths ----#
                                        
                                        #Store previous contents of IFS.
                                        previousIFS=$IFS
                                        
                                        IFS=:
                                          for p in $PATH; do
                                        
                                                #Get grep path
                                                if [[ -f $p/grep ]]; then
                                                        grep=$p/grep
                                                fi
                                        
                                                #Get awk path
                                                if [[ -f $p/awk ]]; then
                                                        awk=$p/awk
                                                fi
                                        
                                                #Get cut path
                                                if [[ -f $p/cut ]]; then
                                                        cut=$p/cut
                                                fi
                                        
                                                #Get ip path
                                                if [[ -f $p/ip ]]; then
                                                        ip=$p/ip
                                                fi
                                        
                                                #Get sed path
                                                if [[ -f $p/sed ]]; then
                                                        sed=$p/sed
                                                fi
                                        
                                                #Get mysql path
                                                if [[ -f $p/mysql ]]; then
                                                        mysql=$p/mysql
                                                fi
                                        
                                                #Get cp path
                                                if [[ -f $p/cp ]]; then
                                                        cp=$p/cp
                                                fi
                                        
                                          done
                                        
                                        #Restore previous contents of IFS
                                        IFS=$previousIFS
                                        
                                        #If any command variables don't have content, exit the script.
                                        if ! [[ -z $grep ]] && [[ -z $awk ]] && [[ -z $cut ]] && [[ -z $ip ]] && [[ -z $sed ]] && [[ -z $mysql ]] && [[ -z $cp ]]; then
                                                exit
                                        fi
                                        
                                        #---- Get interface name and last IP from .fogsettings ---#
                                        
                                        interface="$($grep 'interface=' /opt/fog/.fogsettings | $awk -F'"' '{$0=$2}1')"
                                        fogsettingsIP="$($grep 'ipaddress=' /opt/fog/.fogsettings | $awk -F'"' '{$0=$2}1')"
                                        
                                        #If there isn't an interface and IP set in .fogsettings, exit the script.
                                        if ! [[ -z $interface ]] && [[ -z $fogsettingsIP ]]; then
                                                exit
                                        fi
                                        
                                        
                                        #---- Wait for an IP address ----#
                                        
                                        IP=`$ip addr list ${interface} | $grep "inet " |$cut -d" " -f6|$cut -d/ -f1`
                                        
                                        while [ -z $IP ]
                                        
                                        do
                                            sleep 5
                                            IP=`$ip addr list ${interface} | $grep "inet " |$cut -d" " -f6|$cut -d/ -f1`
                                        done
                                        
                                        
                                        
                                        if [[ "$IP" != "$fogsettingsIP" ]]; then
                                        #If the interface IP doesn't match the .fogsettings IP, do the below.
                                        
                                                #---- SQL ----#
                                        
                                                snmysqluser="$($grep 'snmysqluser=' /opt/fog/.fogsettings | $awk -F'"' '{$0=$2}1')"
                                                snmysqlpass="$($grep 'snmysqlpass=' /opt/fog/.fogsettings | $cut -d \' -f2 )"
                                        
                                                #These are the SQL statements to run against the DB
                                                statement1="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_TFTP_HOST';"
                                                statement2="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WOL_HOST';"
                                                statement3="UPDATE \`nfsGroupMembers\` SET \`ngmHostname\` = '$IP' WHERE \`ngmMemberName\` ='DefaultMember';"
                                                statement4="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WEB_HOST';"
                                        
                                        
                                                #This builds the proper MySQL Connection Statement.
                                                if [ "$snmysqlpass" != "" ]; then
                                                        #If there is a password set
                                                        $mysql --user=$snmysqluser --password=$snmysqlpass --database='fog' -e "$statement1$statement2$statement3$statement4"
                                        
                                                elif [ "$snmysqluser" != "" ]; then
                                                        #If there is a user set but no password
                                                        $mysql --user $snmysqluser --database='fog' -e "$statement1$statement2$statement3$statement4"
                                        
                                                else
                                                        #If there is no user or password set
                                                        $mysql --database='fog' -e "$statement1$statement2$statement3$statement4"
                                                fi
                                        
                                                #---- Update IP address in file default.ipxe ----#
                                        
                                                $sed -i "s|http://\([^/]\+\)/|http://$IP/|" /tftpboot/default.ipxe
                                                $sed -i "s|http:///|http://$IP/|" /tftpboot/default.ipxe
                                        
                                        
                                                #---- Backup config.class.php and then updae IP ----#
                                        
                                                $cp -f /var/www/html/fog/lib/fog/config.class.php /var/www/html/fog/lib/fog/config.class.php.old
                                                $sed -i "s|\".*\..*\..*\..*\"|\$_SERVER['SERVER_ADDR']|" /var/www/html/fog/lib/fog/config.class.php
                                        
                                                #---- Update .fogsettings IP ----#
                                        
                                                $sed -i "s|ipaddress=\".*\"|ipaddress=\"$IP\"|" /opt/fog/.fogsettings
                                        
                                        fi
                                        

                                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                                        Daily Clean Installation Results:
                                        https://fogtesting.fogproject.us/
                                        FOG Reporting:
                                        https://fog-external-reporting-results.fogproject.us/

                                        1 Reply Last reply Reply Quote 0
                                        • W
                                          Wayne Workman
                                          last edited by Dec 24, 2015, 5:34 AM

                                          Version 5. This one will build the dnsmasq config file.

                                          #---- Notes ----#
                                          
                                          # This script is for changing the FOG Server's IP address and configure dnsmasq automatically.
                                          # It's intended to run as a cron event every 5 minutes, should work fine on Red Hat and RH variants. 
                                          # Thanks to forums.fogproject.org @sudburr for doing a ton of initial work.
                                          # Updated by forums.fogproject.org @Wayne-Workman
                                          # Version 5.
                                          # If you want to use dnsmasq, you must first set this up as a cron script to run every so oftne (every 5 minutes)
                                          # And add dnsmasq to the packages list inside /opt/fog/.fogsettings
                                          # and when "dodnsmasq" and "bldnsmasq" show up (after script's first run), set those to 1 or whatever you prefer.
                                          #
                                          # the final "undionly" line still needs fixed to be created from the bootfile variable in the ltsp.conf file.
                                          
                                          fogsettings=/opt/fog/.fogsettings
                                          
                                          
                                          #check for .fogsettings existence, if it isn't there, exit the script.
                                          if ! [[ -f $fogsettings ]]; then
                                                  exit
                                          fi
                                          
                                          #---- Set Command Paths ----#
                                          
                                          #Store previous contents of IFS.
                                          previousIFS=$IFS
                                          
                                          IFS=:
                                            for p in $PATH; do
                                          
                                                  #Get grep path
                                                  if [[ -f $p/grep ]]; then
                                                          grep=$p/grep
                                                  fi
                                          
                                                  #Get awk path
                                                  if [[ -f $p/awk ]]; then
                                                          awk=$p/awk
                                                  fi
                                          
                                                  #Get cut path
                                                  if [[ -f $p/cut ]]; then
                                                          cut=$p/cut
                                                  fi
                                          
                                                  #Get ip path
                                                  if [[ -f $p/ip ]]; then
                                                          ip=$p/ip
                                                  fi
                                          
                                                  #Get sed path
                                                  if [[ -f $p/sed ]]; then
                                                          sed=$p/sed
                                                  fi
                                          
                                                  #Get mysql path
                                                  if [[ -f $p/mysql ]]; then
                                                          mysql=$p/mysql
                                                  fi
                                          
                                                  #Get cp path
                                                  if [[ -f $p/cp ]]; then
                                                          cp=$p/cp
                                                  fi
                                          
                                                  #Get echo path
                                                  if [[ -f $p/echo ]]; then
                                                          echo=$p/echo
                                                  fi
                                          
                                                  #Get mv path
                                                  if [[ -f $p/mv ]]; then
                                                          mv=$p/mv
                                                  fi
                                          
                                                  #Get rm path
                                                  if [[ -f $p/rm ]]; then
                                                          rm=$p/rm
                                                  fi
                                          
                                                  #Get systemctl path
                                                  if [[ -f $p/systemctl ]]; then
                                                          systemctl=$p/systemctl
                                                  fi
                                          
                                            done
                                          
                                          #Restore previous contents of IFS
                                          IFS=$previousIFS
                                          
                                          #If any command variables don't have content, exit the script.
                                          if ! [[ -z $grep ]] && [[ -z $awk ]] && [[ -z $cut ]] && [[ -z $ip ]] && [[ -z $sed ]] && [[ -z $mysql ]] && [[ -z $cp ]] && [[ -z $echo ]] && [[ -z $mv ]] && [[ -z $rm ]] && [[ -z $systemctl ]]; then
                                                  exit
                                          fi
                                          
                                          #---- Get interface name and last IP from .fogsettings ---#
                                          
                                          interface="$($grep 'interface=' $fogsettings | $awk -F'"' '{$0=$2}1')"
                                          fogsettingsIP="$($grep 'ipaddress=' $fogsettings | $awk -F'"' '{$0=$2}1')"
                                          
                                          #If there isn't an interface and IP set in .fogsettings, exit the script.
                                          if ! [[ -z $interface ]] && [[ -z $fogsettingsIP ]]; then
                                                  exit
                                          fi
                                          
                                          
                                          #---- Wait for an IP address ----#
                                          
                                          IP=`$ip addr list ${interface} | $grep "inet " |$cut -d" " -f6|$cut -d/ -f1`
                                          
                                          while [ -z $IP ]
                                          
                                          do
                                              sleep 5
                                              IP=`$ip addr list ${interface} | $grep "inet " |$cut -d" " -f6|$cut -d/ -f1`
                                          done
                                          
                                          
                                          
                                          if [[ "$IP" != "$fogsettingsIP" ]]; then
                                          #If the interface IP doesn't match the .fogsettings IP, do the below.
                                          
                                                  #---- SQL ----#
                                          
                                                  snmysqluser="$($grep 'snmysqluser=' $fogsettings | $awk -F'"' '{$0=$2}1')"
                                                  snmysqlpass="$($grep 'snmysqlpass=' $fogsettings | $cut -d \' -f2 )"
                                          
                                                  #These are the SQL statements to run against the DB
                                                  statement1="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_TFTP_HOST';"
                                                  statement2="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WOL_HOST';"
                                                  statement3="UPDATE \`nfsGroupMembers\` SET \`ngmHostname\` = '$IP' WHERE \`ngmMemberName\` ='DefaultMember';"
                                                  statement4="UPDATE \`globalSettings\` SET \`settingValue\` = '$IP' WHERE \`settingKey\` ='FOG_WEB_HOST';"
                                          
                                          
                                                  #This puts all the statements into one variable. If you add more statments above, add the extra ones to this too.
                                                  sqlStatements=$statement1$statement2$statement3$statement4
                                          
                                          
                                                  #This builds the proper MySQL Connection Statement.
                                                  if [ "$snmysqlpass" != "" ]; then
                                                          #If there is a password set
                                                          $mysql --user=$snmysqluser --password=$snmysqlpass --database='fog' -e "$sqlStatements"
                                          
                                                  elif [ "$snmysqluser" != "" ]; then
                                                          #If there is a user set but no password
                                                          $mysql --user $snmysqluser --database='fog' -e "$sqlStatements"
                                          
                                                  else
                                                          #If there is no user or password set
                                                          $mysql --database='fog' -e "$sqlStatements"
                                                  fi
                                          
                                                  #---- Update IP address in file default.ipxe ----#
                                          
                                                  $sed -i "s|http://\([^/]\+\)/|http://$IP/|" /tftpboot/default.ipxe
                                                  $sed -i "s|http:///|http://$IP/|" /tftpboot/default.ipxe
                                          
                                          
                                                  #---- Backup config.class.php and then updae IP ----#
                                          
                                                  $cp -f /var/www/html/fog/lib/fog/config.class.php /var/www/html/fog/lib/fog/config.class.php.old
                                                  $sed -i "s|\".*\..*\..*\..*\"|\$_SERVER['SERVER_ADDR']|" /var/www/html/fog/lib/fog/config.class.php
                                          
                                                  #---- Update .fogsettings IP ----#
                                          
                                                  $sed -i "s|ipaddress=\".*\"|ipaddress=\"$IP\"|" $fogsettings
                                          
                                          
                                                  #Check if the dodnsmasq setting exists in fog settings. If not, create it and set it to false.
                                                  if ! $grep -q dodnsmasq "$fogsettings"; then
                                                          #Remove any blank lines at the end of fogsettings, then rewrite file.
                                                          $sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $fogsettings > $fogsettings.new
                                                          $mv $fogsettings.new $fogsettings
                                                          #Add dodnsmasq setting.
                                                          $echo dodnsmasq="\""0"\"" >> $fogsettings
                                                          #Add a blank line at the end of fogsettings.
                                                          $echo "" >> $fogsettings
                                                  fi
                                          
                                          
                                                  #Check if the bldnsmasq setting exists in fog settings. If no, create it and set it to false.
                                                  if ! grep -q bldnsmasq "$fogsettings"; then
                                                          #Remove any blank lines at the end of fogsettings, then rewrite file.
                                                          $sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $fogsettings > $fogsettings.new
                                                          $mv $fogsettings.new $fogsettings
                                                          #Add bldnsmasq setting.
                                                          $echo bldnsmasq="\""0"\"" >> $fogsettings
                                                          #Add a blank line at the end of fogsettings.
                                                          $echo "" >> $fogsettings
                                                  fi
                                          
                                          
                                                  #Read the dodnsmasq and bldnsmasq settings.
                                                  dodnsmasq="$($grep 'dodnsmasq=' $fogsettings | $awk -F'"' '{$0=$2}1')"
                                                  bldnsmasq="$($grep 'bldnsmasq=' $fogsettings | $awk -F'"' '{$0=$2}1')"
                                          
                                                  #If either of the dnsmasq fogsettings are empty, exit the script.
                                                  if ! [[ -z dodnsmasq ]] && [[ -z bldnsmasq ]]; then
                                                          exit
                                                  fi
                                          
                                                  #If bldnsmasq is seto as 1, build the config file.
                                                  if [[ "$bldnsmasq" == "1" ]]; then
                                          
                                                          #set the ltsp.conf path.
                                                          ltsp=/etc/dnsmasq.d/ltsp.conf
                                          
                                                          #Read what boot file is set in fogsettings, use that in ltsp.conf
                                                          bootfilename="$($grep 'bootfilename=' $fogsettings | $awk -F'"' '{$0=$2}1')"
                                          
                                                          #If bootfilename is blank, set it to undionly.kkpxe
                                                          if [[ -z "$bootfilename" ]]; then
                                                                  bootfilename=undionly.kkpxe
                                                          fi
                                          
                                                          #Check for existence of the bootfile copy ".0" file. If it exists, delete it and recreate it.
                                                          bootfileCopy="${bootfilename%.*}.0"
                                                          if [[ -f $bootfileCopy ]]; then
                                                                  $rm -f $bootfileCopy
                                                          fi
                                                          $cp /tftpboot/$bootfilename /tftpboot/$bootfileCopy
                                          
                                          
                                                          #this config overwrites anything in ltsp.conf because "bldnsmasq" was set to 1.
                                                          $echo port=0 > $ltsp
                                                          $echo log-dhcp >> $ltsp
                                                          $echo tftp-root=/tftpboot >> $ltsp
                                                          $echo dhcp-boot=$bootfileCopy,$IP,$IP >> $ltsp
                                                          $echo dhcp-option=17,/images >> $ltsp
                                                          $echo dhcp-option=vendor:PXEClient,6,2b >> $ltsp
                                                          $echo dhcp-no-override >> $ltsp
                                                          $echo pxe-prompt="Press F8 for boot menu", 3 >> $ltsp
                                                          $echo pxe-service=X86PC, “Boot from network”, undionly >> $ltsp
                                                          $echo pxe-service=X86PC, "Boot from local hard disk", 0 >> $ltsp
                                                          $echo dhcp-range=$IP,proxy >> $ltsp
                                          
                                                  fi
                                          
                                          
                                          
                                                  #if dodnsmasq is set to 1, restart and enable dnsmasq. ELSE disable and stop.
                                                  if [[ "$dodnsmasq" == "1" ]]; then
                                                          $systemctl enable dnsmasq
                                                          $systemctl restart dnsmasq
                                                  else
                                                          $systemctl disable dnsmasq
                                                          $systemctl stop dnsmasq
                                                  fi
                                          
                                          
                                          fi
                                          

                                          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                                          Daily Clean Installation Results:
                                          https://fogtesting.fogproject.us/
                                          FOG Reporting:
                                          https://fog-external-reporting-results.fogproject.us/

                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 1 / 2
                                          1 / 2
                                          • First post
                                            13/27
                                            Last post

                                          162

                                          Online

                                          12.0k

                                          Users

                                          17.3k

                                          Topics

                                          155.2k

                                          Posts
                                          Copyright © 2012-2024 FOG Project