Sunday, October 30, 2011

deluged on a server

I want to move my (quite limited) torrenting from my laptop onto the server. Here's how to run headless deluge on a server, and connect to it from the deluge client. (Instructions).

Since my server (Debian 6.0.3) is at version 1.2.3, but my Laptop (Ubuntu 11.10) is at version 1.3.3, using the GTK client won't work. I tired and tried, but ultimately the incompatibility defeated me...

...so instead of the GTK client, we'll use the web client. (There's also a console client)





Setup and start the deluged server

1) Run the following on the server as root:
apt-get install deluged deluge-console deluge-web
# To set this for automatic startup at boot, 
# see http://dev.deluge-torrent.org/wiki/UserGuide/InitScript

2) Run the following on the server as a user (not root)
deluged         # Run as USER to create the .config directory
pkill deluged   # Stop deluged

#Add an entry to the /home/USERNAME/.config/deluged/auth file
echo "USERNAME:my__deluge-only_password:5" >> /home/USERNAME/.config/deluged/auth

# Use deluge-console to change the config setting, allowing remote access.
# (For some reason, if you change .config/deluge/core.conf, the change is not persistent!)
deluge-console
config -s allow_remote True
exit

# Start deluged and deluge-web to launch the server and the web socket
deluged
deluge-web --fork

Connect to the server from the laptop:
Open a web browser to the server, port 8112: http: me.myserver.org:8112
Use the same password as the auth file (the "my_deluge-only_password")

And you should be in!

Try it with a small torrent (like a Debian Businesscard .iso)

Using runlevels to demote a network king to a mere baron

I have put enough services onto my server that it has become a single-point of failure. It's a router, a DSL modem, backup storage, and has network-shared drive, plus a few other cool things.

The key point of failure is the combination of Modem + Router. The PCI DSL card requires a custom driver, and sometimes after a system upgrade it needs to be reinstalled. The details of the wanrouter driver are here.

What I need is a failover mode: If the DSL fails to work, I want to use my old external modem and router. So I still want the system to run, but as a dchp-client server instead of a router.

Let's use some startup logic and runlevels to define two roles for the server: Network King routing over DSL, and faithful Baron merely connecting over wi-fi to the Linksys. And a bit of connective tissue so the machine automagically boots into the correct role, plus can be switched manually.

Internet <------+ Network King +-----> LAN

Internet <------+ Other router +------> LAN <------+ Faithful Baron 

Runlevel 1 - startup (Don't touch this)
Runlevel 2 - network testing
Runlevel 3 - server (Network King)
Runlevel 4 - client (Faithful Baron)
Runlevel 5 - unchanged from stock install
Runslevel6 - reboot (Don't touch this)

Decision logic:
If the server can connect to the internet over the dsl interface, then it is a King
Otherwise, it is a Baron.

Issues:
1) I need to change the LAN IP address of the server so it doesn't conflict with the router anymore!
2) All changes to the server must be tracked and undoable

Changes to the external router
Port-forward from the internet to the Baron (easy, one DMZ setting or separate port-forward settings for each service)

Server setup changes
1) Create a new directory to hold the three small scripts we are going to make, so you can keep track!
mkdir /root/startup-scripts

2) It's possible to create one really ugly /etc/networking/interfaces file, but let's not do that. Instead, we'll create separate interface files for runlevels 3 and 4. For convenience, let's put a link to them next to the original interfaces file.
cp /etc/network/interfaces /root/startup-scripts/runlevel-3-interfaces
cp /etc/network/interfaces /root/startup-scripts/runlevel-4-interfaces
ln /root/startup-scripts/runlevel-3-interfaces /etc/network/interfaces
ln /root/startup-scripts/runlevel-4-interfaces /etc/network/interfaces

3) Edit the runlevel 3 file (/root/startup-scripts/runlevel-3-interfaces)
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# This file is ONLY for runlevel 3 (Network King [router] mode)

# The loopback network interface
auto lo
iface lo inet loopback

