Raspberry Pi Shutdown Switch – Safely Turning off the Pi

We use a model B rev 2.0 Raspberry Pi as one of our Samba and DLNA media servers, and normally turn it off through a Webmin control panel to ensure nothing untoward happens with any of the attached hard drives. This solution is less than ideal however, as it requires a second powered-on device and a couple of clicks to get to the shutdown page in the control panel.

The Raspberry Pi forum has am excellent thread about a simple & safe shutdown button, from which I copied to produce my shutdown switch. It’s something you can put together in less than 20 minutes if you have the parts.

All you need is to install the RPi.GPIO Python class on the Pi (use SSH to grab it, “wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.4.1a.tar.gz”; unzip it; and install it, “sudo python setup.py install”; then remove the files to tidy it all up), and you can start accessing the pins via Python scripts.

Just connect pin 1 to a momentary open switch, and the switch to a 1K and a 10K resistor. Then connect the 10K resistor to the ground on pin 9 and the 1K to pin 11 (GPIO17). If you’re wondering where these are then this page has some nice illustrations; and more info on these pins can be found here. It’s worth covering the 5V line with some insulation just to minimise the risk of shorting out your Pi with it (see images below), as everything else on the GPIO header is 3.3V.

Breadboard setup, minus switch which would cross lanes 12 & 13.
Breadboard setup, minus switch which would cross lanes 12 & 13.
Raspberry Pi Shutdown Switch
In the case, soldered directly onto the pins with a momentary switch screwed into the case above the pi logo (hence minimising risk of contact)

All that’s left is to monitor pin 11 (GPIO17) for activity, for which I used the code on the Raspberry Pi forum.

Placed in /home/pi/bin/button/shutdown.py

import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
while True:
if(GPIO.input(17)):
os.system("sudo shutdown -h now")
break
time.sleep(1)

Placed in /etc/rc.local on the line before “exit 0”

python /home/pi/bin/button/shutdown.py

Then the Pi will shutdown when the button is pressed for about 1 second – only the Power light will remain on (red) when it’s shut down.┬áIt’s worth noting that this won’t work if the Pi has crashed but that’s not an issue we often see.

Updated 22/01/15 – Thanks to “Joost” for clarification on pins, specifically that GPIO17 is pin 11 on the board.

Mediatemple Grid Server (gs) MySQL and Support Problems

Let me be honest, I really REALLY want to like Mediatemple. Their website is extremely well designed, there’s loads of support information in their customer area, their GPU system gives you detailed information on high-resource scripts and files on your server and their file system has excellent uptime and good speeds.

Mediatemple GS Control Panel

However, as I write this one of our personal projects which we put on it’s own Mediatemple server is displaying a MySQL connection error – again. Over the last week it’s been a constant on/off battle made many times worse by the very slow Mediatemple support.

Mediatemple Sport a Speedy 20Hr Response Time

It was acceptable to begin with, 5 hours for the first reply, 13 hours for the second that informed me there was a bigger issue (mediatemple always seem to have MySQL issues), 7 hours later they informed me the issue had been fixed.

25 hours later (yes, TWENTY FIVE), after I had replied saying there was still a problem, they told me it was all running ok…which it was THEN but it had been too slow to work for hours before they replied.

I should probably point out that all of this was mid-week so the only reason I can see for the slow responses is that everyone was busy working on the problem?

Mediatemple Support Home

In the past I have had timely replies to my tickets (2 hour average) which is not as good as some (VPSLatch and PowerVPS being the best I’ve seen) but decent. In fact the response time is estimated at 4 hours 28 mins in the control panel right now. I have had only one instance of downtime for my files but unfortunately there are a couple of other shortcomings of their system including overly complicated domain setup (for subdomains) and how they work with the system. Whereas cPanel (for example) has seperate stats and settings for each domain, Mediatemple’s control panel mixes them together so the Urchin stats show all sites as one.

This post isn’t completely one sided, as the amount of space & bandwidth you’re given is very generous; along with the actual computing ‘budget’ they provide you with being pretty high (with their GPU system). Their website is beautifully designed and works pretty well but is let down by their MySQL system and slightly confusing control panel. You can of course fix the MySQL fault by purchasing a MySQL container at $20/mo, offering excellent response times; but this doubles the monthly cost of the service.

Extra MySQL Packages Are Available

I’d also point out that the Mediatemple terms of use are similar to those found on VPS and dedicated servers, much more relaxed than shared servers. This is still very useful (combined with the high storage space and inclusive bandwidth) for image hosting sites etc that you can’t put elsewhere.

Hopefully this has given you a fairly round view of my time with mediatemple, everybody’s views differ and you’ll have a different experience depending on what cluster you’re on; but I’d suggest a VPS is a better way to go until Mediatemple sort out the annoying MySQL lag.

Godaddy FTP Backup Servers – Dedicated Plesk Server

One of our clients recently had an issue where his Godaddy FTP Backup Server was full – causing his seperate dedicated Plesk Server to fill up it’s own Drive with Temp files, while at the same time use a lot of resources trying to put files to the full FTP backup server.

You can sign up for a remote backup server when you order a godaddy hosting service, and it does sound a good idea considering it should keep your data safe. You can only access the data on the FTP server from within the Godaddy network – stopping any outside access.

When Plesk attempts to connect to a remote FTP server, it first tries to place a file on the server – which is a no-go if the server is full. This fails of course, so you can’t even get a directory listing of the remote server through Plesk.

Easy solution though – connect to your server through SSH and then use commands to connect to the remote FTP through your server.

  1. Open your SSH application of choice (we use PuTTY, available free from greenend.org.uk) and connect to your server. Use your main IP address or your hostname (domain name), depending on what your host supports. For dedicated servers from Godaddy, either can be used.
  2. Once you’ve logged in with your root username and password, simply enter

    FTP XXX.XXX.XXX.XXX (where xxx…. is the IP address of the FTP server) and hit enter.
    then your login username, hit enter and then your login password (also followed by enter). For Godaddy all of this is available in your Server Management Area.

  3. Now you should be logged on to the server. Type DIR and hit enter to produce a list of the directory contents. This also shows file sizes and other details.
    1. You can DELETE individual files on the server using the DELETE command. For example, to delete info.php use DELETE info.php and hit enter.
    2. To change directories type CD directoryname/ and hit enter.
    3. To copy a file to your local server type WGET filename.file and hit enter. If you don’t specify a directory then the file will be copied to your server in the /root/ directory. You can access this directory by connecting to your server using PuTTY and typing DIR and hitting enter when you’ve logged in. (It will be in the default directory).

That’s a basic guide, there are many better out there but this follows the basics. There are a couple of useful SSH commands on this site, including how to set specific options.