Posts from my general blog (old posts, page 2)


Ubuntu Dynamic MOTD

I'm just finishing off moving all my web sites and related things from one VPS host to another. The new host had customized the message of the day on the Ubuntu 12.04 LTS image which I had installed. It had helpful links to support and what not, things that are only actually helpful the first time I logged in.

As I went through the process of removing all this I had to learn about the update-motd system, since I quickly found that the solution wasn't a simple:

$ sudo echo "" > /etc/motd

So I cooked up a bash script to spit out some information about the system every time I log into the server. The output looks like this:

!-- image ubuntu-dynamic-motd_1.png --!

Create or edit update-motd's 00-header file.

$ sudo vi /etc/update-motd.d/00-header

And here's the source of the bash script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh

[ -r /etc/lsb-release ] && . /etc/lsb-release

if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then  
 # Fall back to using the very slow lsb_release utility  
 DISTRIB_DESCRIPTION=$(lsb_release -s -d)  
 fi

UPTIME=`uptime | awk '{if ($4 == "day," || $4 == "days,") print $3, $4, $5; else print $3}' | awk -F: '{print $1, "hrs", $2, "mins"}' | sed 's/,//g'`

LOADAVG=`uptime | awk '{if ($4 == "day," || $4 == "days,") print $10, $11, $12; else print $8, $9, $10}'`

PROCCOUNT=`ps -l | wc -l`  
 PROCCOUNT=`expr $PROCCOUNT - 4`  
 IP=$(/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}')

echo -e "  
 ==============: System Info :===================  
 Hostname: `hostname`  
 Address: $IP  
 Distro: $DISTRIB_DESCRIPTION  
 Kernel: `uname -r`  
 Uptime: $UPTIME  
 Load Avgs: $LOADAVG  
 Processes: $PROCCOUNT  
 ==============: Memory Info :===================  
 Total: `cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB  
 Free: `cat /proc/meminfo | grep MemFree | awk {'print $2'}` kB  
 Lowest: `cat /proc/meminfo | grep LowFree | awk {'print $2'}` kB  
 ===============: Disk Info :===================="  
 df -h

Hyper-V 2012 Failover Cluster: Live Migration Fails

I love hyper-v. I especially love hyper-v running on windows server 2012 in a failover cluster configuration. It truly is a wonderful environment to administer windows servers. With this said, the error logging leaves a lot to be desired.

I've just spent the better part of two days trying to work out why live migration of servers between cluster nodes wasn't working. The error message which Microsoft helpfully give you when this happens is simply:

Event ID: 21502
Source: Hyper-V High Availability
’Virtual Machine <VM NAME>’ Live Migration did not succeed at the destination

And over on the hyper-v host you were trying to migrate the virtual machine onto you'll get the equally as amazing Microsoft-Windows-Hyper-V-High-Availability-Admin log entry of:

Source: Microsoft-Windows-Hyper-V-High-Availability
Event ID: 21111
Description:
Live migration of 'Virtual Machine <VM NAME>' failed.

Oh thanks, it didn't work because it failed.

Finally after reading many a technet article and support thread I stumbled onto the fix. It was simple. Here's the details for anyone else who suffers this problem:

  • On any node in your hyper-v cluster, open up Failover Cluster Manager

  • Select the cluster name

  • In the bottom right corner of the manager window, click Take Offline

  • Again in the bottom right corner, under More Actions, click Repair

  • This will bring the cluster back online and magically fix the mysterious problem causing live migrations of VMs to fail

Best of all, it will do this with out any disruptions to running VMs. Enjoy!