# The ethernet jack and wi-fi antenna in bridged server mode
iface eth0 inet manual
iface wlan0 inet manual
     up hostapd -B /etc/hostapd/hostapd.conf
     down ifconfig mon.wlan0 down
     down pkill hostapd
auto br0                       
iface br0 inet static
     # Adding and removing the slave eth0 and wlan0 interfaces
     # is handled by /etc/init.d/kingbaron
     address 192.168.1.1
     broadcast 192.168.1.255
     netmask 255.255.255.0
     network 192.168.1.0
     up hostapd -B /etc/hostapd/hostapd.conf
     up route add -net 239.0.0.0 netmask 255.0.0.0 br0
     down ifconfig mon.wlan0 down
     down pkill hostapd
     down route del -net 239.0.0.0 netmask 255.0.0.0 br0

iface dsl-provider inet ppp
     pre-up /sbin/ifconfig dsl0 up # line maintained by pppoeconf
     provider dsl-provider

auto dsl0
iface dsl0 inet manual

4) Edit the runlevel 4 file (/root/startup-scripts/runlevel-4-interfaces)
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# This file os ONLY for runlevel 4 (Network dhcp client mode)

# The loopback network interface
auto lo
iface lo inet loopback

# The ethernet jack in client mode
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

# The wi-fi antenna in client mode
auto wlan0
iface wlan0 inet dhcp
     pre-up ifconfig wlan0 down
     pre-up iwconfig wlan0 mode Managed
     pre-up iwconfig wlan0 essid MY_LAN_NAME

5) Let's edit the original /etc/network/interfaces file to reduce startup time by not automatically raising the eth0 and wlan0 interfaces. We don't need those in runlevel 2, since only the DSL line will needs to be brought up.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The ethernet jack in client mode
# (Disabled during initial boot)
allow-hotplug eth0
iface eth0 inet manual

# The wi-fi antenna in client mode
# (Disabled during initial boot)
auto wlan0
iface wlan0 inet manual
     pre-up iwconfig wlan0 essid Klein-Weisser

# The following lines are auto-generated for the dsl connection

auto dsl-provider
iface dsl-provider inet ppp
     pre-up /sbin/ifconfig dsl0 up # line maintained by pppoeconf
     provider dsl-provider

auto dsl0
iface dsl0 inet manual

6) Create a new file for the startup testing and decision logic: /root/startup-scripts/kingbaron
#!/bin/bash

### BEGIN INIT INFO
# Provides:             runlevel_chooser
# Required-Start:       $network $remote_fs $syslog wanrouter
# Required-Stop:        $network
# Default-Start:        2
# Default-Stop:
# Short-Description:    Choose runlevels based on testing network connection to an interface
### END INIT INFO

# Functions

start_king_mode () {
   # If coming from runlevel N or 4, need to change from dhcp to static/Master
   [ runlevel=="4 2" ] && ifdown -a --interface=/etc/network/runlevel-4-interfaces
   [ runlevel=="N 2" ] && ifdown -a

   # If the br0 interface does not exist (coming from runlevel N), create it.
   [ $(brctl show | grep -c br0) -eq 0 ] && brctl addbr br0

   # Add the slave interfaces to br0
   [ $(brctl show | grep -c eth0) -eq 0 ] && brctl addif br0 eth0
   [ $(brctl show | grep -c wlan0) -eq 0 ] && brctl addif br0 wlan0

   # Bring up the King mode interfaces (except dsl0 and ppp0, which are already up)
   ifup -a -v --interfaces=/etc/network/runlevel-3-interfaces

   # Test that ifup worked
   [ $(ifconfig | grep -c mon.wlan0) -eq 0 ] && logger -i -s -t kingbaron "Failed to bring up wlan0...Sorry"
   [ $(ifconfig | grep -c br0) -eq 0 ] && logger -i -s -t kingbaron "Failed to bring up br0...Sorry"

   logger -i -s -t kingbaron "Network should be up now. If not, try 'ifconfig' for LAN interfaces and 'wanrouter' for the DSL interface"
   telinit 3
   exit 0
}

