How to know if Ubuntu needs rebooted

How to know if Ubuntu needs rebooted

I like to keep my servers up to date with the latest security patches, but I hate rebooting them unless I have to. So after doing apt-get update and apt-get upgrade, how do you know if your server should be rebooted?

The solution is the /var/run/reboot-required file. If the file is there, a reboot is required. If it isn’t, then you don’t need to reboot. Pretty simple.

reboot-required

You can do some neat things using bash. For example, you can reboot only if a reboot is required:

[ -f /var/run/reboot-required ] || shutdown -r now

This will check if the file exists, and if it doesn’t, it will reboot.

You can also do the entire update/reboot in one shot:

apt-get update && apt-get -fy upgrade && [ -f /var/run/reboot-required ] && shutdown -r now

I like to keep that in a bash script I can run during a maintenance window, and that way I don’t forget to reboot if it is needed.

Read More

Baby’s First Domain redesign with Laravel and Bootstrap

Baby’s First Domain redesign with Laravel and Bootstrap

One of my ugliest sites has always been Baby’s First Domain. The background was a muddy greenish color. The blindingly bright orange from the logo wrapped the content of the page. Everything was unstyled and just bleh. To make matters worse, the backend was powered by an ancient version of CodeIgniter. And with 37% of this site’s visitors using a mobile device, the fixed width layout was unacceptable.

The site was originally intended to help you find a domain name for your child. You can then use that domain name for email, a photo gallery, a blog, a link to their wish list at Amazon, whatever. That part of the site has never really turned a profit, so at some point I added baby name meanings. This part of the site is surprisingly popular.

I hope to get the domain name selling portion of the site beefed up so it can take over as the main feature of the site. I think I need to add some instructional videos on how to buy a domain, what to do with it, how easy it is to set up a wish list or photo gallery, that sort of thing.

Before that can happen, I needed a new design for the site using a modern framework. I settled on Laravel for the backend because it has basically won the PHP framework wars. It is easy to use and works well with popular build tools. It uses Composer for package management, so it is easy to pull in useful third-party tools. And everybody uses it so it is easy to find examples for just about anything you could want to do.

For the frontend I went with Bootstrap. I’ve used it a bunch on other sites. It is easy to make responsive sites without monkeying with a bunch of CSS. Its build system makes it easy to customize without digging through thousands of lines of code.

I spent about 3 days working on the new site. I used a few new packages that had some large prerequisites and I’m on incredibly slow DSL, so most of the first day was spent getting my dev environment setup. Oh how I miss cable internet!

The logic for this site is pretty straightforward, and I was able to copy/paste a lot of it from the old site. I saved the logo from the old site for now. My wife is going to convert the baby in the logo into a vector, then I’ll use it and some CSS to make a more appealing logo that loads faster on all devices.

I also added a new search feature. You can type anything you want into the search box. The search page tries to find a baby name that matches what you searched for. If it is a name that works for both genders, it sends you to the most popular gender for that name. If the name isn’t found, it calculates the Levenshtein distance between your search term and all the names in our database, and directs you to the closest match. This makes it really easy to find the baby name meaning you are looking for.

I also use the Levenshtein distance on some of the 404 pages. For example, if someone tries to go the meaning page for Jaycob, the 404 page will suggest Jacob, Yaacob, or Kaylob.

Another new feature I added is a boys and girls name page. On the old site you had to pick the first letter of the baby’s name to get a listing of all names that begin with that letter. You can still do that on the new site, but it is a bit tedious. On the new boys/girls name pages, I display a handful of the most popular names for each letter, with a link to the full listing. This makes it much easier to find common names.

Laravel is an absolute joy to work with. In about 10 minutes I created a command line script that pulls names from the database to automatically create a sitemap. The sitemap is saved in both xml and gz formats. The script is automatically run once a week by Laravel’s scheduler.

There is a lot of room for expansion on this site. I could easily add a baby due date calculator, tie in to various baby name APIs for more data, and perhaps even add templates for baby websites (like an announcement site, photo gallery, etc).

Anyways, I’m pretty happy with it. Only time will tell if the redesign actually increases my revenue or retains visitors better, but I’m optimistic.

Read More

Getting a domain with a ccTLD that is restricted to residents

Getting a domain with a ccTLD that is restricted to residents

A ccTLD is a top-level domain that uses a two letter country code. These domains are often reserved for residents and businesses in the country they serve. For example, you can’t get a .br domain unless you live in or have a business in Brazil.

But what if your company is based in the United States and you want to target residents of another country? Or what if you want a vanity domain that uses a restricted ccTLD?

