Some Bits: Nelson's log

10 posts in January 2019

Ubuntu 18.10 install notes

I’m updating my venerable home Linux server to Ubuntu 18.10. Installing on an SSD, and I figured I’d take the advantage to start over rather than bring along this Ubuntu install I’ve been coddling since 2011. Nothing like a little spring cleaning.

It’s remarkably tough to tell what all is running on a crusty old barnacle server like mine. I found the output of “ps -xaf” and looking at crontabs to be most useful. systemctl’s output is so noisy to not be very helpful. nmap is a good backstop for checking out network services.

All told it took about 2 hours to get the software environment set up more or less like I used to have it. That seems incredibly fast to me! It took 2-3 more hours to install more persnickety things and I am still apt installing various random command line tools I’m missing.

Boy SSDs are nice. The machine boots in about 6 seconds. Really 3, but then we waste 3 seconds (or more) waiting on the buggy r8169 Realtek driver for the ethernet to come up. I tried ordering a replacement Intel NIC but the one that arrived from Amazon was counterfeit.

The drive I’m replacing has run for 61289 hours, or just about 7 years. Been turned off and on 41 times. Smart has logged 0 errors for it. Not bad, li’l WD Blue!

Things I did and random notes

“curtin” is the name of the Ubuntu installer. It leaves a couple of little named turds behind in /etc/apt/, /etc/cloud, and /etc/default/grub.d.

A lot of Ubuntu wiki docs are seriously outdated, often describing things that were only relevant in 2014 in the pre-systemd days. Caveat lector.

Configuration change

Immediately run apt update; apt upgrade. No idea why this isn’t done automatically.

Add a static IP configuration in /etc/netplan, removing the old 50-cloud-init.yaml that was there. The default DHCP configuration is perfectly reasonable but I want my server to work even if DHCP is down.

Edit /etc/default/grub to add fsck.repair=yes to the kernel command line. I’m not certain but I think this is the systemd way to ensure the boot disk is really fscked at boot time. Note there’s a bug in Ubuntu where /etc/default/grub.d/50-curtin-settings.cfg overrides the setting of GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub. I swore a little and then edited the offending 50-* file. This bug may be fixed in December 2018.

Stuff I installed

python3.7 and python3.7-venv. Cosmic (18.10) defaults to 3.6.

chrony to replace the crappy systemd NTP implementation.

plexmediaserver from their Ubuntu repo. Bless their hearts, this is still buggy so many years later, but it mostly works. Ignore any weird warnings about “Conflicting distribution”.

postfix as a local machine. this means mail stays entirely local, so mostly useless, but lets cron errors get through

munin. good ol’ system monitoring. I love the inscrutable graphs.

rsnapshot for backups both local and remote. I like the idea of Duplicati but after its last install corrupted itself I’m not in a hurry to install it again.

samba. This just worked?! I borrowed bits of my config from before but that was pretty simple, just set up a couple of shares. Samba used to be such a heartache to get working, amazing.

SABnzbd for Usenet downloads. This turned out to be remarkably complicated. Ubuntu 18.10 has a recent version in the repo, but the setup script is not great.

  1. Install sabnzbdplus. Ignore the suggested packages
  2. Create a nzb user. useradd -r nzb; usermod --lock -s /usr/sbin/nologin nzb
  3. Edit /etc/default/sabnzbdplus. You have to change USER. Default port is localhost:8080, I changed that too.
  4. service sabnzbdplus start
  5. point a web browser at the instance, use the configuration wizard
  6. if you had an old config, it’s stored in ~nzb/.sabnzbd/sabnzbd.ini. Server passwords are helpfully in plaintext.

Stuff I didn’t have to do

Some things I’m used to doing on new systems, but weren’t necessary.

Install locate, the doodad that lets you do a fast find for a filename. Ubuntu 18.10 comes with mlocate already installed.

Set up unattended-upgrades for security fixes. It was already installed for me.