start_baron_mode () {
   # Shut down the dsl0 and ppp0 interfaces (not used in Runlevel 4).
   # Sometimes the signal needs to be sent twice
   [ $(wanrouter status | grep -c stopped) -gt 0 ] || wanrouter stop
   [ $(wanrouter status | grep -c stopped) -gt 0 ] || wanrouter stop

   # If coming from runlevel 3, need to change from static/Master to dhcp
   # If coming from runlevel N or 4, we can keep the same interfaces
   [ runlevel=="3 2" ] && ifdown -a --interface=/etc/network/runlevel-3-interfaces

   # If br0 is up, bring it down. If it still has slaves from runlevel 3, unslave them
   [ $(ifconfig | grep -c br0) -gt 0 ] && ifconfig br0 down
   [ $(brctl show | grep -c wlan0) -gt 0 ] && brctl delif br0 wlan0 && ifconfig wlan0 down
   [ $(brctl show | grep -c eth0) -gt 0 ] && brctl delif br0 eth0 && ifconfig eth0 down

   # If wlan0 is stuck in Master mode from runlevel 3, unstick it
   [ $(ifconfig | grep -c mon.wlan0) -gt 0 ] && pkill hostapd && ifconfig wlan0 down && iwconfig wlan0 Managed

   # Bring up the Baron Mode interfaces, ignoring anything already up
   ifup -a -v --interfaces=/etc/network/runlevel-4-interfaces

   # Sometimes the network fails to come up, especially if it didn't go down properly
   # Check for the most common errors (like WiFi not going up) and try to autofix
   if [ $(ifconfig | grep -A2 wlan0 | grep -c inet) -eq 0 ]; then
      logger -i -s -t kingbaron "Wireless failed to come up. Resetting and trying again..."
      ifconfig wlan0 down
      iwconfig wlan0 mode Managed
      iwconfig wlan0 essid MY_ESSID
      ifconfig wlan0 up
      dhclient -v wlan0
   fi
   logger -i -s -t kingbaron "Network should be up now. If not, try 'ifconfig' and 'iwconfig'"
   telinit 4
   exit 0
}

logger -i -s -t kingbaron "Testing for DSL connectivity"

# Check for the existence of a the DSL interface. If it exists, try to get a connection
# If the internet is reachable, goto runlevel 3 (King mode). Else goto runlevel 4 (Baron mode)

# If wanrouter is not already running, then start it
flag="wanrouter off"
[ $(wanrouter status | grep -c Connecting) -eq 0 ] && flag="wanrouter on"
[ $(wanrouter status | grep -c Connected) -eq 0 ] && flag="wanrouter on"
[ $flag=="wanrouter off" ] && wanrouter start

# If the test interface does not exist, then start client mode
if [ $(ifconfig | grep -c dsl0) -eq "0" ]; then
   logger -i -s -t kingbaron "The DSL interface (dsl0) does not exist. Entering dhcp client mode"
   start_baron_mode
fi

# If the test interface exists, then wait for wanrouter to start up
# Average start time is about 20 seconds
logger -i -s -t kingbaron "Found the DSL interface. Waiting up to 40 seconds for the DSL link (dsl0) to come up"
i="0"
while [ $i -lt 40 ]; do
   sleep 1
   i=$[$i+1]
   [ $(wanrouter status | grep -c Connecting) -gt 0 ] || i=100
done

# If time expires without the wanrouter starting, print the error and start client mode
if [ $i -lt 100 ]; then
   logger -i -s -t kingbaron "dsl0 interface failed to come up. Entering dhcp client mode"
   start_baron_mode
fi

# If the wanrouter comes up properly, then wait for a ppp connection
logger -i -s -t kingbaron "dsl0 up. Waiting up to 40 seconds for a PPPoE connection (ppp0)"
pon dsl-provider
i="0"
while [ $i -lt 40 ]; do
   sleep 1
   i=$[$i+1]
   [ $(route | grep -c default) -gt 0 ] && i=100
