Some Bits: Nelson's log

14 posts in September 2014

Notes on setting up a new Ubuntu 14.04 box

I’ve now recovered from my server hardware failure on Saturday. I can’t say enough good things about my remote rsnapshot setup. I’d kind of forgotten that backup even was running and it totally saved my ass. The hard drive had failed, the system wouldn’t reboot, would have been a nightmare getting it back. And while I don’t have any essential data on the remote server I do have a bunch of logsoflag logs I’d hate to have lost. Not to mention the server setup at all.

I ordered a new machine and set up Ubuntu 14.04 on it. I have no automation for building these servers, the overhead is hard. Couldn’t even easily import crap over from my backup of the Ubuntu 12.04 box, too much has changed like the shift to Apache 2.4.

Here’s a dump of the journal I kept as I set up the new server, the steps I took. Nowhere near complete.

Change root password and reboot
Set hostname, reboot
Edit /etc/network/interfaces to use Google DNS. “ifdown p2p1; ifup p2p1” and hold breath.
Edit /etc/default/rcS to set FSCKFIX=yes
Partition the extra disk, make file system, add to fstab
Create user nelson, add nelson to sudoers, also to group sudo.
Restore /home files from backup, put /home/nelson in order

Install unattended-upgrades
Install mg git gcc make munin nmap rtorrent screen mtr traceroute zip unzip curl optipng graphicsmagick gawk libimage-size-perl ntp
Install munin munin-node sensors
Install postfix bsd-mailx

Set up remote rsnapshot

Install apache2
enable a lot of mods
reconfigure deflate to not be stupid

http://nelsonslog.wordpress.com/2011/03/13/gzip-encoding-chrome-dev-tools-bug/

apache2 2.4 auth changes http://httpd.apache.org/docs/2.4/upgrading.html
set up backups

Set up web sites

