Weblog entry #5 for endecotp
Firstly, I need to deal with networking. Compared to every other box I have there are two differences: it has two network interfaces (wired and wireless) and they can be connected and disconnected at any time. So I have marked neither interface as "auto" but both as "allow-hotplug" in /etc/network/interfaces. But this isn't quite sufficient, as the wired interface is always present : it's just the cable that comes and goes. After a lot of searching I found ifplugd, which waits for cable attach/detach events and does the necessary work in response; the Debian package integrates nicely with /etc/network/interfaces so that it works out-of-the-box.
Now I just need to work out how to manage having two network interfaces. I think it's right to say that the two interfaces should have different IP addresses, but that I can associate both IP addresses with the same hostname. Is that right? Ideally, I want to be able to ssh to the machine using its hostname without having to worry about which interface is up at the moment. Will the client automatically try each possible IP address in turn until it finds one that works? I doubt it! Any ideas anyone?
The other thing that I need to set up is anachron, so that the jobs that run daily (such as an over-the-net backup) only run when the network is up. I think I need to somehow couple the if-up hooks into anacron somehow. Has anyone ever done anything like that?
Thanks for any suggestions.
Comments on this Entry
Try network-manager* packages. They will catch up network related events and make network "just work" for you, I am using it with my EEE 900.
I personally never used anacron, but afaik, remove cron, install anacron, and voila.
BTW, join the Debian EEE mailing list / IRC / Wiki: http://wiki.debian.org/DebianEeePC .
Bye.
[ Parent | Reply to this comment ]
anacron will try to run jobs if the machine is on, even if the network is not connected. A bit more magic is needed.
Yes, I've joined that list.
[ Parent | Reply to this comment ]
No idea if it'll work though :)
Can't help you on the anacron stuff unfortunately :/
[ Parent | Reply to this comment ]
I think that the issue with the association between hostname and IP is more at the DNS than at the machine itself. What kind of DNS do you rely upon for your local network?
Another thing: who decides the IP address of the wired and wireless cards? Do you have a DHCP server? If you have a wifi router, have you tried configure it to serve the same IP to both your wired and wireless MAC addresses?
Regarding anachron, I used to have a similar problem with fetchmail,which I wanted to be running only when I was online. I had resorted to a rather rough solution with a temporary file acting as a flag: the if-up/down script would create/delete it, while the anachron script would test its presence before starting.
[ Parent | Reply to this comment ]
> IP is more at the DNS than at the machine itself.
Yes, absolutely.
> What kind of DNS do you rely upon for your local network?
> Another thing: who decides the IP address of the wired and
> wireless cards? Do you have a DHCP server?
Yes, I'm using DHCP, but the DHCP server is configured to allocate fixed IP addresses based on the MAC addresses. So it's almost like using static IPs.
> If you have a wifi router, have you tried configure it to
> serve the same IP to both your wired and wireless MAC addresses?
That doesn't sound like a good idea to me; my understanding was that you should never have duplicate IP addresses. Is there anyone who really understands this stuff who can comment?
[ Parent | Reply to this comment ]
If not, there is no problem with many IP on a machine. How do you think routers work, do you :)
You already have more than one address. loopback (127.0.0.1), your broadcast address and your ordinary address.
You can use any one to talk to your machine. DNS can have many A-records for same name. Clients, as ssh, is supposed to use them in a round robin fashion.
You can have cron and anacron installed at the same time. If you start your net conenctions with ifup, you can always run scripts when network is up, like sending mail, dynamic setting DNS A record to your machine etc.
[ Parent | Reply to this comment ]
I've noticed in the anacron man page that it can take an optional command-line parameter that is matched against the names of the jobs (and defaults to '*'). So presumably I could name my anacron jobs as e.g. either net-xxxx or nonet-xxxx, and then run anacron 'net-*' from ifup and anacron 'nonet-*' for the regular daily thing. Has anyone ever done anything like that?
> temporary file acting as a flag: the if-up/down script would
> create/delete it, while the anachron script would test its
> presence before starting.
The trouble with that is that, AFAICT, the script has no way to report to anacron that it didn't really run and that it should be retried sooner than the normal 24 hours.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
1. I want to run anacron when the network comes up, so I put a script in /etc/network/interfaces/if-up.d/anacron that invokes anacron.
2. I remove the existing hard-coded test for ac power in init.d/anacron.
3. I want to run anacron when mains power comes on. I haven't worked out how to do that yet; I think I need an "acpi action", or something. Anyone know?
I'm a bit concerned that the network, or the mains power, could come on and go off before the anacron jobs have finished and that in this case they will have been marked as done. It would surely be better to mark them as done once they're finished, wouldn't it? The culprit is /etc/cron.daily/0anacron: what's it for?
So anacron will now get invoked in 4 conditions:
- At boot.
- At 0730 each day.
- When the network comes up.
- When the mains power comes on.
4. Now I change /etc/anacrontab so that it calls a script, rather than invoking
run-parts directly, and the script does something like this psuedo-code:
suffix=""
if the network is up
then
suffix+=".net-up"
else
suffix+=".net-down"
fi
if mains power is on
then
suffix+=".mains"
else
suffix+=".battery"
fi
nice run-parts --report /etc/cron.$interval$suffix
I may need more fine-grain control over the network condition, as some scripts might not want to be run over a pay-per-megabyte connection...
4. Now I symlink all of the scripts in /etc/cron.{daily|weekly|monthly} into directories with names that indicate the conditions in which they should be run.
et voila.
I'll let you know how I get on...
[ Parent | Reply to this comment ]