done

# If time expires without the ppp connection starting, print the error and start client mode
if [ $i -lt 100 ]; then
   logger -i -s -t kingbaron "ppp0 failed to come up. Entering dhcp client mode"
   start_baron_mode
fi

# If all has gone well, and the ppp connection comes up
logger -i -s -t kingbaron "ppp0 came up. This system has DSL connectivity. Starting Router services"
start_king_mode

7) Install the script:
chmod +x /etc/startup-scripts/kingbaron            # Make executable
ln /root/startup-scripts/kingbaron /etc/init.d/    # Hardlink to init.d
update-rc.d kingbaron defaults                     # Symlink to runlevel 2

8) Take a look at /etc/rc2.d/. See all those router and server services that shouldn't operate in runlevel 2? Or shouldn't operate in runlevels 2 and 4? Use the command "update-rc.d $Name disable 2" to disable the appropriate services in runlevel 2 (or 4).

...And do a whole lot of tweaking and testing, and voila! An automated detection and failover system. If the DSL line is active, router services start and the interfaces come up in static/master mode. If the DSL line isn't active, router services don't start and the interfaces come up in dhcp mode. Runlevel 2 is the decision mode, runlevel 3 is the King (router) mode, and runlevel 4 is the Baron (dhcp) mode.

All the server services (samba, cups, etc) still operate, regardless. And you can manually reset with the command 'telinit 2' to make the system reset the interfaces and router services.

TIP: Look for related posts using the kingbaron tag.

Friday, October 28, 2011

The better, easier way to install wanpipe

In this post from march 2011, I described my successful installation of Sangoma software for my Sangoma S518 PCI DSL Modem.

Well, for unknown reasons a couple weeks ago the software failed completely upon a reboot.

So it's time to reinstall. And this time, to do it the right way. (Instructions)

In this case, PPPoE, two interfaces are created, dsl0 and ppp0. Wanrouter creates the physical dsl0 interface, and the pon/poff creates the virtual ppp0 interface that actually shows up in the routing table and enables real network activity.

To install wanrouter, do the following as root:
#Create the build environment
apt-get install gcc g++ automake autoconf libtool make libncurses5-dev flex bison patch libtool linux-headers-$(uname -r)

# Get the latest driver tarball
cd /usr/src
wget ftp://ftp.sangoma.com/linux/current_wanpipe/wanpipe-3.5.23.tgz
tar xvfz wanpipe-<version>.tgz

# Create a deb package from the tarball
cd wanpipe-<version>
./Setup builddeb    # no make, no prepare. Setup does it all for you.
dpkg -i wanpipe_<version> 
And that's all for the install.

It seems last time I made a few mistakes. Live and learn:
1) I missed a couple build dependencies like automake and autoconf
2) I used obsolete information to prepare for the installation
3) I completely missed the builddeb option!

Next, configure the dsl0 interface. The DSL line does not need to be connected:
wanrouter hwprobe  # Test if the card is detected
wancfg             # Ncurses tool to configure the wanpipe and interface
                   # Name the interface (foe example dsl0)
                   # Enable the startup and shutdown scripts
                   # Note the name of the configuration file (wanpipe1)

Let's test to make sure wanrouter works:
wanrouter start wanpipe1   # Test - should bring up interface
ifconfig                   # The interface should be on the list
ifconfig dsl0 down         # Test - should bring down interface
ifconfig                   # The interface should *not* be on the list
ifconfig dsl0 up           # Test - should bring up interface
ifconfig                   # The interface should be on the list
wanrouter stop wanpipe1    # Test - should being down interface
ifconfig                   # The interface should *not* be on the list