Restore /var/www/* from backups
Reinstall sites in /etc/sites-available/* and enable
/etc/logrotate.d/apache2

Restore user contrabs from /var/spool/cron

Some notes from old setups:

http://nelsonslog.wordpress.com/2012/01/07/ubuntu-server-notes-from-an-old-debian-user/

http://www.somebits.com/weblog/tech/blosxom/server-migration.html

Apache 2.4 security stuff

My new server setup has mostly gone well, but I got tripped up by an error
authz_core client denied by server configuration

Turns out this is a change made between Apache 2.2 and 2.4. It’s reasonably well documented by Apache itself and this Stack Overflow post goes into more detail.

Long story short, for directories outside /var/www where I had some stuff stashed to load (namely CGI scripts), I had to Require all granted in Directory blocks for those oddball directories. I guess Apache moved to a “not allowed by default” model, which makes a lot of sense from a safety point of view.

Note that Munin in Ubuntu 14.04 has Apache 2.2 style config files, despite Apache 2.4 now being the default Ubuntu server. They have a bug tracking this.

Apache optimization still too hard

Setting up my new server, I’m struck by a few things.

  • Ubuntu doesn’t install mod_deflate at all by default
  • The default mod_deflate configuration is very conservative, effectively only compressing HTML. I replace it with a config which says “compress everything but GIF, JPG, MP3, that kind of thing”. Apparently it breaks IE6 or something to compress Javascript or JSON or the like. Who gives a shit?
  • I have no idea what, if any caching Ubuntu HTTPD does by default
  • I don’t even know how to test it any more. Chrome’s developer tool audit suggests stuff is being marked cacheable for 3600 seconds, which it complaints is “too short” but actually as default policies go, isn’t terrible

Hitting reload or Cmd-R on http://logsoflag.com/#8guI7GZ2OhU causes Chrome to reload everything. Hitting return in the location bar or pasting it in causes Chrome to load most things from cache, only loading the page itself and the JSON blob in the AJAX from cache. I don’t know if Chrome is being strictly standards-compliant or is a bit extra aggressive in trying to load things from cache.

I feel like I used to understand HTTP caching a lot better, but it’s been a couple of years since I looked closely at what was being cached and how. I also seem to remember there were more tools online that would load a page and give you advice on how to better optimize performance. Like there used to be a server hosted variant of YSlow, right? All I know to use now is Chrome’s developer tools in the browser.

Logs of Lag summary stats

My Logs of Lag tool now has collected some 25,000+ logfiles. It’s a heavily biased sample: people mostly bring logs to my site if they have network trouble, but some stats nonetheless. Numbers are the average of each stat, with SD in parentheses

  • Best ping: 85ms (153)
  • Median ping: 97ms (389)
  • Packets lost / minute: 8 (120)
  • Game length: 28 minutes (13 minutes)

Would be nice to publish something from this data. I sure wish I had a way to get a representative sample. I wonder if I can convince some group of players to just upload their logs, whether they have problems or no. Would still be biased but maybe useful.

Here’s the kludgey script I use to generate a CSV file of all the results, which I can then feed to my 20 year old C program that calculates averages and standard deviations. Very quick and dirty, I should tackle a project of handling user data as more than flat JSON files.

for f in *; do
  ~/lol-netlog/logToJson.js < $f | 
  jq '"\(.matchLength),\(.packetsLost),\(.packetsLost/.matchLength),\(.medianPing),\(.bestPing)"'
; done > /tmp/logs.csv

Full window maps

I like making slippy maps that fill the browser window. Every time I do this, I forget how to do it right. It’s easy to screw up and make a map that causes the window to have a vertical scrollbar, or that doesn’t fill the whole window. Firefox used to have a different CSS model which caused some of my maps to only fill the upper left of the window, like 2 map tiles. Chrome recently changed and now my maps are broken that way in Chrome. Here’s a screenshot of how it looks:

Screen Shot 2014-09-27 at 11.10.06 AM

So how to fix it? The notes below are only testing desktop Chrome 37.0.2062.124 on a Mac. This d3noob block has a full window Leaflet map that works well and is simple. The crux of it is

body { padding: 0; margin: 0; }
html, body, #map { height: 100%; width: 100%; }

<body>
  <div id="map"></div>
</body>

If you don’t set the margin on the body to 0, then Chrome’s default is an 8 pixel margin on the entire body and you end up with scrollbars because the 100% map now hangs 8 pixels off the window. The padding: 0 may not be necessary; Chrome’s default seems to be no padding on the body already. But it’s harmless and seems like a good idea for a full reset.

It’s also common to see overflow: hidden on the body, to suppress all scrollbars. I think that’s also harmless and even possibly a good idea, but is not strictly necessary. It also causes problems for other full screen webapps that aren’t maps. Logs of Lag has a “natural” height of about 800px. I used to set overflow: hidden to work around a scrollbar bug, but then that broke the case where the window is shorter than 800px and you really do want a scrollbar. Not something that’s likely to come up in a map, but maybe in other full window app contexts.

The height: 100% must be set on all of html, body, map. If it’s not set, then the height calculates to 0 and you end up with nothing displayed. The width: 100% seems unnecessary, you can remove it entirely and it still renders full width. But it seems harmless.

I wasn’t able to reproduce the “show only two tiles” brokenness in my screenshot above in Leaflet with a simple example of a page with just a map div. It may be not possible any more, not sure.

The bug is showing up for me with my Polymaps maps though, even if I set all the widths and heights and stuff as described above. Turns out for Polymaps you also have to set the size of the SVG that you put inside your map div. I did this by hacking in a svg { width: 100%; height: 100%; } in my stylesheet, which obviously only works if you have no other SVG elements on the page. Since Polymaps is long since EOL, there’s not much point trying to figure out anything better.

Services I host, setting up a new server

I have a server in a datacenter in Kansas. Or rather, did: the hardware went boom. Fortunately I have backups, unfortunately I have to set up again a bunch of hand-crafted services and crap I put there. I greatly simplified things when I set this server up, back in March 2012, but I still have to install and tweak a bunch of stuff by hand.I think all the services I run publicly come via port 80 and Apache. Best as I can tell here’s what I care about:

  • logsoflag.com: Apache virtual host with some CGI writing to local directories.
  • windhistory.com: Apache virtual host, nothing but static files.
  • somebits weblog: Blosxom CGI
  • somebits web server: random stuff, mostly (all?) static files.
  • rivers map: nginx, Tilestache, GUnicorn, Postgres, oh god so many things.

It may be a few days before the replacement is online. I’m trying to move logsoflag and windhistory to my home DSL system as a stopgap for the weekend. I’ll wait for the new server to set up the somebits blog, etc. I may not bother with the river and airport maps at all. They’re neat, and somewhat easy to get running again, but it’s a lot of extra servers to manage for not a lot of benefit.

I sure wish system automation tools were better; I’d love to script all this setup so I can migrate more easily. But Chef, Puppet, and Docker are all a fair amount of work to set up. The other option is a virtual image snapshot I can just clone, either a Linux VM based thing or Vagrant or something. But that’s wonky. It would not be inappropriate for the river project though.

Update: I’ve gotten two recommendations for Ansible as a lightweight system configuration tool. It looks basically like a sane wrapper around scripts that ssh to a machine and install packages, copy files, etc. YAML declarative “playbooks” define how to set up services. (Very simple example of running it.). I’d definitely look to use this if I were setting up machines regularly. May not bother for one single system.

I managed to get all the web stuff except the river map working on my home server on cable modem. It only took a couple of hours. So maybe I don’t need to sweat over the server setup too much. I’ve got the Apache virtual host stuff configured well enough now that it’s pretty painless.

Sonos hacking

I love my Sonos devices, they are reliable and sound great. I’m also curious how they work, and I do wish there were better diagnostics for media files that refuse to play.

Turns out the Sonos has an admin web interface on port 1400. A URL like http://192.168.0.20:1400/support/review brings up a bunch of debug data; substitute the IP address for one of your Sonos devices. It loads slowly. Also appears to be centralized, no need to find the right device first.

I also found my way to SoCo, an open source hacker interface to the Sonos. Command line control over playing, queuing, etc. Neat stuff and seems to work.

What I haven’t found is any way to get an error message why a track won’t play :-(

I thought the Network Matrix was interesting. Screenshot below. STP presumably refers to spanning tree. Sonos’ core magic is the way music plays completely correctly, synchronized, in an unmanaged wireless network. Presumably this is the status of the magic that makes that work.

Screen Shot 2014-09-26 at 10.58.02 AM

SF bandwidth usage before and after

in mid-July I switched ISPs, from sonic.net DSL with 6/1 Mbps speeds to astound.net cable with 100/5 Mbps. Best thing ever, 100 Mbps is like seeing through time. It is sometimes faster for me to download something over the Internet than to get it off my LAN, which is just ridiculous.

Getting a higher speed doesn’t seem to have changed my usage. I average about 150GB a month both before and after. Here’s a table of usage for the past few months

Date Download Upload Total
2014-09 133.03 GB 7.13 GB 140.17 GB
2014-08 102.84 GB 5.22 GB 108.06 GB
2014-07 102.81 GB 8.29 GB 111.11 GB
2014-06 144.46 GB 11.42 GB 155.88 GB
2014-05 136.55 GB 11.61 GB 148.15 GB

Compare to bandwidth usage in Grass Valley, with a 1/0.1 Mbps link, where I average 15 GB a month. The big difference between the two houses is totally behavioral. I deliberately only download video, stream video, update Steam and iOS and stuff in San Francisco with the fast link.

VPN server notes

I need a VPN server for when I’m travelling. I used to use sonic.net’s great service, but now that I switched ISPs I need my own mostly to get IP tunnelling to circumvent stupid hotel networks. Options:

  • Cloak. Their service works well, particularly the iOS client. It’s cheap ($10/mo for unlimited bandwidth). The drawback is that a lot of their VPN server endpoints are on IP blacklists for websites, which is just terrible.
  • Tomato firmware. Run this at home and use my cable modem service as a VPN. Not ideal, but Tomato has a built-in service that looks easy to configure.
  • PPTPD, as documented here. Apparently pretty easy but a bit kludgey, not clear how secure it is.
  • OpenVPN, maybe as automated here. I think this is the more serious option but I’m warned it’s hard to get working right.

The VPN server and client world is terribly confusing and usability is awful. I’m hoping I can just skate through with Cloak for my light usage.

IP address is not identity

I’m using Cloak as a VPN provider while travelling. Great product, excellent MacOS VPN client. Unfortunately they terminate your VPN links at random servers in VPS clouds like Linode. And those IP addresses are blocked by sites like Yelp and Pinterest. Pinterest goes so far to say as “there’s a bot in your network”, which really means “we blocked that block of IP addresses because someone once ran a bot there”.

Stupid.

Apple hates signals

Why do so many MacOS apps fail to quit in response to a simple kill command? softwareupdated, mtmd, I think ocspd and maybe even mdsworker. kill doesn’t kill them, have to kill -9. That doesn’t help anything.

Today’s mess: I deleted 20 old files from my Downloads folder. So now Time Machine is insisting on pegging one CPU at 100% and running the battery down, preparing another backup or something. The backup drive isn’t plugged in, this is the local backup thing which I generally like when it’s not being stupid. Even better; after the kill -9 launchd spawned the process again. Of course.

 

MacOS file sharing and CPU usage

Why does MacOS file sharing take so much CPU? I’m rsyncing 30GB of files from one Mac to another. Using MacOS file sharing, 10.9.4 server and 10.9.2 client. The client is a MacBook Air and the fan is whirring away. Some kernel_task associated with the copy is taking 50% of one CPU; the rsync processes are taking another 13%. It’s not awful, but that’s a shitton of CPU for doing something that should be low impact. The iMac server is using 15% of a CPU to serve the files too.

Automatic Dashboard

JeffN was kind enough to point out the new Automatic Dashboard. Automatic is a gizmo that plugs into your car service data port and relays data to an iPhone app. It records fuel usage, speed, GPS track, etc. Neat data, but the presentation has been really limited so far to a mobile-only experience. Well now they have a webapp and it looks great.

The map view is most interesting to me. All built using MapBox.js. The data for it is stored in URLs like https://api.automatic.com/v1/trips?page=1&per_page=100&start=1407222000000&end=1409756534672. Requires authentication, my eyebrows slightly raised that my user ID isn’t in the URL: implicit by authentication.

trips returns an array; one example element below. I’ve zeroed some of the IDs. The path data is most interesting to me. It looks to be pre-encoded as a polyline, which the javascript renders in SVG. It doesn’t load more detailed data when you zoom in, I think this is it. A bit of a hassle to reverse engineer this to normal lat/lon data, but it’s probably all some standard MapBox data format so should be possible. Update: apparently it’s the Google Maps polyline format.

The graphs are nice. They’re SVG and I see nvd3 is loaded in the page, so I assume that’s what they’re using.

{
  &amp;quot;vehicle&amp;quot;: {
    &amp;quot;uri&amp;quot;: &amp;quot;https://api.automatic.com/v1/vehicles/C_0000000000000000&amp;quot;,
    &amp;quot;color&amp;quot;: &amp;quot;&amp;quot;,
    &amp;quot;id&amp;quot;: &amp;quot;C_0000000000000000&amp;quot;,
    &amp;quot;display_name&amp;quot;: &amp;quot;Audi A6 Quattro&amp;quot;,
    &amp;quot;year&amp;quot;: 2005,
    &amp;quot;model&amp;quot;: &amp;quot;A6 Quattro&amp;quot;,
    &amp;quot;make&amp;quot;: &amp;quot;Audi&amp;quot;
  },
  &amp;quot;score&amp;quot;: {
    &amp;quot;score2&amp;quot;: 50,
    &amp;quot;score1&amp;quot;: 50
  },
  &amp;quot;drive_events&amp;quot;: [],
  &amp;quot;average_mpg&amp;quot;: 20.803669567728743,
  &amp;quot;uri&amp;quot;: &amp;quot;https://api.automatic.com/v1/trips/T_0000000000000000&amp;quot;,
  &amp;quot;end_time_zone&amp;quot;: &amp;quot;America/Los_Angeles&amp;quot;,
  &amp;quot;duration_over_75_s&amp;quot;: 0,
  &amp;quot;duration_over_80_s&amp;quot;: 0,
  &amp;quot;path&amp;quot;: &amp;quot;karlFrrzaVCf@Er@c@Gc@IcAQmAU}Bk@cDw@{D{@qA]oAe@iAo@}@_@]EK~Bg@pHMbBa@Kg@Wi@c@aB{Ae@a@iBsAcBiAgCsByBeBcAo@sHqEWM{Ac@kBg@cCw@_GeD_BeAw@u@mCeDoCeDq@k@e@YiAe@cCm@kA]y@k@KOkCzDu@|Aq@nBShAM~@IfAEpA?hCNxBVpBVjArAbEvCdJbAhDb@|Bj@zDP`CZlGh@~O\\hFTlBb@~CZ|A~@zDfChKb@nBh@xCZhCVjCNfCh@fZh@nSNlFBzCAtCGrDo@nLQjEIxEC~CBjBFbDHT@bD?pIGP?PC|BBlBDhAXElBc@a@iDQ]K_AAg@Fg@N[xCm@JB|ChE^zAa@J&amp;quot;,
  &amp;quot;end_location&amp;quot;: {
    &amp;quot;lon&amp;quot;: -121.0936601,
    &amp;quot;lat&amp;quot;: 38.9406032,
    &amp;quot;display_name&amp;quot;: &amp;quot;Bell Rd, Auburn, CA&amp;quot;,
    &amp;quot;name&amp;quot;: &amp;quot;2705 Bell Road, Auburn, CA 95603, USA&amp;quot;,
    &amp;quot;accuracy_m&amp;quot;: 10
  },
  &amp;quot;distance_m&amp;quot;: 6805.27783203125,
  &amp;quot;end_time&amp;quot;: 1409172044053,
  &amp;quot;start_time&amp;quot;: 1409171491960,
  &amp;quot;id&amp;quot;: &amp;quot;T_0000000000000000&amp;quot;,
  &amp;quot;duration_over_70_s&amp;quot;: 0,
  &amp;quot;fuel_cost_usd&amp;quot;: 0.753902077674866,
  &amp;quot;fuel_volume_gal&amp;quot;: 0.203262895345688,
  &amp;quot;hard_brakes&amp;quot;: 0,
  &amp;quot;hard_accels&amp;quot;: 0,
  &amp;quot;user&amp;quot;: {
    &amp;quot;id&amp;quot;: &amp;quot;00000000000000000000&amp;quot;
  },
  &amp;quot;start_location&amp;quot;: {
    &amp;quot;lat&amp;quot;: 38.9280456,
    &amp;quot;lon&amp;quot;: -121.0552683,
    &amp;quot;display_name&amp;quot;: &amp;quot;Lincoln Way, Auburn, CA&amp;quot;,
    &amp;quot;name&amp;quot;: &amp;quot;13500 Lincoln Way, Auburn, CA 95603, USA&amp;quot;,
    &amp;quot;accuracy_m&amp;quot;: 50
  },
  &amp;quot;start_time_zone&amp;quot;: &amp;quot;America/Los_Angeles&amp;quot;
}

 

Screen Shot 2014-09-03 at 8.16.43 AM

First light: WebTule

I’m working on a data exploration tool. Sort of a simplified version of GGobi, for web usage. Give it a CSV file and it lets you explore scatterplots of various columns. I did a custom version for Battlefield 4 a few months ago, now working on a generic tool.

So here’s “first light”, taking the HYG Database of stars and trying to recreate the Main Sequence diagram. It’s visibly at least a little right, once you realize the Y axis (magnitude) is inverted.

Screen Shot 2014-09-02 at 5.46.08 PM