Setting up Second Crack
Someone on Twitter asked me about any gotchas I ran into when installing Marco Arment’s Second Crack as the blog engine powering DannyStewart.com. For the sake of anyone else looking to do what I’ve done, I thought I’d write a little bit about my experience. (Despite what Marco says, I highly recommend Second Crack.)
Disclaimer: I did not write Second Crack and am not an expert here. I may have done this very badly. You should not necessarily trust anything I say. All I can tell you is that as of right now I have my site working the way I want it.
First of all, my server is hosted with Linode and is running Debian 6 with Apache. I checked out the Git repo on the server. I had a choice here. I could put it in /home/danny or I could put it in /srv/www where I host my site. I wasn’t as sure of what I was doing at first, so for simplicity and convenience (especially early on), I placed it in with my site (/srv/www/secondcrack). This isn’t necessary, so it’s really up to you.
Then, I installed the CLI version of Dropbox along with their dropbox.py utility, both available for download directly from the main Dropbox page. After installation, I excluded every directory in my Dropbox (using dropbox.py) except the top-level Blog folder. I didn’t want my 30+ GB of other stuff syncing across to my server.
Once everything was syncing over, I added the following lines to my crontab.
* * * * * danny /srv/www/secondcrack/engine/update.sh /home/danny/Dropbox/Blog /srv/www/secondcrack
* * * * * danny /home/danny/.dropbox-dist/dropboxd
I did this because I wanted Second Crack running under my user. Then I restarted cron and verified that update.sh was running with a ps -A.
Finally, once I had everything working the way I wanted to, I erased the built-in www folder that Second Crack writes to by default, and I symlinked the secondcrack/www folder back to the root of my website, so that all the files would be written directly there without me having to move my Second Crack install from where it was already.
Working around permissions
The biggest problem I ran into was with the bookmarklet. When you use the bookmarklet, it tries to write a text file directly to your Dropbox drafts folder. This is no good on my setup because the danny user owns my Dropbox folder, while the user Apache runs as (www-data) can’t write to (or even see) danny’s Dropbox.
So I created a draft_temp folder in the root of where my site is hosted from, and then wrote the following shell script:
#!/bin/bash
BASH_LOCK_DIR="/home/danny/move_drafts.sh.lock"
if mkdir "$BASH_LOCK_DIR" ; then
trap "rmdir '$BASH_LOCK_DIR' 2>/dev/null ; exit" INT TERM EXIT
while true ; do
inotifywait -q -q -r -t 30 -e close_write -e create -e delete -e moved_from /srv/www/draft_temp/
if [ $? -eq 0 ] ; then
mv /srv/www/draft_temp/* /home/danny/Dropbox/Blog/drafts/
fi
done
rmdir "$BASH_LOCK_DIR" 2>/dev/null
trap - INT TERM EXIT
else
echo "Already running"
fi
This uses inotifywait (like Second Crack) to watch the draft_temp folder, and the moment I create a new draft using the bookmarklet, this script instantly moves it to my Dropbox folder. Just put this in your crontab like the previous entries.
Triggering a rebuild
Every time you make a global change (such as a modification to the template files), the easiest way to trigger a rebuild of the site is to first empty the secondcrack/cache folder, then just change anything in your Dropbox’s Blog folder. Delete something and then undo it, add a random word to a post then save and undo, etc. Just get Dropbox to sync the change and notice that a file is different, and then it will rebuild.
If a post breaks
If a post breaks, such as (in the example Marco cites) when you remove a post from the middle of several posts in one day and they do not re-number properly, there is an easy fix. Just drag all the posts from that month’s folder back to the Turns out, this is not such a great idea after all. It can cause duplicate posts. Instead, limit yourself to just the posts from that day, and you might be better served by moving them to drafts/_publish-now folder. They will be published again, with their original timestamps, except any broken numbering or missing posts will be fixed._publish_now one at a time, in order.
If I did something stupid…
…and you want to help me make my setup less stupid, please feel free to email me (see my Contact page) or tweet me at @dannystewart. The same thing goes if you have questions about something I didn’t cover here. I would be happy to add it.