Next, create and configure the ppp0 connection. The DSL line must be connected for this step to work.
wanrouter start   # Activate wanrouter so pppoeconf can detect it
ppoeconf          # Configure ppp0
                  # The pppoeconf program will ask two important questions:
                  # 1) Do you want to start PPPoE at each startup? 
                  #  NO, because it will fail - dsl0 will not be ready yet.
                  # 2) Do you want to start PPPoE now? 
                  #  You can, but if there are any problems, the process will be 
                  #  orphaned. Kill it with the command 'poff -a'
                  # You can see the PPPoE configuration (link to the dsl0 interface) 
                  # in /etc/ppp/peers/dsl-provider. You can see your dsl username 
                  # and password in /etc/ppp/pap-secrets.

Configuration is complete. DSL connectivity should work now.

Let's test it:

To manually open/close the dsl connection:

wanrouter start     # To bring up the dsl0 interface. Wanrouter does this at boot already.
pon dsl-provider    # To bring up the ppp0 interface, which is the real PPPoE connection 
                    # (with an IP address).
plog                # A handy debugging tool. Take a quick look at the log
ifconfig            # The dsl0 interface does not have an IP. 
                    # The ppp0 interface does have an IP
route               # The upstream DSL server should be showing as a gateway,
                    # and a 'default' route should exist
ping <example>      # Test network connectivity
poff -a             # To close the PPPoE connection, and bring down the ppp0 interface
wanrouter stop      # To bring down the dsl0 interface. Wanrouter does this at shutdown already,


To automatically open/close the dsl connection: Insert a start script and a stop script as follows. Automatically starting takes about 45 seconds:

echo "pon dsl-provider" >> etc/wanpipe/scripts/wanpipe1-dsl0-start
echo "poff -a" >> etc/wanpipe/scripts/wanpipe1-dsl0-stop
# If these don't work, then you may need to use 'wancfg' to enable the start/stop scripts.



For my own reference, here's the Setup output:
me@mysystem:/usr/src/wanpipe-3.5.23# ./Setup builddeb
Enabling the FR Protocol
Enabling the CHDLC Protocol
Enabling the PPP Protocol
Enabling the X25 API Protocol
Enabling the ADSL Protocol
Enabling the Multi Protocol Driver
Enabling the AFT TE1 Support
Enabling the AFT TE3 Support

WARNING: Module installation dir mismatch!
         Linux source name  = 2.6.
         Current image name = 2.6.32-5-686

  If you are building wanpipe modules for the
  currently running image, use the 2.6.32-5-686
  directory (i.e. select 'y') 

Install modules for current image: 2.6.32-5-686 ? (y/n) y

Installing modules for kernel: 2.6.32-5-686 !


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------


  
 WANPIPE DEB BUILD

Wanpipe DEB will be build based on the 
following Environment variables.
 
 1. Linux Source Dir  : /lib/modules/2.6.32-5-686/build

 2. Linux Source Name : 2.6.32-5-686

 3. Current Image Name: 2.6.32-5-686
 
 4. CPU Type          : i686
 
 5. Wan Protocols     : FR-CHDLC-PPP-MFR-MPROT-X25-AFT_TE1-AFT_TE3-ADSL-ATM
 
 6. Build Directory   : /usr/src/wanpipe-3.5.23/debbuild 



Would you like to build WANPIPE DEB ? (y/n) y
Enabling the FR Protocol
Enabling the CHDLC Protocol
Enabling the PPP Protocol
Enabling the X25 API Protocol
Enabling the ADSL Protocol
Enabling the Multi Protocol Driver
Enabling the AFT TE1 Support
Enabling the AFT TE3 Support

 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

WANPIPE INSTALLATION

You are about to install WANPIPE Multi-Protocol
TDM Voice & WAN Router into your system.

This script will examine your system, then install, create
and/or modify necessary files and directories.

You must have Linux Kernel Headers along with
full development tools (i.e. GNU C compiler and utilities)
installed in order to be able to install this product.

This script will automatically compile all WANPIPE kernel
drivers and install them in their appropriate directory.

If you are installing Wanpipe for ASTERISK/ZAPTEL this
script will will prompt you for zaptel source location.

If you have previoulsy installed WANPIPE, this release
will overrite/upgrade full release without the need to
uninstall first!

IMPORTANT:
It is always recommended to say YES to all options
prompted during the install!

