Sunday, May 31, 2015

Download a RackSpace Server Image

No comments:
I needed to download one of my Rackspace cloud backup images to my computer for use with VirtualBox. I assumed I would be able to simply download it, but to my surprise, that´s not possible. Rackspace suggested I use their API and their "getting started" tutorial, and upvote the request to add direct image download as a Rackspace feature, which I did.

NOTE: Be aware that, at least with a CentOS 7 Cloud Server, the image you download with the following method is ONLY compatible with XenServer, a Type 1 Hypervisor. It simply did not work with VirtualBox. I saw one report that you can load it with VirtualBox, but Rackspace themselves says it will not work and suggests this method instead.

I got my Rackspace cloud API token, and used curl from my Rackspace server to do the following:

  • Get export endpoint (which is based on your server region) and authentication token using these docs. The export endpoint is the "cloudImages" "publicURL", and the authentication token is the "access" "token" "id".
    curl -X POST https://auth.api.rackspacecloud.com/v2.0/tokens -d '{ "auth":{ "RAX-KSKEY:apiKeyCredentials":{ "username":"RACKSPACE_USER_NAME", "apiKey":"API_TOKEN" } } }' -H "Content-type: application/json" |python -m json.tool
  • Export your account and authentication token (NOT your API token).
    export account="RACKSPACE_USER_NAME"
    export token="
    AUTHENTICATION_TOKEN"
  • Combine your endpoint URL with the calls from this article to get your list of images.
    curl -s https://lon.images.api.rackspacecloud.com/v2/images -H "X-Auth-Token: $token" |python -m json.tool
  • Asynchronously export the image your interested in (check the "image" "name" field to find the one you want) by using the image "id" and the name of you Cloud Files container. If you don't have a Cloud Files container (I didn't), you have to sign up for it to get exported images.
    curl -s https://lon.images.api.rackspacecloud.com/v2/tasks -X POST -d '{"type": "export","input":{"image_uuid": "IMAGE_ID","receiving_swift_container": "YOUR_CLOUD_FILE_CONTAINER"}}' -H "Content-Type: application/json" -H "X-Auth-Token: $token" |python -m json.tool
  • You can now simply wait for your image to appear in your cloud file container, or you can actively check the status of you export job by using the id returned by the export command.
    curl -s https://lon.images.api.rackspacecloud.com/v2/tasks/EXPORT_JOB_ID -H "X-Auth-Token: $token" |python -m json.tool
  • If all goes well, you can pick up your image from the cloud file container. Mine took about 5 to 10 minutes to appear.

Friday, May 29, 2015

Adjustable Height Desks - cheaper version

No comments:

Ever since I started reading about it years ago, the idea of an adjustable height desk really intrigued me. Back when I wanted to be a writer, I remember reading about Hemingway using a standing desk, and I've since learned that luminaries such as Ben Franklin and Winston Churchill did the same.

I badly wanted to switch both myself and my staff to adjustable height desks, but could never convince myself to pay the cost. However, in 2012, Susana was able to buy motor driven adjustable height tables for everyone at 443 EUR each from http://www.schaefershop-industrie.es/. These tables have been great for sitting less, and also for breaking up the day.

Standing can be overused (standing for long periods of time can cause varicose veins), and I could not find any long term, detailed studies that back up claims that switching between sitting and standing is healthier and makes you more productive (the standard claims), but I do like having the option to switch between both, and I DO feel that it makes me healthier and more productive.

When I was on my flight back from Düsseldorf yesterday via Air Berlin, I saw an ad for Veridesk that I wish I had seen back before we bought our desks. If you want the benefits of a standing desk without as much cost, then Veridesk might be a useful alternative.

Hmm... looking at their site, maybe I should look into getting a standing mat....

Monday, May 18, 2015

PuTTY - Script Output in Different Color

No comments:
I was writing a shell script with rather verbose output, and was getting confused with which output was from which invocation of the command. I started clearing the screen between commands, but sometimes forgot. There's got to be a better way....

How about if I changed the color of the output? This article turned me onto the basic method, which had to be fine tuned due to my use of the zenburn color theme. Also, I found that, for some reasons, the color macros that work on the command line were not working in the scripts. Doesn't matter... I can now start and end scripts with commands to change color, and get the output in a different color....

So, a shell script (myscript.sh) like this...

#!/bin/bash
echo -e "\e[0;32m----------------------------------------------------"
echo "My Script Output"
echo -e "----------------------------------------------------\e[0m"

Will output the following (assuming you are using the zenburn color theme)....
[root@local ~] ~/myscript.sh
----------------------------------------------------
My Script Output
----------------------------------------------------
[root@local ~]

Friday, May 15, 2015

CentOS 7 Hostname Resetting on Reboot - SOLVED

No comments:

Problem

Setting the hostname was working without problems in CentOS 7 (including latest updates), but the hostname would revent back to the old hostname on every reboot. Nothing I read about worked, and I see lots of other people with the same problems (although RackSpace could not reproduce the problem on a newly spun up CentOS 7).

Solution