The solution is to use a trustee service. The trustee maintains a legal presence in the ccTLD’s country, and registers the domain on your behalf. Your contract with the trustee maintains your legal rights to the domain even though the whois will show the trustee as the registrant. This allows you to fulfill the requirements of the ccTLD local presence rules.

I use 101domain. There website is awful but they have just about any ccTLD you could possibly want.

The Ring of ccTLDs #2 by Grey Hargreaves used under the CC BY 2.0 license.

Read More

Why does CTRL+S freeze your PuTTY screen?

Why does CTRL+S freeze your PuTTY screen?

tl;dr – If you hit CTRL+S in PuTTY, your screen will freeze. Anything you type will still be sent to the server. Press CTRL+Q to unfreeze your screen.

Imagine you are an old laser printer. You have something like 128 KB of memory. You print a max of 8 pages per minute. Someone decides to print the man page for gcc.

You are doing the best you can, cranking out pages and pages of obscure options and arguments. Your 128 KB of memory is quickly filling up. What do you do? You use flow control to send an XOFF to the computer. This message tells the computer that, for whatever reason, you need it to stop sending data. You print a few pages, you free up some memory, so you send XON to the computer. This message tells the computer that you are ready for it to start sending data again. This cycle repeats itself until you’ve received the full document from the computer.

These XOFF and XON controls are built-in to PuTTY, too. And they can be super useful. Imagine you are tailing a log file, and you catch a glimpse of an error message. Hit CTRL+S to send XOFF and the screen will freeze for you. When you are done, hit CTRL+Q to send XON and the screen will unfreeze. Yay!

It is important to keep in mind that XOFF only stops transmissions coming FROM the server. If you hit CTRL+S and start bashing the keyboard, all those keystrokes are going to make it to the server.

Another caveat is that you’ll lose any screen updates between hitting CTRL+S and CTRL+Q. This isn’t a DVR. You can’t go forward and backward. Hitting CTRL+Q goes back to “live TV” so to speak.

If you don’t care for this feature, you can easily disable it. Simply add the following to ~/.bashrc:

stty ixany
stty ixoff -ixon

The first line will let any character restart output, just in case the server receives an XOFF somehow. The second line enables the sending of start and stop characters, but disables XON/XOFF flow control. Realistically stty -ixon should be good enough, but the other bits provide some extra safety against unexpected screen freezes.

Read More

Office upgrades

Office upgrades

My wife always struggles to know what to get me for my birthday. Well this year she finally figured it out: let me buy office upgrades! A new desk, monitor, graphics card, headphones, and wifi adapter.

Old desk:

old-office

New desk:

new-desk

My parents bought me my old desk for my birthday 13 years ago. It has served me well, but was getting a bit cramped. My new desk is an UPLIFT Plus standing desk. Each leg has a motor that makes it easy to go from a sitting desk to a standing desk and back again. I’m hoping to improve my posture by spending more time standing rather than sitting. The desk is huge: 80″ x 30″. I’ve been using it for a few days and love it.

My monitors are a little newer than my old desk (only 4.5 years old) and still look fine, but I’m not going to complain about a new 27″ IPS monitor with QHD resolution. I decided to keep both of my old monitors, so now I have a 27″ IPS flanked by 22″ LEDs. I’ve always wanted a tri-monitor setup!

I’ve been using onboard video for a few years. It has been fine for my needs but was limited to 2 monitors. This means…. new graphics card! YAY! I went with the Gigabyte GTX 750 Ti. It is nice and quiet, supports up to 4 monitors, and performs infinitely better than my onboard video. I’m not a gamer so this card should be more than adequate for my needs.

As a bonus, I got a set of Sennheiser RS 170 wireless headphones a few weeks ago. When the kids start getting too noisy while I’m working (or I’m getting too noisy while they are trying to sleep) then I slap on my headphones and everyone is happy. I opted for wireless so I can easily move around without yanking out a wire. They are a bit heavier than I’d like, but comfortable enough for a few hours of listening at a time.

The one downside to the wireless headphones is that they interfered with my 2.4 GHz wifi adapter. To fix this, I was going to run network cable. Unfortunately, our walls have firebreaks and I’m not prepared to go through them (either by putting extra holes in the wall which would be difficult to patch thanks to our textured walls, or by getting a fish bit which can be a bit difficult to use) so I just got a new dual band wifi adapter. It works great.

I’ve got a big blank wall that I’m planning on putting a whiteboard on. I’m going to try following the Google Ventures design sprint methodology, but not sure how well it will work with just me and my wife. Worth a try anyways.

Read More