Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Author Topic: DSLStats on FreeBSD - Redux  (Read 2707 times)

displaced

  • Reg Member
  • ***
  • Posts: 270
DSLStats on FreeBSD - Redux
« on: August 28, 2017, 11:16:22 PM »

Hi,

A while back I was asking around about getting DSLstats running on FreeBSD.  I'd got as far as building it from source successfully and got the MDWS uploading working and was looking into getting it packaged up for installation via FreeBSD Ports system. 

However, that turned out to be rather complex, and I wasn't sure I'd have the free time to act as the port maintainer in future. 

Since then, there's been success making DSLstats available as a Docker container.  That's great if you're already using Docker on your FreeBSD system.  But, if you'd like to keep things 'slim', or your machine isn't meaty enough for the job, here's an alternative.


Background
FreeBSD has the ability to load 'personalities' via kernel modules.  These modules act as an abstraction, making FreeBSD's kernel appear to be a different OS to selected software.

Alongside the kernel module, FreeBSD also provides a subset of Linux's 'user-land' libraries. 

If we activate the Linux kernel module and install the relevant Linux libraries, DSLstats will run perfectly well on FreeBSD!

Prerequisites
This guide assumes that you have a working FreeBSD installation, including an Xorg-based windowing system.  If you want to run the machine headless, I'd suggest using the xrdp package.  This will let you use a Remote Desktop client on another machine to access a virtual X session for DSLstats to run within.

Also, the guide will list the steps I took to get DSLstats running on a FreeBSD 11.1 system.  I'll update this with info regarding 10.x systems when I get a chance to set up a virtual machine for testing.  The steps should be very similar if not identical, so feel free to have a try and post feedback if you're running 10.x and feeling adventurous!

Also, this is using the 32 Bit version of DSLstats.  I'm seeing some odd behaviour with the 64-bit version which I've not yet sorted.  However, the 32-bit version works fine on my 64-bit FreeBSD 11.1 system.

Enabling Linux Emulation

First, take a look to see if the linux kernel module is already loaded.  From a terminal prompt, issue the kldstat command:

% kldstat
Id Refs Address            Size     Name
 1   39 0xffffffff80200000 1f67a88  kernel
 2    1 0xffffffff82223000 3f18     amdtemp.ko
 3    1 0xffffffff82421000 2018f1   zfs.ko
 4    1 0xffffffff82623000 9aea     opensolaris.ko
 5    1 0xffffffff8262d000 5936     fdescfs.ko
 6    1 0xffffffff82633000 3650     ums.ko
 7    1 0xffffffff82637000 34d5c    pf.ko
 8    1 0xffffffff826b4000 bb55     tmpfs.ko


If you don't see any mention of 'linux' here, continue through this section to install it.  Otherwise, skip to the next section.

Load the linux kernel module:

sudo kldload linux


Run kldstat again to check that they've loaded correctly:

% kldstat
Id Refs Address            Size     Name
 1   39 0xffffffff80200000 1f67a88  kernel
 2    1 0xffffffff82169000 abe00    linux.ko
 3    4 0xffffffff82215000 df88     linux_common.ko
 4    1 0xffffffff82223000 3f18     amdtemp.ko
 5    1 0xffffffff82421000 2018f1   zfs.ko
 6    1 0xffffffff82623000 9aea     opensolaris.ko
 7    1 0xffffffff8262d000 5936     fdescfs.ko
 8    1 0xffffffff82633000 3650     ums.ko
 9    1 0xffffffff82637000 34d5c    pf.ko
10    1 0xffffffff826a9000 a877     linprocfs.ko
11    1 0xffffffff826b4000 bb55     tmpfs.ko


Now, to make sure these load whenever the machine reboots, add the following to your /etc/rc.conf file:

linux_enable="YES"

To make sure the system looks as 'linux-y' as possible, we need to mount a couple of locations into the filesystem.  Edit your /etc/fstab file and add the following two lines to the end:


linprocfs   /compat/linux/proc  linprocfs       rw      0       0
tmpfs    /compat/linux/dev/shm  tmpfs   rw,mode=1777    0       0


...then run these commands to actually mount the two locations:


sudo mount /compat/linux/proc
sudo mount /compat/linux/dev/shm


Install Libraries

There are a few packages to install to get DSLstats running.  Run each of these commands in succession to install these:


sudo pkg install linux_base-c7
sudo pkg install linux-c7-xorg-libs
sudo pkg install linux-c7-xorg-libs
sudo pkg install linux-c7-gdk-pixbuf2
sudo pkg install linux-c7-libpng


The first package there is the base linux environment - based on CentOS 7 (hence the 'c7'). The rest are dependencies needed by DSLstats (and many other GUI-based applications).

Download & Run DSLstats

Download DSLstats from dslstats.me.uk

Choose the 32-bit Linux version.

Once downloaded, extract the archive file.  Personally, I like to rename the resulting folder to simply 'dslstats'.  I'll assume you've done the same, and that the folder is in your home directory.  Feel free to move it elsewhere (/usr/local/ is probably the best place).

Back at a terminal, change to the dslstats directory:

cd ~/dslstats

Now, we need to 'brand' the executables to tell FreeBSD that these are Linux binaries that it should run within the Linux environment:


