Flashing or Blinking Command Prompt

Have you ever been swapping between a Production and Staging environment when suddenly you make a change, but aren’t sure which pool you’re playing in anymore? It doesn’t happen often, but late nights and too many cups of coffee can lead to issues if you have your fingers in multiple environments. Adding a small script to your /etc/profile.d/ directory can help avoid making changes to the wrong system. I created a command.sh in the /etc/profile.d/ directory with the following information:

Production:

# added by Kristopher to differentiate between staging and production environments.
# staging command prompt will show green on a blue background where production will flash yellow on a red background.
# may the odds be ever in your favor.

PS1='\[\e[1;5;41;33m\]**PRODUCTION**\[\e[0m\][\[email protected]\h \W]\$ '

Which ended up looking like this, but with the **PRODUCTION** text flashing:

Screen Shot 2015-01-06 at 2.50.54 PM

 

Staging:

# added by Kristopher to differentiate between staging and production environments.
# staging command prompt will show green on a blue background where production will flash red on a yellow background.
# may the odds be ever in your favor.

PS1='\[\e[1;44;32m\]**STAGING**\[\e[0m\][\[email protected]\h \W]\$ '

Which looked like:

Screen Shot 2015-01-06 at 2.50.39 PM

There are really a countless number of options that you can use when changing the format of your command prompt! For more information and different options, these are the links I used to research the syntax for what I wanted:

http://blog.twistedcode.org/2008/03/customizing-your-bash-prompt.html
http://blog.superuser.com/2011/09/21/customizing-your-bash-command-prompt/
https://wiki.archlinux.org/index.php/Color_Bash_Prompt

If you have any questions, leave a comment or hit me up on twitter @goestocollege!!

Software: The Operating System

Picking an operating system for this endeavor wasn’t too difficult of a task. I’ve spent a lot of time tinkering with Debian on servers and Ubuntu on PCs, so the decision to go with Raspbian over Arch Linux was pretty painless. You can head over here to check out the Raspberry Pi Foundation’s documentation on installing Raspbian, or back up a step in their docs to look at info on installing different operating systems. I’ll be installing from a Macbook Pro, but if you need instructions installing Raspbian from a different operating system, check out the links here.

So, you’ve bought your SD card or grabbed one you had laying around and downloaded the Raspbian image, so now what? First things first, pop the SD card into the machine and open up Disk Utility. You’ll want to start with a fresh, clean slate, so let’s format it.

Once that is done, open up terminal and run the following command:

$ diskutil list

This is going to show us a list of all the disks attached to the machine. Were going to be looking for the SD card you have installed. Be careful, however, if you have any flash drives of the same size that you identify the SD card so that we don’t install to the wrong device! Next, run the following command:

$ diskutil unmountDisk /dev/disk2

where /dev/disk2 is the path to your SD card. This can vary depending on your system and number of hard drives/flash drives/etc that you have installed. Once the SD card is unmounted, run the command:

$ sudo dd bs=1m if=path-to-your-raspbian-img of=/dev/diskN

Of course, change out the “if=” value for the path of your Rasbian image and change the “of=” value to the path to your SD card that you found previously.

The process of writing the image to the card can take some time depending on the speed of the card and the size of the image. Usually, it takes long enough for me to get up, grab a cup of coffee, stretch my legs and it’ll be done when I get back. Your mileage may vary.

Once it’s done, you’re set! Pop the SD card into your Raspberry Pi, connect a keyboard and a monitor, power it up and you’re set! In the next post we’ll take a look at the initial configuration and a few tools that will help make the rest of the process easier.

Find the Temperature of your Raspberry Pi

It happens to all of us; you’re sitting there tinkering away on your Raspberry Pi and the thought enters your head: I wonder how warm this thing is right now.

It’s a good question and easy to answer. From the command line, simply enter this command:

     sudo /opt/vc/bin/vcgencmd measure_temp

For a nice, human-readable output in centigrade. You can take it a step further and write the command into a shell script and for easy execution. For example, I created a script called temp.sh and added the following:

     #!/bin/sh

     sudo /opt/vc/bin/vcgencmd measure_temp

After saving, I made it executable for only my user with:

     chmod 700 temp.sh

And now I can pull up the temperature at any time by executing:

     ~/temp.sh

from the command line.

Questions? Comments? Let me know below or at @goestocollege on twitter.

Cheers!

The Hardware