Please visit: http://wiki.sangoma.com for more info.


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

Fixing file permissions...

Verifying files and fixing permissions ...Done
Checking for C developement tools ...(gcc) OK
Checking for C++ developement tools ...OK
Checking for Make utility ...OK
Checking for ncurses library ... OK
Checking for Perl developement tools ...OK
Checking for AWK ...OK
Checking for FLEX ...OK
Checking for Patch ...OK
Checking for libtermcap-devel...OK
Checking for bison...OK
Checking for libtool...OK


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------


Installing WANPIPE Device Drivers: Linux KERNEL

To integrate WANPIPE Multi-Protocol Voice & WAN Router 
modules into the Linux kernel, the kernel has to be 
updated with latest wanpipe sources.  Install will only
modify existing wanpipe source that is already in the
Kernel. 

IMPORTANT:
It is always recommended to say YES to all options 
prompted during the install!


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

Setting linux directory to /lib/modules/2.6.32-5-686/build



Upgrading WANPIPE kernel documentation ...Done.


Installing WANPIPE include headers ...Done.

WANPIPE device drivers upgraded successfully!


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

WANPIPE KERNEL DRIVER COMPILATION
 
The next step in WANPIPE installation involves compiling 
WANPIPE kernel modules.  

This script will compile and install WANPIPE modules
into the currently running linux kernel.

For greater customization you will be prompted to
select which Protocol/Drivers you would like to
build into the WANPIPE kernel modules.

Wanpipe for Asterisk/Dahdi/Zaptel
 Default for Asterisk/Dahdi/Zaptel
Wanpipe for Wan Routing/API 
 Default for Wan/IP Routing and Data API
Wanpipe for Asterisk SMG/SS7
 Default for Asterisk SS7
Wanpipe for TDM API
 Default for FreeSwitch and Voice API  

Custom Compilation:
------------------
  Customise WANPIPE driver compilation to add only the
  protocols that you need.  This way one can reduce
  the size of the WANPIPE kernel drivers.

Refer to http://wiki.sangoma.com for more info


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------


Checking for SMP support ...Enabled.

Checking current processor type ...i686

Wan Update Flags:  -DWANPIPE_MOD_266_FORCE_UPDATE


--------------------------------------------------
CFLAGS: gcc -Wp,-MD,.wanpipe.o.d -nostdinc -iwithprefix include -D__LINUX__ -Dlinux -D__KERNEL__ -I/usr/src/wanpipe-3.5.23/debbuild/usr/include/wanpipe -I/lib/modules/2.6.32-5-686/build/include  -DMODULE   -DWANPIPE_MOD_266_FORCE_UPDATE  make: Entering directory `/usr/src/linux-headers-2.6.32-5-686'
make: Leaving directory `/usr/src/linux-headers-2.6.32-5-686'
--------------------------------------------------

Checking for REGPARM kernel option ...
Warning: Failed to determine regparm from Makefile defaulting to YES!

Enabled.

Compiling General WANPIPE Driver for 2.6.X Kernel .....Done.


WAN HWEC module enabled and compiled!

FR compiled for GCC Ver=3 Arch=i686 File:wanpipe_fr.gcc3.i686.regparm.o

PPP/CHDLC compiled for GCC Ver=3 Arch=i686 File:wanpipe_sppp.gcc3.i686.regparm.o

ATM compiled for GCC Ver=3 Arch=i686 File:wanpipe_lip_atm.gcc3.i686.regparm.o

ADSL binary compiled for GCC Ver=3 Arch=i686 File:wanpipe_adsl.gcc3.i686.regparm.o

ATM binary compiled for GCC Ver=3 Arch=i686 File:wanpipe_atm.gcc3.i686.regparm.o

Linking Wanpipe Driver and protocols ...Done.

Updating Kernel Modules ...Done.

Compilation Successful.

 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

WANPIPE META CONFIGURATION

There are two configuration files associated with WANPIPE.  

