The Haiku/BeOS Tip Server
Tips and tricks for Haiku/BeOS users

Scheduled network restarts

Contributed by: Scot Hacker
This tip is valid for: Both BeOS and Haiku

The BeOS network stack is in the process of being completely re-written from scratch, and replaced with a high-powered stack based on BSD networking (see the BONE story at BeNews for more information). BONE is scheduled to be released as an upgrade some time after R5 is released.

Until that time, there are two instances in which it can be handy to be able to restart networking automatically according to a schedule or script. Specifically:

  1. If you’re running a BeOS web server, you’ll find that some tcp threads aren’t closed properly. Over time (around 14,000 hits), these unclosed threads can clog the network stack, which kills networking. To check on the status of these threads, type ps | grep tcp into a Terminal. Networking can be restarted without rebooting by clicking Restart Networking in Network prefs, but you’ll probably want to automate this so it happens at regular intervals without manual intervention. 
  2. If you connect via DHCP, your lease on given IP or DNS addresses may expire every day or two, depending on how your provider sets things up. You may want to have networking restarted every 24 hours or whatever to automatically grab new addresses. <./OL>First of all, you need a command capable of restarting networking, so you have something to invoke from your schedule or script. Grab this updated version of John Wiggins net_restart and see the included readme. You’ll need to compile the source for your platform; the instructions are very easy. Move the compiled net_restart binary to ~/config/bin.

    While your first instinct might be to invoke net_restart from cron, you’ll quickly discover that this isn’t so easy — cron doesn’t have access to all the environment variables networking needs to be restarted correctly. I wrestled with this for quite a while before giving up. Fortunately, there’s another way. Grab a copy of Brian Tietz’ Scheduler from BeDepot. Invoke net_restart from Scheduler, and everything will work perfectly. Scheduler is also a native BeOS app rather than a port, and is 10x easier to use.

    That leaves one missing piece — when you restart networking, you’ll kill your web server. I use Robin Hood, and wrote a brief script to get around this problem. The script simply kills the Robin Hood daemon, runs net_restart, and restarts the daemon. Save this script as ~/config/bin/network_getup and invoke it from Scheduler, rather than net_restart itself. You may have to tweak some paths to match paths on your system.

    /bin/kill -9 rhdaemon
    /boot/home/config/bin/net_restart
    /boot/apps/net/RobinHood/server/rhdaemon &

Posted in Scripting


(comments are closed).