Assumes you're running as root. Otherwise, sudo the commands
  • Backup /etc/hosts, /etc/sysconfig/network, /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/cloud/cloud.cfg
  • execute "hostnamectl set-hostname yourdomain.com"
  • execute "hostnamectl set-hostname --static yourdomain.com"
  • Change old hostname to yourdomain.com in /etc/hosts
  • In /etc/sysconfig/network, add
    HOSTNAME=yourdomain.com
  • In /etc/sysconfig/network-scripts/ifcfg-eth0, add
    HOSTNAME=yourdomain.com
    DHCP_HOSTNAME=yourdomain.com
  • in /etc/cloud/cloud.cfg, set
    preserve_hostname=true
  • Reboot
  • hostname and hostname -f should now correctly give yourdomain.com

Wednesday, May 13, 2015

Windows PuTTY Tips

No comments:

  • Make a .reg file with your color scheme and font to easily apply it to new sessions (since the default dark blue folder names on black background is just a pain in the butt). Just add the name of the session and run the .reg file. I use the zenburn color theme with a larger font.
    I also change my LineCodePage to UTF-8, which is necessary on CentOS7 - ymmv.
    Here is a gist of my customized zenburn.
  • F6 gets you the tilde character in putty (useful for non-US keyboards), which is the path to your home directory.
  • nano ~/.bashrc opens a file where you can define aliases to make your work easier. Of course, this will only be available on the machine you are working on, but if you work on the machine a lot, it's well worth the time to make aliases. Much, much more can be added... search bashrc some day when you're bored
  • I like: alias dir="ls -CFhal"
  • Also, alias bashrc="nano ~/.bashrc && source ~/.bashrc && { echo -e 'Success--'; cat ~/.bashrc; } | mail -s 'bashrc backup' 'you@yourdomain.com'". This open bashrc for editing, puts any changes you make live, and emails you the script so you have a backup. Like, wow!
  • Add scripts to bashrc, which are available from the command line. To backup a file by sending it to an email address (always a good idea before you make any changes to files via the shell), add this to .bashrc
    bufile() {
            file_to_backup=$1
            { cat $file_to_backup; }  | mail -s "'$file_to_backup' Backup" 'you@yourdomain.com'
    }

    ...and then call it from the shell
    bufile index.php

Thursday, May 07, 2015

PrestaShop 1.5/1.6 and the Google Tag Manager

No comments:

Adding Page View Tracking

Most PrestaShop themes use one header.tpl for all pages on the site. This post assumes that is the case with your theme... if not, apply everything about header.tpl to all your headers.
  • Set up a GTM (Google Tag Manager) container, etc., and copy out the GTM snippet
  • open header.tpl
  • Look for the body tag
  • IMMEDIATELY after the end of the body tag, add...
     {literal}
    [your GTM snippet]
    {/literal}

    e.g.
  • NOTE FROM 2018: This article is rather old, and the newest GTM installation code from Google also talks about adding code right after the "head" tag, which could also be done in the header.tpl file. Thanks to Oliver Gerber for pointing that out.
  • Add a tracking tag to GTM
  • Preview and debug your GTM code.
  • Publish the GTM container

Adding Transaction (Conversion) Tracking

Adding page view tracking is super simple. Adding conversion tracking requires a data layer, which I added with a module.
IMPORTANT: For this code to fire, your payment method modules need to be calling PrestaShop after payment. E.g. here are the changes I needed to make to get this to happen with PayPal. As far as I can tell, this "problem" exists for both my module, and for the PrestaShop Google Analytics module.
  • Install the PrestaShop module "Data Layer Module" (instructions for installing a PrestaShop module can be found in the PrestaShop Documentation). This is simply a copy of the ganalytics module with lots of code removed and analytics JavaScript adapted to the GTM. It's a VERY basic module that any PHP coder can understand and expand on.
  • In GTM, add a new Google Analytics transaction tag... named something like "PrestaShop Conversion"
  • Add a firing rule (a.k.a. a Trigger) named e.g. "Order Confirmation" with values {{event}} equals prestashop_order_confirmation (prestashop_order_confirmation is an event that I trigger in the Data Layer Module) for the conversion tag.
  • Preview and debug your conversion tracking.
  • Publish the GTM container

Adding Site Speed Tracking

Speed of your website is fundamental to a good conversion rate. In addition, it effects your ranking in the serps. Monitoring your page speed is an important KPI.
By default, GTM and GA track your site speed, but using only a 5% sampling rate. That's perfect if your Amazon, but many sites need 100% sampling to get good data. Here's how to get this up.

  • In GTM, open your page view tracking tag
  • In the "Fields to Set" section, add a new field called "siteSpeedSampleRate"
  • Set the value to 100 (= 100%) 
  • Preview and debug your GTM code.
  • Publish the GTM container

Notes

  • Always push when using the data layer! See Simo Ahava's article on the subject. Actually, read all of Simo Ahava's articles... he's a great resource.
  • This code was written for a site which only has PayPal as a payment option. Theoretically, it should work for other gateways (it's not at all PayPal specific). I would be interested in hearing of your results if you use this with other payment gateways.