Why my udev backup script kept failing and how I fixed it

I wanted to use udev to sync my backups to an external usb drive but the rsync-based shell script kept mysteriously stopping before the job was done.

When I say ‘use udev for backup’ what I mean is to use udev’s discovery of me plugging in the offline backup drive to fire off the backup script. Plug it in and the synchronization starts automatically. When it’s done it will automatically unmount the drive and inform me of the outcome via email. Sometimes there would be several weeks of new backups equalling gigabytes of data and so it would be convenient to just plug it in and leave it to do it’s thing.

The script was not apparently crashing wildly, just at one point it is running and the next it is not.  htop shows it to be running. iotop shows that data are being transferred. And then poof, suddenly it’s gone, even though there were still tens of Gbs left to transfer.

Luckily, the explanation is simple. Udev can fire off scripts but they are supposed to be very shortlived. Syncing 40 Gb over a USB 2.0 connection takes over an hour. The script is killed by the system after a few minutes. I found this elegant solution in an opensuse forum post.


Steam In-home Streaming lags with NetworkManager revisited: Replacing NetworkManager with systemd-networkd

Back in early 2015 I encountered an issue with NetworkManager: Even if you have ever only told it about your one single wireless network (or AP, access point) it insists on scanning the airwaves at regular intervals (about every two minutes) looking for a better connection. I thought that was dumb. This behaviour is known to the developer and is working-as-intended. There is no off-switch. I thought that was really, seriously dumb. I still do.

It was not an issue for me until I tried live streaming, specifically using Steam’s in-home streaming that allows you to play a game on a different computer to the one you’re sitting at and streaming the ‘playback’ to your current machine. Then NetworkManager cuts into the smooth streaming every two minutes, turning it into a screenshot slideshow instead for 3-5 seconds. If you’re playing a game that requires attention to not dying/crashing/clicking-the-wrong-button, this is a bad thing for a long time.

Now, my gaming desktop died shortly afterwards (note to self: Never buy another (cheap) Corsair PSU as long as you live) so it quickly became a non-issue. I recently got a new gaming computer, dual-booting Windows 10 and Ubuntu 16.04 17.04.  Coupled with a new 802.11ac wireless network  it seemed obvious to try to make in-home streaming work with the desktop-to-HTPC streaming, essentially making the HTPC a high-end Steam Link, rather than a low-end gaming computer in it’s own right. Running the streaming ‘server’ from Windows, everything works. Streaming from linux I was instantly reminded of the problems I had two years ago.

About half a year ago, commenter William Bernting kindly added some information to my original post suggesting how to make NetworkManager stop the scanning routine. I hope it works for whoever finds this information and I should probably have tested his solution before forging ahead with my own, more radical one. However, I have no patience with NetworkManager anymore, I do only connect to one network and I had the impetus last night so here is what works for me: Rip out NetworkManager, replace with systemd-networkd.


Stackexchange Answers: Systemd and PIDs

Systemd tracks PIDs. This is kind of obvious but I never thought to investigate before today. These two commands have been and I suspect, will be, very useful:

journalctl _PID = 1234

Get info on anything logged by the process in question. Technically, I suppose (?) it shouldn’t tell you anything that systemctl -u whatever.service doesn’t but it helped me get the exact error that caused the service not to work. Thanks, Rahul Khimasia.

systemctl status 1234

How exactly does pulseaudio get started on your desktop? Simply use htop to find the PID and ask systemctl for a status on the it and you will get told what systemd unit is associated with it. session-27.scope, it seems. Didn’t even know there was such a thing as ‘scopes’. Thanks, larsks.


Arachnophobia: Getting the macro keys on the Razer BlackWidow to work on linux

I bought the Razer BlackWidow for the hardware, not for Razer’s Synapse software or all the joys that it offers (Google suggest for searchers entering Razer Synapse? “Razer Synapse sucks”) Which meant that I was perfectly content not to use any of the special function keys on the keyboard. However the thought hit me that I had five Firefox profiles (yes, I prefer not to do my banking in the browser I watch smut in. There. Happy?) and there were five macro keys sitting in a row, not being used. 1+1=?