My personal blog

This is my personal blog about tech, arts, philosophy and the stuff that I care about in my life.

Setting up a DigitalOcean droplet for Rails

Setting up post receive hook


ssh root@
apt-get install memcached redis-server git vim
cd /home/rails
mkdir .git
git init --bare
cd hooks
vim post-receive
chmod +x post-receive

Enter the following content into the post-receive file. This will allow for a single git push to deploy the entire rails application.


#!/bin/bash
echo 'Received push..'

# Switch to rails user
su rails

# Checkout git code into /home/rails dir
echo 'Checking out code..'
APP_PATH=/home/rails
GIT_DIR=/home/rails/.git
git --work-tree=${APP_PATH} --git-dir=${GIT_DIR} checkout -f
cd ${APP_PATH}

# Reload rvm to have proper ruby functions. This is outputted to `/dev/null` because we don't are for the output of the call.
# See http://www.simontaranto.com/2014/01/23/doing-more-than-deploying-code-in-a-git-post-receive-hook.html for details
source /usr/local/rvm/bin/rvm > /dev/null

# Bundle gems
# Start by aliasing the direct path to bundler. See problem with rvm above.
# Then check if the bundle is complete. Otherwise bundle gems.
echo 'Bundling..'
alias bundle=/usr/local/rvm/gems/ruby-2.1.3@global/bin/bundle
bundle check --gemfile=Gemfile --path vendor/bundle || bundle install --deployment --quiet

# Restart all services. If services are added to the app, add them here as well.
echo 'Restarting services..'
service unicorn restart
service memcached restart
service redis-server restart

Setting up local remote

Then on your local machine, run the following to enable git push production master to push the code to the digital ocean droplet.

bash git remote add production ssh://root@178.62.120.146/home/rails/.git

Unicorn setup

To change the unicorn setup, run vim /home/unicorn/unicorn.conf to view and edit the unicorn configuration. It shouldn’t be necessary to change anything here, though.

Disabling destructive rake actions in production

Ever wondered how it is to loose all the data in a production environment? Ever tried it?

If you have, I suggest that you use this simple snippet to save the day :)

if Rails.env == 'production'
  tasks = Rake.application.instance_variable_get '@tasks'
  tasks.delete 'db:reset'
  tasks.delete 'db:drop'
  namespace :db do
    desc 'db:reset not available in this environment'
    task :reset do
      puts 'db:reset has been disabled'
    end
    desc 'db:drop not available in this environment'
    task :drop do
      puts 'db:drop has been disabled'
    end
  end
end

Creating a role playing character generator part 3

Getting people to contribute

All right, so there’s no fun in doing a project alone and only for one self. Of course, there’s the satisfaction of creating this huge, complicated application, that needs to be able to handle all kinds of similarly, but yet different games and structures. But really role playing is about the social aspect. And truthfully it would be a greater success and experience if people would participate.

So the question becomes, how do you motivate people to join in on the idea of creating this awesome application?

Open source

I believe that one of the first things is running your application on open source software. This allows everyone regardless of wealth to participate. Further more, leaving the source open for review ultimately creates a mor secure and robust implementation with less errors and we all get a better experience for it.

All though: There is pitfalls with open source software, but mostly they are about the same as with proprietary ones. Mainly it’s important to choose a software that can run on as many different operating systems as possible.

In this case - and because I love the language and the framework - this means using Ruby on Rails.

Easy and friendly

Having an easy, outgoing and friendly tone in the discussions is paramount. If you scare the people, who participate in the discussions away, then you have less people participating - not more.

And this application is for all who play d20 games, and his means that we need to strive to create an environment that everybody is happy to contribute within.

Keeping track

It’s important to keep track of your application, and to be honest and forthcoming about the prospect for features to be released and bugs to be solved. At Chargen we try to keep this information easily available through milestones and issues - all of which are publicly available.

This means that at any time, you can review any and all of the security issues, feature requests or enhancements that’s being planned for the application. You can also see a schedule for when they’re expected to be released.

So come and join us

If you are up for joint in and helping to create this awesome application you can either mail me or start helping out by going to our github page.

Coffee and water

I often find my self trying to keep my intake of coffee down. Not because I feel addicted to it - I don’t have any problems going days without it - but because like all good things it should be taken in moderation.

And I don’t know about you but coffee seems to have the same effect as alcohol, in the sense that it quickly and effectively drains water from my body.

So when ever I go to grab a cup of coffee I try to have a glass of cool refreshing water as well. I find that this is a good habit and it keeps the bad effects of caffeine at bay.