Over at Axis & Allies .org, the community loves to upload files but my new Digital Ocean instance only has 30GB. The solution: mount an AWS S3 bucket to the filesystem and point the forum uploads to that directory.

After a bit of research I settled on using RioFS:

RioFS is an userspace filesystem for Amazon S3 buckets for servers that run on Linux and MacOSX. It supports versioned and non-versioned buckets in all AWS regions. It handles buckets with many thousands of keys and highly concurrent access gracefully.

The instructions to compile and install it were very straightfoward but setting up an upstart script was not.

Here's the script:

#!upstart

description "RioFS"

start on (filesystem and static-network-up)  
stop on shutdown

env AWS_ACCESS_KEY_ID="<key>"  
env AWS_SECRET_ACCESS_KEY="<secret>"

script  
  exec /usr/local/bin/riofs -f -l /var/log/riofs.log --uid 33 --gid 33 --fuse-options="allow_other" --fmode 0755 --dmode 0755 bucket /mnt/s3/bucket
end script  
  • start on should not be "startup" otherwise it will not be able to mount the S3 bucket, it appears to need both the filesystem and the network
  • The -f flag tells riofs to not daemonize allowing upstart to get and record the process pid
  • --fuse-options="allow_other" appears to be required when running via upstart. If somebody can explain why, I'd appreciate it.
  • Other options like --uid --gid --fmode and --dmode are optional but I prefer not to mount the bucket as root.

One final takeaway for working with upstart: if upstart starts behaving oddly, just restart your machine. It'll save you time and sanity.