brandelf -t Linux dslstats
brandelf -t Linux upload17.l32


Now, assuming you're using a terminal prompt inside your GUI (X) session, start DSLstats now!

./dslstats

NOTE: You may get some errors/warnings about the location of 'curl' -- and maybe even some unhandled exception messages.  I found that this happened on first launch, but if I hit Ctrl+C in the terminal window and relaunched, the exception messages stopped. 

Setting Up DSLstats

Set up DSLstats as normal, but there's one setting you'll need to change if you're uploading to MDWS - the Path to curl executable.

Under the Configuration -> MyDSLWebStats tab, set the Path to curl executable to /usr/local/bin/curl

Remember to untick and re-tick the Upload data to MyDSLWebStats for the change to take effect.

You're Done!

Please leave any feedback for corrections, etc. and I'll investigate/update as needed.

I hope this is helpful to some people!

To-Do

I currently run DSLstats in an xrdp virtual session.  This is great because my machine's headless and I only need the most minimal of GUI environments for DSLstats.  Unfortunately it means I must remote-desktop into the machine and re-launch DSLstats should it ever reboot.  I need to find a way in the xrdp/x session configuration to get it to create a session and launch DSLstats automatically at startup.
« Last Edit: August 29, 2017, 07:57:30 AM by displaced »
Logged
YouFibre 1Gbit, OPNsense on Intel N100.  Ubiquiti UAPs.

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: DSLStats on FreeBSD - Redux
« Reply #1 on: August 29, 2017, 07:20:08 AM »

That's a terrific job! :clap:

I don't want to lumber you with unwanted work, but would you object if I put a link to this message on my website?
Logged
  Eric

displaced

  • Reg Member
  • ***
  • Posts: 270
Re: DSLStats on FreeBSD - Redux
« Reply #2 on: August 29, 2017, 07:54:56 AM »

Thanks! And feel free to link away - more than happy to answer forum threads, but maintaining a port is a little beyond me at the mo!

I’d like to get to the bottom of the problems with the 64bit version. The exception at startup states that there’s another instance of the program already running when there’s not - so clearly there’s some problem creating a mutex or somesuch under x64 which the code is assuming means the mutex/lock already exists.  Funny one, that.

Plus, the access violations at initial startup are odd - especially how they magically go away!

Out of curiosity, does Lazarus give you to option of creating debug builds?  If so, and if you’re happy to, would you mind doing a ‘with-symbols’ debug build alongside your next update?  It’s not critical, since we’ve got something that works.  But with that build, I’d be able to see where in the code the exception’s happening and perhaps infer what needs tweaking in the environment to avoid the errors!

Cheers!

Logged
YouFibre 1Gbit, OPNsense on Intel N100.  Ubiquiti UAPs.

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: DSLStats on FreeBSD - Redux
« Reply #3 on: August 29, 2017, 10:33:20 AM »

Lazarus can create debug builds with symbols quite simply. It's just a couple of tick boxes in the project configuration. The debug builds are compatible with GDB, and can optionally generate code for valgrind as well. I can do this whenever you want.
Logged
  Eric

displaced

  • Reg Member
  • ***
  • Posts: 270
Re: DSLStats on FreeBSD - Redux
« Reply #4 on: August 29, 2017, 10:40:55 AM »

Ah, great -- I thought it'd be reasonably simple but didn't want to presume!

Debug builds for the 32 and 64-bit versions of 6.0.6 would be great.  It seems valgrind isn't massively well supported on FreeBSD, so plain-old GDB is all I'll be using.

Whenever you next happen to be looking at the code would be fine, no rush!

Cheers,
Chris
Logged
YouFibre 1Gbit, OPNsense on Intel N100.  Ubiquiti UAPs.

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: DSLStats on FreeBSD - Redux
« Reply #5 on: August 29, 2017, 03:32:02 PM »

You can download the two of them here:

http://dslstats.me.uk/files/dslstats-6.0.6-debug.tar.gz
Logged
  Eric

displaced

  • Reg Member
  • ***
  • Posts: 270
Re: DSLStats on FreeBSD - Redux
« Reply #6 on: September 03, 2017, 09:43:38 PM »

Thanks, roseway.

The crash-on-startup in x86_64 is in the uniqueinstance.pas module.  The code that uses this in dslstats.pas is even commented to say 'this doesn't work on FreeBSD' and is wrapped in a platform-check.  Of course, as this is the Linux build, it's executing.  Quite why it fails in Linux emulation on the x86_64 version but not the x86_32 is a bit of a mystery.

gdb sadly gets itself into an unstable state stepping into this exception, so there's no really useful info to be gleaned.  It successfully detects that the IPC channel hasn't been created, but fails when creating it. 

I think I'll need to dust off my Pascal knowledge and build a small test app to see what's going on and experiment!
Logged
YouFibre 1Gbit, OPNsense on Intel N100.  Ubiquiti UAPs.

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: DSLStats on FreeBSD - Redux
« Reply #7 on: September 03, 2017, 10:54:49 PM »

I can easily remove the unique instance code. It's there because you can't sensibly run two instances of DSLstats on the same machine because they would both be overwriting each other's data in the configuration files directory. But if it's useful for your FreeBSD adaptation then it would be quite simple to do.
Logged
  Eric