Set up powersaving. The default configuration is powersaving for the CPU, you can verify via cat /sys/devices/system/cpu/cpu$FIRSTCPU/cpufreq/scaling_available_governors. (To configure this see systemd ondemand or else cpufrequtils).

Change the I/O scheduler. CFQ looks to be the default now.

Monitoring EdgeOS bandwidth with Munin

Ubquiti’s routers are reliable and flexible, but they lack a certain.. consumer polish. One thing missing from the graph is any sort of historical bandwidth tracking or graphs. There’s no way to see what bandwidth you used in the last 5 minutes, much less the last year.

But EdgeOS does support SNMP. So you can collect the SNMP data on a Munin node running on another computer and graph it.

Step 1: turn on SNMP following something like these instructions. I did this via the router GUI instead using the Config Tree wizard. The two settings that are important are

snmp {
     community public {
         authorization ro
     }
     listen-address 192.168.0.1 {
         port 161
     }
}

Note there’s no real security in this kind of SNMP, anyone with access to that listen-address will be able to read a bunch of state off your router.

I was able to test SNMP was working with snmpwalk but I forget exactly what command worked. SNMP is a mystery to me.

Step 2: configure your Munin node to read the SNMP data. I used this guide. It basically has you use munin-node-configure to detect what SNMP data is available and then symlink a bunch of plugins. Then you add a “virtual node” for the router to your munin.conf.

The resulting config is overkill; I’m not sure I need to measure my router’s disk usage, thank you. Also there’s like 8 graphs for the network and I haven’t quite figured out which opaquely numbered interface is the WAN I care about monitoring. I figure after a day’s data is collected it’ll be clear what’s useful to keep.

Update: here’s what I kept

snmp_192.168.0.1_cpuload
snmp_192.168.0.1_if_2
snmp_192.168.0.1_load
snmp_192.168.0.1_netstat
snmp_192.168.0.1_uptime

The graph shows a big upload I did out of my network maxing out at ~10Mbps. Incoming bandwidth maxes out at 250Mbps so if I ever saturate that the scale on this graph is going to go to hell.

EXIF in Python

I’m working on using my Flickr export. I naively thought that working with EXIF metadata from images in Python would be easy in 2019. I was wrong. Particularly if you want to write EXIF data. I’m tentatively trying PyExifTool, a wrapper for a Perl command line program. More on that below.

PyPI has 126 packages for EXIF. But a closer look shows a lot of them are bad in various ways and there’s no one consensus package. Lots of version 0.1s, stuff that was abandoned 4 years ago, etc. PIL/Pillow has EXIF support but it’s very low level and a clunky API. Piexif looks somewhat promising as a pure Python thing but also very clunky API.

Turns out the real problem is EXIF is a mess. When we say EXIF we actually mean three separate metadata formats: EXIF itself, the older IPTC tags, and the more modern inlineed XMP tags. Some of these formats have overlapping metadata in them. EXIF itself is a real mess of a binary format. For instance the GPS location info looks more like raw data from a GPS chip than a simple WGS location. For instance it supports multiple formats for lat/lon. Want decimals? minutes? seconds? Some mix? You can write anything!

The gold standard for good EXIF+others support is ExifTool, a 15 year old Perl library / command line program. It has an active community of developers who’ve spent a long time fiddling with all the weirdness in image metadata formats and making a bulletproof tool that can read and write them. So why try to rewrite all that code in Python?

Enter smarnach’s pyexiftool and the several separately packaged versions of it on PyPI. It’s four years old and as far as I can tell there is no active fork. Fortunately the code is pretty simple.

The main thing it does is fork a single exiftool process with the -stay_open flag. That causes the Perl program to keep reading commands. The rest of the Python code is a little wrapper around the JSON api and some convenience code if all you want is to read metadata. It seems to work.

So there we go; I’m gonna be writing EXIF tags by passing command line arguments over a file descriptor to a running Perl program. It’s a kludge, but if it works I’ll take it.

mintty/wsltty: Ctrl+Shift+Letter