1) /usr/src/wanpipe-3.5.23/wanrouter.rc: 
 - defines locations of important files such as lock
   and configuration files as well as start/stop 
   order of multiple WANPIPE devices.
2) /usr/src/wanpipe-3.5.23/wanpipe1.conf:
 - main configuration file for each WANPIPE device.
 - defines interfaces, hardware and protocol information.
 - this file can be created using the 'wancfg' GUI
   utility or manually based on sample files located
   in /etc/wanpipe/samples.
   
Please read the WanpipeInstallation.(pdf/txt) manual for further
information.


 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

WANPIPE UTILITIES SETUP

WANPIPE utilities are used to:
 1) create configuration files: for Zaptel and Asterisk
  /usr/sbin/wancfg_zaptel #Zaptel and Asterisk
  /usr/sbin/wancfg_dahdi #Dahdi and Asterisk
  /usr/sbin/wancfg_smg #BRI/SS7, Zaptel and Asterisk
  /usr/sbin/wancfg_tdmapi #TDM API
 2) create WANPIPE WAN/IP configuration files.
  (/usr/sbin/wancfg)
 3) start,stop,restart individual/all devices and interfaces.
  (/usr/sbin/wanrouter)
 4) debug line, protocol and driver problems.
  (/usr/sbin/wanpipemon)
 5) aid in WANPIPE API development
  (/etc/wanpipe/api)

Refer to the WanpipeInstallation.(pdf/txt) for more information.

Compiling WANPIPE LibSangoma API library ...Done.



Compiling WANPIPE Utilities ...Done.


Compiling WANPIPE WanCfg Utility ...Done.


Compiling WANPIPE API Development Utilities ...Skipped, no makefile

Compiling WANPIPE HWEC Utilities ...Done.


 WANPIPE Environment Setup Complete !!!

Installing WANPIPE Files ... !
Installing  WANPIPE Utilities in /usr/src/wanpipe-3.5.23/debbuild/usr/sbin
Installing wanrouter.rc in /usr/src/wanpipe-3.5.23/debbuild/etc/wanpipe
Installing wanpipe libraries in /usr/src/wanpipe-3.5.23/debbuild/etc/wanpipe
Installing firmware in /usr/src/wanpipe-3.5.23/debbuild/etc/wanpipe/firmware
Installing documentation in /usr/src/wanpipe-3.5.23/debbuild/usr/share/doc/wanpipe
Installing sample api code in /usr/src/wanpipe-3.5.23/debbuild/etc/wanpipe/api
Installing AFT Firmware update utility in /usr/src/wanpipe-3.5.23/debbuild/etc/wanpipe/util
Installing driver headers in /usr/src/wanpipe-3.5.23/debbuild/etc/wanpipe/api/include/linux
Installing Hardware Echo Cancel Utilites

 ----------------------------------------------------------
           WANPIPE v3.5.23 Installation Script
     Copyright (c) 1995-2011, Sangoma Technologies Inc.
 ----------------------------------------------------------

WANPIPE INSTALLATON: COMPLETE
 
WANPIPE installation is now complete. WANPIPE kernel drivers 
and configuration/debug utilities have been compiled and installed.

 1) Proceed to configure the WANPIPE drivers:
  Asterisk/Zaptel  : /usr/sbin/wancfg_zaptel
  Asterisk/Dahdi   : /usr/sbin/wancfg_dahdi
  TDM API          : /usr/sbin/wancfg_tdmapi
  SMG SS7/BRI/PRI  : /usr/sbin/wancfg_smg
  WAN Routing/API  : /usr/sbin/wancfg
 2) Use the /usr/sbin/wanrouter startup script to start and stop
    the router. (eg: wanrouter start)
 3) To uninstall WANPIPE package run ./Setup remove
  
Please read http://wiki.sangoma.com for further instructions.


WANPIPE DEB BUILD SUCCESSFUL

The new rpm is located in /usr/src/wanpipe-3.5.23:  wanpipe_3523-k266_i686.deb

To install run:
 dpkg -i 

Thursday, October 27, 2011

