Script to update an OpenShift repository with changes made on server

If you haven’t tried OpenShift yet, you should!

Anyway I have a WordPress installation there. When upgrading WordPress to a new version, files are changed on the server but they would be overwritten if I push the repository. So I created a script to download a snapshot of the OpenShift app, extract the changes in the php directory where WordPress resides, and add them to repository.

It is fully automated except for the crucial git push.

The script is called update-repo-from-snapshot.sh and is meant to be commited to the root of each repository.

PHP Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes)

I’m a very happy user of New Relic for my websites, even if I’m only leeching on the free tier.

One of my WordPress sites, taurin.se has been suffering from this out-of-memory error for quite some time now and I finally tracked it down. New Relic shows the stack trace, with the failing line on top:

in wpdb::get_results called at /usr/share/wordpress/wp-includes/wp-db.php (1413)
in wpdb::get_results called at /usr/share/wordpress/wp-includes/meta.php (295)
in update_meta_cache called at /usr/share/wordpress/wp-includes/post.php (4133)
in update_postmeta_cache called at /usr/share/wordpress/wp-includes/post.php (4113)
in update_post_caches called at /usr/share/wordpress/wp-includes/query.php (2534)
in WP_Query::get_posts called at /usr/share/wordpress/wp-includes/query.php (2695)
in WP_Query::query called at /usr/share/wordpress/wp-includes/query.php (2791)
.
.
.

So, it fails when updating the postmeta cache. What’s that? Well, had a look in the database.

In the database I found the wp_postmeta table. A quick check revealed that it contained thousands of syndication_item_hash entries. These are added by the FeedWordPress plugin.

Unfortunately taurin.se is quite low priority for me, and the blogs I have been syndicating seem quite dead. But the upside is that I could just disable FeedWordPress and delete all syndication_item_hash entries from the wp_postmeta table.

Now my web server should work much better!

Disable some useless stuff in Raspbian

I’m currently running three Raspberry Pi projects, with Raspbian as my choice of distribution. One of the machines will be co-located at FS Data and run ownCloud. The other will be handle switching a central heater between oil and electricyty via SMS. The third is a surveillance camera heavily inspired by Dummy camera made smart with Raspberry Pi by my talented colleague Tomas Bjerre.

While examining the default Raspbian image I noticed there were some things I will never use, so I disabled them to free up some RAM:

  1. Disable the consoles by putting a # in front of all lines containing /sbin/getty in /etc/inittab:

    #1:2345:respawn:/sbin/getty --noclear 38400 tty1
    #2:23:respawn:/sbin/getty 38400 tty2
    #3:23:respawn:/sbin/getty 38400 tty3
    #4:23:respawn:/sbin/getty 38400 tty4
    #5:23:respawn:/sbin/getty 38400 tty5
    #6:23:respawn:/sbin/getty 38400 tty6
    .
    .
    .
    #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    If you get into network issues and need the console you can always mount the SD card on another machine and edit the file there!

  2. If you don’t have a keyboard connected or otherwise don’t want global hotkeys, disable the triggerhappy global hotkey daemon:

    sudo update-rc.d triggerhappy disable

  3. If you have Transmission installed but is not using UPnP, disable the minissdpd daemon for keeping track of UPnP devices:

    sudo update-rc.d minissdpd disable

  4. If you run Apache, disable modules you don’t use. Maybe:

    sudo a2dismod dir
    sudo a2dismod cgi
    sudo a2dismod negotiation
    sudo a2dismod autoindex
    sudo a2dismod setenvif