TIL; mintty, the venerable Cygwin terminal emulator, has an option so you can use Ctrl-Shift-C to copy and Ctrl-Shift-V to paste. mintty has been around forever and has a second life as wsltty, a very specifically adapted to easily launch Microsoft’s WSL environment. No cygwin required.

To enable it, right click a mintty window, go to keys, and tick on the box “Ctrl+Shift+letter shortcuts”. The full list of shortcuts is in the mintty man page.

– Ctrl+Shift+A: Select all
– Ctrl+Shift+C: Copy
– Ctrl+Shift+V: Paste
– Ctrl+Shift+N: New
– Ctrl+Shift+H: Search scrollback buffer
– Ctrl+Shift+W: Close
– Ctrl+Shift+R: Reset
– Ctrl+Shift+D: Default terminal size (rows/columns)
– Ctrl+Shift+F: Full screen (not zooming font despite Shift)
– Ctrl+Shift+S: Flip screen
– Ctrl+Shift+O: Toggle scrollbar
– Ctrl+Shift+P: Cycle pointer styles
– Ctrl+Shift+T: Cycle or tune transparency levels

Some of those are insane (“close window”?!), but the copy/paste shortcuts are lifesavers.

(I finally figured this out after finally mustering the encourage to install Windows 1809, which includes Ctrl-Shift-C for stock WSL consoles. A whole OS update for a keybinding! Then I realized I don’t use stock WSL consoles anyway. oops.

Update: while I’m here, mintty has a nifty feature I’d never heard of before.

Flip screen
Applications such as editors and file viewers normally use a terminal feature called the alternate screen, which is a second screen buffer without scrollback. When they exit, they switch back to the primary screen to restore the command line as it was before invoking the application.

The Flip Screen menu command and Alt+F12 shortcut allow looking at the primary screen while the alternate screen is active, and vice versa. For example, this allows to refer to past commands while editing a file.

30 years of using ttys as my user interface and I’d never heard of this. You know how you run less or emacs or whatever and lose whatever was on the screen to the fullscreen program? Alt-F12 shows what’s hidden. Amazing!

The virtual tabs feature is neat too. The mintty authors don’t want to add a full tab UI, but they do have a quick session switcher built in via Mouse Button 5, Ctrl-Shift-I, or the menu.

It also supports SIXEL graphics. Sadly, no Tektronix 4014.

Kernel module blacklist

Ran across a fun part of my Ubuntu system today, /etc/modprobe.d/blacklist*. It comes from the kmod package and contains a list of kernel modules which are included in the Linux sources, were compiled and shipped with Ubuntu, but nevertheless are being banned because someone made the choice they didn’t like the module. It’s kind of hilarious.

I can’t find a web-linkable version of the default Ubuntu files, but here are some gems from them. I suspect each entry here is a series of hard-earned lessons.

# causes no end of confusion by creating unexpected network interfaces
blacklist eth1394

# ugly and loud noise, getting on everyone's nerves; this should be done by a
# nice pulseaudio bing (Ubuntu: #77010)
blacklist pcspkr

# Framebuffer drivers are generally buggy and poorly-supported, and cause
# suspend failures, kernel panics and general mayhem.  For this reason we
# never load them automatically.

# Many less commonly used network protocols have recently had various
# security flaws discovered. In an effort to reduce the scope of future
# vulnerability exploitations, they are being blacklisted here so that
# unprivileged users cannot use them by default. System owners can still
# either modify this file, or specifically modprobe any needed protocols.

I was looking for this because I’m reinstalling Linux on my server and there’s still some drama about the r8169 driver, with some suggestions to lacklist it and build a vendor driver from source.

In the grand old days I used to build my own Linux kernels. But I always statically linked them, no loadable drivers, no init ramdisks. One kernel carefully sculpted to work on my one particular computer. It’s kind of a dumb way to make a system work.

SF Internet upgrade to 250/10

I’ve been using Wave (formerly Astound) as my ISP in San Francisco since June 2014. When I first got their 100 Mbps / 5Mbps cable modem it seemed so fast I could see through time. But network tech keeps improving, at least in urban areas. Sonic now offers $50/mo gigabit fiber and both Astound and Comcast have tried to match with upgraded cable modem speeds.

I’d prefer to switch back to Sonic but it requires running a new wire, which is a bit complicated for me. OTOH I could simply fill out a form with Wave, agree to pay an extra $10, and poof: I get 250 / 10 speeds. Which I did today, and it seems to work fine.

The real surprise here is I’m getting 250 all the way to my desktop. I’d been putting this upgrade off because I thought my home network wiring limited me to 100 Base T, so anything over 100 Mbps wasn’t so exciting. I guess the wiring in the house (particularly the patch panel) is better than I feared. (I’d planned ahead with the cable modem, an Arris 6141 which maxes out about 343 Mbps.

250/10 is hugely asymmetric, I wish they wouldn’t do that. I read somewhere that 19:1 was the maximum reasonable asymmetry, more than that and there wasn’t enough upstream bandwidth for ACKs to to clock the download. No idea if that’s really true and I bet that varies depending on window sizes, etc.

As always when I first got the speed boost it didn’t seem to work because I forgot I’d configured my router to do traffic shaping. I’m using an EdgeRouter X and their “smart queue”. It does an excellent job managing bufferbloat, but you do have to configure your max bandwidth correctly! Once I’d done that I was still only getting 190 Mbps down. Turns out that’s a limitation of the EdgeRouter X; once you enable QoS the CPU has to touch every packet and unfortunately it’s just not fast enough to keep up. One solution would be to upgrade the router, maybe an ER-4. What I’m doing now is only doing smart queueing on the 10 Mbps upload. Realistically that’s probably enough; saturating 250Mbps is hard.

I did get a nice practical demo with this game update. 30 MBytes/second, I remember when that was as fast as a hard drive could go! Unfortunately this nirvana only lasted about a minute until EA’s horrible servers crapped out and/or throttled me, real throughput over the whole download is more like 2MB/sec. Speed tests show I’m still getting 250 from my ISP.

Let’s Encrypt refresh

Back in 2016 I did a half-hearted attempt to enable SSL on my web servers, by using Let’s Encrypt. At that point all the scripts were relatively new, I think I used certbot 0.27. The little project is all grown up now and is already deprecating a protocol I relied on (ACME TLS-SNI-01). They were nice enough to send out a warning email about it, although dumbly the sent the “Action Required” email before the site’s docs have been written.

I read enough docs to realize that changing protocols basically means getting a new certificate. Also realized I needed to upgrade certbot, or at least really should, so basically I started over. Here’s what I did

  1. Removed the old certbot. Bits of it were in $HOME/ssl, $HOME/.local/share, /etc/letsencrypt, /var/log, and root’s crontab. Kind of a mess.
  2. Follow the Ubuntu instructions to follow a PPA for the new certbot
  3. apt-get install python-certbot-apache
  4. apt-get install python3-pyasn1
  5. Run certbot --apache and trust its configuration
  6. Test with ssllabs

Really all was super simple, hats off to EFF and Let’s Encrypt for building such a turnkey tool. The only wrinkle in my config is that all my server’s domains share a single SSL certificate with a bunch of different domain names on it. It’d be cleaner to have those separate, I imagine there’s some way I can do that.

I haven’t tested that all my sites work right under SSL. Both Windhistory and Logs of Lag are complaining about mixed SSL/nonSSL content. Meh.

noUiSlider, a nice Javascript control

Just wanted to give a shout out to noUiSlider, a nice Javascript library for building slider controls. We just used it to add a time-range slider control to Wanderings, my little location tracker. Now you can restrict what data is shown to specific date ranges. Our control looks a lot like this demo.

There’s a zillion slider controls implemented in Javascript. Most of the well known ones are 5+ years old and require jQuery. There’s some fancy new ones that require React. What I like about noUiSlider is it’s standalone, doesn’t rely on any other frameworks. It’s not tiny but it’s pretty small, about 90k uncompressed or 25k gzipped.

noUiSlider is also remarkably professional. It’s quite flexible; you can have any number of handles, linked or not. It’s straightforward to restyle. It gives off a nice collection of events when the user interacts with it. It works thoughtfully on touchscreens. And it’s all well documented! Nice library.

The one thing I haven’t figured out how to do in my app is add a nice UI for “filter to one month” for “one year”. It’d be easy enough to add buttons but the UI would be so cluttered then. Want something less obtrusive. For now we have a bunch of hotkeys defined on the main window (YQMWD for ranges, also HL to pan back and forth) but that’s pretty mysterious.

Edit WSL Linux files from Windows with SFTP

I just hit on a way to edit files in WSL that in retrospect seems really obvious. I’m wondering if there’s some reason it’s a bad idea. It seems to work!

The problem I’m trying to solve is editing files in the Linux partition of WSL from Windows. Ie: editing $HOME/.bashrc with Notepad. We’re told to absolutely never change the Linux filesystem files from Windows because things can break.

So my solution is to run the sshd daemon under WSL. Then use that to connect to my Linux files via SFTP running as a Windows app. I’m using SFTP Net Drive to mount my Linux files as a Windows drive, there are other options. Then use any Windows program to edit the files in that drive, like Notepad or Sublime Text.

All the actual file I/O is happening under WSL thanks to SFTP, so it should be safe. SFTP imposes some overhead but it’s not a big deal for just editing files. One nice thing is SFTP seems to do a pretty good job at preserving Unix file permissions even when editing from Windows.

Update: I’m now doing this regularly, all the time, with the Linux partition mounted as W: in Windows. It’s great! Makes a big difference having easy access to the files over there.

Update 2: this trick works but is no longer necessary. WSL in Windows v1903 includes support for accessing your WSL files via Windows paths like \\wsl$\Ubuntu-18.04\home\nelson. Underneath the scenes it’s using a Plan 9 network filesystem to bridge things.

(originally posted to Reddit)

New release of Wanderings, in which I learn to love Webpack

Brad and I pushed our first new release of Wanderings since the big release last January. No user visible changes, but we upgraded all the versions of third party packages and build tools we were using.

The real thing is I had to get over being whiny about webpack and npm. Right after we finished 1.0 Brad stepped in and reorganized our code to use fancy web tools. Previously we just had a big ol’ wanderings.js file we imported on every page, along with a bunch of third party minimized redistributables included one after the other in the HTML file. You know, the old school way. Brad redid everything nicely in webpack and npm so that third party modules were fetched from a repository and bundled together. Our code was refactored and then combined into the bundle. All with nice frontend scripts like “test” and “deploy” and “start development server”.

Unfortunately I don’t know anything about these fancy new fangled tools, I live or die by press-F5-in-the-browser. And it was kind of a big hump for me to get over it, learn the tools, and use them. I have a categorical problem any time someone tries to inject a “compile” or “link” phase into what should be simple interpreted code. It always slows me down. npm is very hard to love, too.

But webpack solves a lot of problems too. Managing distributing the right versions of things. Bundling them so they distribute efficiently. Minimizing the code for obfuscation + network savings. Keeping it possible to still run devel versions with source maps, etc for easy debugging.

The fancy devel server we get from webpack is pretty nice too. It seems to automagically arrange for things to recompile and reload when they change. I had a problem with this at first because our devel bundle is like 4.5 megabytes and I was running my devel server remotely, on another continent. That’s a bad idea; once I got the devel server running locally on my laptop it was much better. (We might want to split our bundle into two pieces though, a big one of third party code that seldom changes and a small one of our own code. Just to keep reload overhead down).

I’m still grumpy about some things. I’ve lost all my global variables I used to reach into to inspect the state of the running system in the console. I’m not sure I can get the Firefox debugger working at all, the source maps or something aren’t working. Chrome seems better though.

I still hate imposing any overhead in the “change code, reload, run” loop. But all this build stuff solves real problems in the Javascript ecosystem so I think it’s best to play along.