Mailing List Archive

execute a command after getting/loosing a IP-Address?
Hi list,

i've set up a round robin/failover scenario with squid.
Wackamole works fine, but my problem is that, in my case,
squid has to bind itself to a special address (not all 0.0.0.0).
So i have to send a kill -HUP to the squid process, after getting a new
IP address, because squid does not listen to this IP.
The problem occurs with any other process, that binds to a special IP and not
to all.

I've put a line in wackamole.c at the end of the Acquire function:
system ("kill -HUP `cat /var/run/squid.pid >/dev/null 2>&1` >/dev/null 2>&1");

But I don't like this very dirty solution, so i wanted to ask,
if there could be a better way to execute a command after
acquiring/releasing an ip address.

I can write the system stuff in c, but I would prefer a more configurable solution.


Thanks.

Kind regards,



Oliver Fänger
execute a command after getting/loosing a IP-Address? [ In reply to ]
So, we don't provide any solutions to this problem within Wackamole.=
=20
However, I'm sure someone else has had to deal with it, and might ans=
wer=20
you with something they've already developed. (This is a big holiday=
in=20
the US, which means a lot of people on the list probably won't be=
=20
responding for a few days).

The solution you proposed is probably the quickest and dirtiest way t=
o=20
get what you want. If you wanted something more powerful, using the=
=20
same mechanism to run a pair of shell-scripts "Acquire-script" and=
=20
"Release-script" would give this to you. However, I'd be a little=
=20
worried about doing so in a general situation, because of the privile=
ges=20
with which Wackamole is run.

I wouldn't recommend adding anything too complicated directly to=20
Wackamole, because of timing concerns. You might consider a=20
long-running daemon to handle this failover, that communicates=20
(something along the lines of "Acquire/Release address") with Wackamo=
le=20
via named pipes or another Unix IPC mechanism.

Hops this helps,
Ryan