First and foremost, let’s start with the bare-metal parts I’ll be using. I’ve added the links to Amazon where I picked up most of the parts for ease of grabbing your own:

pi_complete

With that out of the way, time for everyone’s favorite part: putting it all together!

Starting with the Raspberry Pi, there’s not much variation here. Ever since the Model B+ came out, the Model B shows up less and less and tends to be a few dollars more on Amazon and the like. While I’ll be using the Model B for this endeavor, the B+ provides more USB ports, better power efficiency, slightly different board layout, more GPIO pins, but the processor and RAM specs are the same and those are really the only things I’m concerned about.

The reason I chose the 8GB PNY SD card was simple: It’s what I had sitting on my desk at the time. It’s not the biggest or fastest, but so far it seems to be good for the job. http://elinux.org/RPi_SD_cards has a list of compatible cards and OS flavors that work/haven’t worked and would be a great resource if you’re looking to play with SD card class or size to serve files larger than what you find on a website or blog. I’ve used as much as a SanDisk 64GB microSD card without any issues with Raspbmc serving some media files, so really the world is your oyster as far as storage card options go.

The topic of heatsinks on a Raspberry Pi seems to have gone through a bit of debate across the community and the final conclusion I came to was this: Are they necessary? No. Do they help? Yes. The processor in the Raspberry Pi is designed to operate without an active cooling system. Its design doesn’t allow it to get too hot and there are safeguards in place to prevent damage even if it did. However, I’m of the school of thought that if it can get hot, help it stay cool. Aside from this, heat scans actually show that the ethernet controller actually gets hotter than the processor/RAM, and since I figure (and hope) that network traffic will be greater than the processor need, I purchased these to help do the trick. It shouldn’t matter whether you pick copper or aluminum considering the heat levels we’re working with — a cooler chip tends to live longer either way.

As far as Raspberry Pi cases go, you really have more options than you could care to count. From DIY Lego cases, to swanky, full-aluminum heat-case-sinks, it’s really up to your personal tastes as to which you choose. I went with the JBTech Open Case with Fan because of the cost — only a few dollars — and the fan piqued my interest. Just like with the heatsink: Do you need a fan? No. Does it help? Yes. As a bit of anecdotal evidence, on two similarly chilly days I took temperature measurements from the command line. Running the fan, temps came back at 27.2 degrees Celsius. Without the fan running, they came back at 45 degrees — still well within normal operating temperature, but I figure that cooler temperatures are better for the longevity of the parts. (Note: make sure to get the case that matches your model of Raspberry Pi!)

That’s it for the parts – pretty simple! In the next post, I’ll go into OS installation and setting up Nginx, PHP, and MySQL. If you have any questions until then, leave a comment here or on Twitter!

Getting Started

Before diving into the details of this little project, a little background on my experiences:

I’ve been playing with servers for over a decade now, both for work and as a hobby. Whether it was a spare machine set up to host and serve my music to machines in the home, or a VPS hosting a handful of websites, or a full-blown, state-of-the-art rack with super powers and chocolate sprinkles hosting enterprise-level applications, I’ve always had my hands in tinkering with things.

pi_600x339

When I first heard of the Raspberry Pi, I was intrigued with the possibilites. I fully understood its limitations, but I wanted to get my hands into playing with one to discover its potential. I was so excited, I didn’t just buy one; why have one when you can buy two at twice the price?

The first already had a purpose in mind. I set it up as a Raspbmc device attached to my TV to serve digital files from a network share. The second, however, didn’t have a clear purpose. Since I bought it, it has served as an SSH server, a Mumble server, an OpenVPN server, or some combination of the three. I thought about serving a wordpress site from the Pi, but had a VM on my desktop that was doing that already. So, why change it up? Simple: curiousity!

I stumbled on raspipress.com — more specifically this tutorial series about installing WordPress using Nginx and MySQL on a Raspberry Pi. I had always used Apache for my web-servering needs, so the thought of branching out to a different solution actually seemed interesting. I’ve never had any problems with Apache, but why not try something new? I’ve also primarily used MySQL for my WordPress databases and will likely continue doing so. I did recently read about MariaDB and am toying with the idea of going with that option down the road, but there is still some time to make that decision yet. 

In my next post, I’ll break down the harware and software I’ll be using for this project and provide links to the items for anyone that wants to do some research on them. If anyone has any questions, feel free to comment or hit me up on twitter — @goestocollege!