Update Problem - one bug, three symptoms

Upon upgrading in one afternoon from 10.10 to 11.04 and then to 11.10, I found a couple problems.


1) No boot! Nooooo!

I suspect I got bit by bug 858122. The workaround is in comment #22, and works.

But it made me wonder...

See, you can simply rename the symlinks for shutdown, but then the next time a package manager runs "update-rc.d", everything will get hosed again. Looks like each of 5 init.d scripts needs to be patched to show accurate #stop init information, and those patched pushed upstream...if upstream even has the problem.

That's why Comment #22 is a workaround instead of a fix.


2) Very slow boot

According to syslog,
Oct 19 13:54:06 cheesebot-supremo kernel: [ 3.362104] EXT3-fs (sda1): mounted filesystem with ordered data mode
Oct 19 13:54:06 cheesebot-supremo kernel: [ 33.253915] lp: driver loaded but no devices found
So let's try commenting out the lp driver in /etc/modules
I wonder...will CUPS still work after that?

Answer: Turns out to bot be an issue, but another arcane symptom of the same bug.


3) Boot Message "Waiting for Network Configuration"

Not really finding anything on it, seems polluted with #1.

Could there have been an initscripts install failure during an upgrade?

Answer: Turns out to not be an issue, but yet another arcane symptom of the same bug.

The takeaway: A reminder to be methodical attacking bugs. Fix one, test it, and move on.

Wednesday, October 19, 2011

Backup solution: rdiff-backup

It's time to finally get serious about my laptop backups.

I tried backup-manager and rsnapshot, but neither really met my needs for a simple, scriptable, push-to-remote-server-via-ssh backup solution.

Let's try rdiff-backup.

Here's what I think I want:

  1. Triggered by laptop connecting to the network and/or cronjob
  2. If the server's backup drive is not mounted, mount it
  3. Do a diff-based backups
  4. Unmount the backup drive
The heart of the backup is the rdiff-backup command. The rdiff-backup package must be installed on both client and server (they can be different versions).

 
# The basic rdiff-backup syntax is: rdiff-backup [options] [machine::]/path/to/original [machine::]/path/to/backup

# Here's a test command to backup my laptop /home directory to the server via ssh:
# option: --terminal-verbosity 5 (tell me a lot)
# option: --remote-schema (necessary for nonstandard ssh ports)
rdiff-backup --terminal-verbosity 5 --remote-schema 'ssh -p $PortNumber %s rdiff-backup --server' /home/me me@myserver.com::/mnt/Laptop/backups/me/ 
# Here's a test command to see how many backups are stored
rdiff-backup -l --terminal-verbosity 5 --remote-schema 'ssh -p $PortNumber %s rdiff-backup --server' me@myserver.com::/mnt/Laptop/backups/me 

You can see how this can be scripted to make things easy:


#!/bin/sh
# This script backs up my laptop to the server's /mnt/Laptop-backup/backups directory
 
# Do pre-backup stuff 
Schema="ssh -p $PortNumber %s rdiff-backup --server"
# Backup the home folder  
rdiff-backup --remote-schema '$Schema' /home/me me@myserver.com::/mnt/Laptop/backups/me 

# Backup /var, including the package list and cache and all the logs 
rdiff-backup --remote-schema '$Schema' /var me@myserver.com::/mnt/Laptop/backups/var 
# Backup /etc, including the firewall script and upstart/init scripts 
rdiff-backup --remote-schema '$Schema' /etc me@myserver.com::/mnt/Laptop/backups/etc 
# Backup /opt, mostly unpackaged non-debian stuff 
rdiff-backup --remote-schema '$Schema' /opt me@myserver.com::/mnt/Laptop/backups/opt 
# Do post-backup stuff
exit 0



What kind of pre- or post- backup actions? How about sanity checks, like that the server is available?

Since the server requires root to mount the backup drive, we need to create a socket for backups. The server will see which machine is asking to send or complete a backup, and mount/unmount the appropriate drive.
We need to write some logic to trigger the process.