Oliver F=E4nger wrote:
> Hi list,
>=20
> i've set up a round robin/failover scenario with squid.
> Wackamole works fine, but my problem is that, in my case,
> squid has to bind itself to a special address (not all 0.0.0.0).
> So i have to send a kill -HUP to the squid process, after getting a=
new
> IP address, because squid does not listen to this IP.
> The problem occurs with any other process, that binds to a special =
IP=20
> and not
> to all.
>=20
> I've put a line in wackamole.c at the end of the Acquire function:
> system ("kill -HUP `cat /var/run/squid.pid >/dev/null 2>&1` >/dev/n=
ull=20
> 2>&1");
>=20
> But I don't like this very dirty solution, so i wanted to ask,
> if there could be a better way to execute a command after
> acquiring/releasing an ip address.
>=20
> I can write the system stuff in c, but I would prefer a more=20
> configurable solution.
>=20
>=20
> Thanks.
>=20
> Kind regards,
>=20
>=20
>=20
> Oliver F=E4nger
>=20
>=20
>=20
>=20
>=20
>=20
> _______________________________________________
> wackamole-users mailing list
> wackamole-users@lists.backhand.org
> http://lists.backhand.org/mailman/listinfo/wackamole-users
>=20
>=20

--=20
Ryan W. Caudy
Center for Networking and Distributed Systems
Department of Computer Science
Johns Hopkins University
execute a command after getting/loosing a IP-Address? [ In reply to ]
On Nov 27, 2003, at 10:13 AM, Ryan Caudy wrote:
> So, we don't provide any solutions to this problem within Wackamole.
> However, I'm sure someone else has had to deal with it, and might
> answer you with something they've already developed. (This is a big
> holiday in the US, which means a lot of people on the list probably
> won't be responding for a few days).
>
> The solution you proposed is probably the quickest and dirtiest way to
> get what you want. If you wanted something more powerful, using the
> same mechanism to run a pair of shell-scripts "Acquire-script" and
> "Release-script" would give this to you. However, I'd be a little
> worried about doing so in a general situation, because of the
> privileges with which Wackamole is run.
>
> I wouldn't recommend adding anything too complicated directly to
> Wackamole, because of timing concerns. You might consider a
> long-running daemon to handle this failover, that communicates
> (something along the lines of "Acquire/Release address") with
> Wackamole via named pipes or another Unix IPC mechanism.

Actually, wackamole in CVS has embedded an embedded perl interpreter in
it. So you can do crazy stuff like that. It is mostly untested and
undocumented, but I have used it. It also has the ability to dlopen
shared objects and run code in those -- if you'd rather write in C.

Perl works something like this in your wackamole.conf:

PerlUseLib .
PerlUse example
RunDynamic example::hup_named on up

In the local directory (.) example.pm looks like:
-- begin --
package example;

use strict;
use Data::Dumper;

sub hup_named {
my $pid;
open(A,"</var/run/named.pid") && chomp($pid = <A>);
close(A);
kill 1, $pid if($pid);
}

1;
-- end --

The following will dlopen funcs.so and run the function returned by
dlsym("shoutout"):

RunDynamic funcs:shoutout on up

A simple funcs.c is:
-- begin --
#include "config.h"

void killhup(struct interface p,
struct interface *e,
struct interface r) {
fprintf(stderr, "I am here with IP %s\n", inet_ntoa(p.ipaddr));
}
-- end --

All this being development work -- YMMV.

// Theo Schlossnagle
// Principal Engineer -- http://www.omniti.com/~jesus/
// Postal Engine -- http://www.postalengine.com/
// Ecelerity: fastest MTA on earth
execute a command after getting/loosing a IP-Address? [ In reply to ]
This is exactly what i was looking for.
I've just checked out from the cvs and will try it tomorow.


Btw.: your 'Browsable via web through viewcvs here.' link is broken.



Thanx a lot


Oliver Fänger


Theo Schlossnagle schrieb:
> On Nov 27, 2003, at 10:13 AM, Ryan Caudy wrote:
>
>> So, we don't provide any solutions to this problem within Wackamole.
>> However, I'm sure someone else has had to deal with it, and might
>> answer you with something they've already developed. (This is a big
>> holiday in the US, which means a lot of people on the list probably
>> won't be responding for a few days).
>>
>> The solution you proposed is probably the quickest and dirtiest way to
>> get what you want. If you wanted something more powerful, using the
>> same mechanism to run a pair of shell-scripts "Acquire-script" and
>> "Release-script" would give this to you. However, I'd be a little
>> worried about doing so in a general situation, because of the
>> privileges with which Wackamole is run.
>>
>> I wouldn't recommend adding anything too complicated directly to
>> Wackamole, because of timing concerns. You might consider a
>> long-running daemon to handle this failover, that communicates
>> (something along the lines of "Acquire/Release address") with
>> Wackamole via named pipes or another Unix IPC mechanism.
>
>
> Actually, wackamole in CVS has embedded an embedded perl interpreter in
> it. So you can do crazy stuff like that. It is mostly untested and
> undocumented, but I have used it. It also has the ability to dlopen
> shared objects and run code in those -- if you'd rather write in C.
>
> Perl works something like this in your wackamole.conf:
>
> PerlUseLib .
> PerlUse example
> RunDynamic example::hup_named on up
>
> In the local directory (.) example.pm looks like:
> -- begin --
> package example;
>
> use strict;
> use Data::Dumper;
>
> sub hup_named {
> my $pid;
> open(A,"</var/run/named.pid") && chomp($pid = <A>);
> close(A);
> kill 1, $pid if($pid);
> }
>
> 1;
> -- end --
>
> The following will dlopen funcs.so and run the function returned by
> dlsym("shoutout"):
>
> RunDynamic funcs:shoutout on up
>
> A simple funcs.c is:
> -- begin --
> #include "config.h"
>
> void killhup(struct interface p,
> struct interface *e,
> struct interface r) {
> fprintf(stderr, "I am here with IP %s\n", inet_ntoa(p.ipaddr));
> }
> -- end --
>
> All this being development work -- YMMV.
>
> // Theo Schlossnagle
> // Principal Engineer -- http://www.omniti.com/~jesus/
> // Postal Engine -- http://www.postalengine.com/
> // Ecelerity: fastest MTA on earth
>
>
> _______________________________________________
> wackamole-users mailing list
> wackamole-users@lists.backhand.org
> http://lists.backhand.org/mailman/listinfo/wackamole-users
>