Scheduling Drupal Site Updates the SysAdmin Way
0 min read
A client of ours recently had a major business announcement and needed to update their site's theme and publish a node to coincide with the announcement. Had the announcement been scheduled for regular business hours I probably would have made the changes manually, but because it was scheduled for 5:30 am I needed a better solution.
First I tried talking a few co-workers into finally learning how to work with git tags on a live site, but that didn't go very well even without mentioning the 5:30 am bit.
One helpfully mentioned that the scheduler module might be of use, and maybe elysia_cron, but they weren't really good fits, and besides installing and configuring a bunch of modules sounded like way too much work.
Fortunately scheduling one-off tasks on *nix is something that was solved a long time ago by the at command. at will run a command at a specific time, and is a sleepy sysadmin's favourite friend. So, while my coworkers sorted out the required theme changes and the nodes that would be published, I wrote a little shell script called update_script.sh to take care of the actual updating.
#!/bin/bash cd /var/www/live-www.amazingclient.com/core; /usr/bin/git checkout 20120116-1; /usr/local/bin/drush/drush sql-query "update node set status=1 where nid=1845; update node_revision set status=1 where nid=1845;"; /usr/local/bin/drush/drush cc all;
This is about as basic as a shell script gets, it is just a list of commands that need to be run to accomplish the site changes. First it changes to the drupal core directory for the site, then it checks out the git tag that includes the theme changes (I had run `git fetch` previously), then it runs two queries on the drupal database to publish node 1845, and finally it clears the drupal cache so that the changes are visible. I tested the script on my development set up and when I was sure it would work properly I copied it over to the production server.
The final step was to set up the scheduling, which was as easy as:
at -f /home/thejibe/update_script.sh 5:30am Jan 16
That tells the at command to read what it is to run from the update_script.sh file and to run it at 5:30am on January 16th.
With my work done I wish I could tell you that I enjoyed sleeping in on the 16th, but me being me I was awake at 5:30 and checked to make sure everything had gone smoothly (it had). Only then did I roll over and go back to sleep for a couple more hours.