LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2012, 01:51 AM   #1
haliban
LQ Newbie
 
Registered: Mar 2006
Posts: 9

Rep: Reputation: 0
Lightbulb Bash: Restart program when IP change for domain.com


[Task description]

We have a dns record domain.com it can resolve to IP1 or IP2. We don't know which one exactly (GTM load balancing)

The script will check every 5 minutes if the IP address for domain.com has changed. If it has than it will execute restartprogram1.sh if it hasn't do nothing.

[End of task description/]

I was thinking maybe to set both IPs as variable but it will work only in one direction

Than I was thinking to store the IP in file and use this file to check if the IP has changed every 5 mins.


Code:
#!/bin/bash
set -x

# domain.com can resolve to 100.24.34.4 or 100.24.35.4

now=`/usr/sbin/nslookup domain.com | /usr/bin/grep 100 | cut -d" " -f2`

before=`cat /home/scripts/lookup`
    
    if [ now =! before ] || [ -z `$before`] then
         `/usr/sbin/restartprogram.sh`
          echo $now > lookup`
         
        else
                `/usr/sbin/restartprogram.sh`
                 echo $now > lookup
fi

#END
I'm learning and will appreciate every helpful feedback and idea

Cheeerss
 
Old 10-04-2012, 02:46 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Hmm, well I'd be more interested to know what the program being restarted was, maybe there's a way to improve that at source rather than hacking around it.

Obviously there are plenty of ways to resolve this. Presumably you are running through a cron job. If this program being restarted maintains a persistent network connection then I would look for connections in the output of netstat to see what destination is currently being used, and compare that to the output from host (not nslookup), although your system is probably fine too, especially in a more general purpose solution.

You're a bit backtick happy there. Note that backticks were superseded by $(this) notation a long time ago in bash, it's much clearer to use. But your restart line in the else block doesn't make sense. You're going to try to run the output of the script, which, unless the script outputs "/usr/bin/somecommand" makes no sense.
 
Old 10-06-2012, 07:54 AM   #3
haliban
LQ Newbie
 
Registered: Mar 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Cheers Chris,

To add more meat on the bone of the story. The restartprogram.sh is actually Apache working as reverse proxy and pointing to the destination hosting server domain.com. The domain.com can change its IP without notification at any time (no control on this process). In our case Apache is cashing the DNS until restart. I'm not sure if Apache can check for IP change every few minutes and went to the hacky way
 
Old 10-08-2012, 07:05 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
check this issue report, seems similar to what you're looking at https://issues.apache.org/bugzilla/s...g.cgi?id=50551

fundamentally, or at least, as *I* read it, there's no fault per se, and you could do well to just tune down the mod_proxy config to kill off connections pretty quickly.
 
Old 10-10-2012, 01:34 AM   #5
haliban
LQ Newbie
 
Registered: Mar 2006
Posts: 9

Original Poster
Rep: Reputation: 0
This looks pretty much the same to what i'm trying to do.
We are using Apache/2.2.9
I'll give it a go and will let you know how it goes.

Last edited by haliban; 10-10-2012 at 01:47 AM.
 
Old 10-14-2012, 07:25 PM   #6
haliban
LQ Newbie
 
Registered: Mar 2006
Posts: 9

Original Poster
Rep: Reputation: 0
My config as bellow

NameVirtualHost 192.168.100.10:443
<VirtualHost 192.168.100.10:443>
SSLEngine ON
SSLProxyEngine ON
ProxyPass / https://backend.mydomain.com:8080/ disablereuse=On smax=0 ttl=30
ProxyPassReverse / https://backend.mydomain.com:8080/
</VirtualHost>I have changed the DNS for backend.mydomain.com to different IPs. Apache picked up the new IP without restart or additional interventions, pretty cool!

I haven't done packet captures at this time as it seems to look may do later on if needed.

Thanks hips for the support! Much appreciated!

Last edited by haliban; 10-14-2012 at 07:26 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cant login to domain after restart micro_xii Linux - Server 1 04-24-2012 06:10 AM
Service postfix restart fail/domain name config cmwalter Linux - Server 2 03-05-2010 03:16 PM
Services must restart after changing NIS domain jlinkels Linux - Server 0 11-21-2009 07:49 PM
windows domain authentication - winbind restart needed bigearsbilly Linux - Server 1 10-01-2008 02:31 AM
Restart a program sibtay Programming 4 09-28-2004 10:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration