ownCloud on OpenShift

Last July, Google shut down Reader, one of my most favorite apps, and to ease off my Reader withdrawal, I decided to host my own RSS reader. There were several alternatives out there, but I opted for ownCloud's News app, hosted on OpenShift. I've outlined the steps I took below.

ownCloud is a cloud storage app that runs on a LAMP stack. OpenShift is Red Hat's Platform as a Service (Paas) offering that allows rapid application deployment using various software stacks.

The steps below have been liberally taken from Isaac Christoffersen's OpenShift ownCloud quickstart. I've also forked Isaac's quickstart that incorporates the steps. Feel free to fork and submit pull requests.

This guide assumes that you have an OpenShift account, and the requisite client tools. This also assumes that the app is located in the project directory.

mkdir -p ~/projects
cd ~/projects
  1. Create app.
    rhc app create owncloud php-5.3 mysql-5.1
    rhc alias add owncloud your.alias.goes.here
    rhc app show owncloud
    rm owncloud/php/*.php
    
  2. Get ownCloud.
    mkdir ~/projects/owncloud-dist 
    cd ~/projects/owncloud-dist
    wget http://download.owncloud.org/community/owncloud-5.0.10.tar.bz2
    tar xjvf owncloud-5.0.10.tar.bz2
    cd owncloud
    rsync -av . ~/projects/owncloud/php/
    
  3. Add script to auto-configure ownCloud.

    In ~/projects/owncloud/php/config/autoconfig.php:

  4. Add OpenShift-specific action hooks.

    Add the following action hooks to be executed at specific points in the deployment process of the OpenShift app. The scripts are located in ~/projects/owncloud/.openshift/action_hooks.

    • pre_build - Restores an existing configuration file and removes the autoconfig script above for succeeding pushes.
    • deploy - Ensures that the MySQL cartridge is available.
    • post_deploy - During the first push, it will autoconfigure the ownCloud instance. For succeeding deployments, it will ensure that an existing configuration is used.
  5. Use cron.

    The News app requires background jobs that need to run regularly, so add OpenShift's Cron cartridge.

    rhc cartridge-add cron-1.4 -a owncloud
    

    Cron jobs go in ~/projects/owncloud/.openshift/cron/ under the respective periods. Add the following job that runs every 15 minutes (in ~/projects/owncloud/.openshift/cron/minutely/owncloud.sh):

    #!/bin/bash
    
    if [[ -f  $OPENSHIFT_REPO_DIR/php/cron.php ]] ; then
        if [[ $(( $(date +%M) % 15 )) -eq 0 ]] ; then
            printf "{\"app\":\"Cron\",\"message\":\"%s\",\"level\":1,\"time\":%s}\n" "Running cron job" $(date +%s) >> $OPENSHIFT_DATA_DIR/owncloud.log
            pushd $OPENSHIFT_REPO_DIR/php &> /dev/null
            php -f cron.php
            if [[ $? -ne 0 ]] ; then
                printf "{\"app\":\"Cron\",\"message\":\"%s\",\"level\":2,\"time\":%s}\n" "Error running cron job" $(date +%s) >> $OPENSHIFT_DATA_DIR/owncloud.log
            fi
            popd &> /dev/null
        fi
    fi
    

    Make sure to enable the system cron in ownCloud's Admin settings page.

  6. Deploy ownCloud.
    cd ~/projects/owncloud
    git add .
    git commit -a -m "Deploy to OpenShift"
    git push
    
  7. Log in and start using ownCloud on OpenShift.

    Go to https://your.alias.goes.here, and use admin/OpenShiftAdmin as the default first-time credentials. (Make sure to change this ASAP.)

Comments

Popular posts from this blog

Pull files off Android phone