Plesk: How many ColdFusion sites?

A customer asked how many ColdFusion sites they had on their Plesk server. Ordinarily, the following query would make this easy to answer:

# mysql psa -e "select count(*) as 'Coldfusion Enabled' from hosting where coldfusion = 'true'"
+--------------------+
| Coldfusion Enabled |
+--------------------+
|                159 |
+--------------------+

In their case, however, they had ColdFusion support enabled for all sites, so we needed to find out how many domains actually had ColdFusion content. Here’s a quick&dirty one-liner:

# find /var/www/vhosts/ -type f | grep -i "\.cfm" | cut -d/ -f5 | sort | uniq | wc -l
   150

Mac OS X Sleep Modes

There are two ways that computers sleep (a.k.a. being suspended). One way is to keep the RAM powered on, and turn the rest of the computer off (suspend to RAM). This allows the computer to wake almost instantly. The disadvantage is that if your computer loses power – say, the battery runs out – you lose your session, and your computer will boot up normally when you turn it on.

The second way is to write the contents of RAM to the hard disc, and turn the computer off completely (suspend to disc). This way you can unplug it or disconnect the battery, and you won’t lose your session. The disadvantage is, it takes longer to sleep and to wake. The more RAM you have, the longer it takes. Current MacBook Pros can have 16GB of memory, which can take a couple of minutes to write to and read from disc.

Recent versions of OS X, at least from 10.5, possibly earlier, ships with its sleep mode configured to do both of the above. This works great! You get fast wake-up times, but if your battery runs out, you don’t lose your session either. On older MacBooks/MacBook Pros this means that you can swap out the battery, and still have your session in tact.

The sleep modes are configured by the ‘hibernatemode’ directive, and you can check yours as follows:

$ pmset -g | grep hibernatemode

	hibernatemode  3

The hibernate modes are as follows:

0: Suspend to RAM. RAM remains powered on while sleeping, safe sleep is disabled, wake is instant.
1: Suspend to disc, a.k.a safe sleep. RAM contents is written to disk, computer shuts down completely. Slower to wake up.
3: RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping.
5: Same as mode 1, but for using secure virtual memory.
7: Same as mode 3, but for using secure virtual memory.

Of course, mode 3 still means that your shiny MacBook is spending a fair bit of time writing to disc every time you close the lid. Even my 2008 vintage MacBook Pro can go about a month in mode 0 or 3 before the (now 5 year old) battery runs out. So for all practical purposes, suspend to disc is completely unnecessary. To set it to 0, do the following:

$ sudo pmset -a hibernatemode 0

Once you’ve set it to 0, you can free up some space by removing the RAM image:

$ sudo rm /var/vm/sleepimage

Migrating a MySQL database containing views

You may have come across this problem: say you have a MySQL database called ‘myblog’ which you’re moving to a new server on a different provider, and said provider doesn’t allow you to name the database, but instead use their own scheme, ‘user82_db1’ for example.

If you happen to have views in your database, this will cause the import to fail, as those views would still refer to ‘myblog’ instead of the new database. Fortunately, this is easily fixed using the ‘rpl’ command. Say your database is backed up as ‘myblog-backup.sql’:

# rpl "\'myblog\'." "\'user82_db1\'." myblog-backup.sql

This will replace any instance to ‘myblog.’ with ‘user82_db1.’ and allow you to import a working database.

Plesk: Finding large log files

I get this kind of problem every day: “We’ve run out of disc space on our Plesk server – what’s taking up all the space?” The answer, almost every time, is “logs.” Plesk doesn’t enable log rotation by default, so logs can end up taking a lot of space.

Here’s something I cooked up to list the size of each domain’s log directory:

Continue reading “Plesk: Finding large log files”

Cisco VPN – Error 51

All weekend I have been having trouble connecting to my work’s VPN on OS X 10.5 (Leopard). My favourite VPN client, Shimo, doesn’t even want to try, and the Cisco VPN client gives me this error:

Cisco VPN - Fix for Error 51: Unable to communicate with the VPN subsystem

All it is, is the Cisco VPN service needing a restart. Open a terminal and type:

$ sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart

Make Apple Mail display plain text

Some of us prefer our mail clients to display mails in plain text. Here’s how to set it.  Open ~/Library/Preferences/com.apple.mail.plist, click on the Root key, click “Add Item.”  Call it ‘PreferPlainText’ and set the type to boolean.  This gives you a checkbox to enable or disable it.

You can also do it via the terminal:

defaults write com.apple.mail PreferPlainText -bool TRUE

Or to disable:

defaults write com.apple.mail PreferPlainText -bool FALSE