My Habitica Instance - http://habitica.linuxbox.ninja
I subscribe to /r/selfhosted and they have a link to another fantasic page which lists tons of software you can host on your own system. From there I found Habitica which is:
Habitica is a free habit building and productivity app that treats your real life like a game. With in-game rewards and punishments to motivate you and a strong social network to inspire you, Habitica can help you achieve your goals to become healthy, hard-working, and happy.
I provisioned myself a new VPS with the following specs:
- 80GB Disk Space
- 4GBs RAM
- 4-cores for CPU
- Ubuntu 15.04
Now Habitica has some installation instructions which can be found here, but I found that I did some Googling around since I hit a couple snags while installing. So before we jump into getting Habitica installed there's some pre-requisites that need to be installed first.
I had some issues running npm install
so I had to adjust my DCACHESIZE
in the containers OpenVZ configuration. I used the following value(s):
DCACHESIZE="2109840:2147483647"
Of note, once I made this change, I restarted the container and confirmed I could then run npm install
without issue.
MongoDB
Habitica utilizes MongoDB for storing data. I utilize this guide here for getting it installed into my Ubuntu 15.04 environment. You should be able to utilize the following steps to get it installed if on Ubuntu 15.04 (assuming you're running the commands as root
:
- Install the MongoDB repository key:
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
- Now add the MongoDB repository to the system:
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
- Now run
apt-get update
- Now install MongoDB!
apt-get install mongodb-org
- You can now run the following to ensure MOngoDB is up and running:
sudo systemctl status mongod
NodeJS & NPM
Next we'll want to get NodeJS and npm
installed. This should be pretty easy.
apt-get install python-software-properties
apt-add-repository ppa:chris-lea/node.js
apt-get install nodejs
apt-get install npm
apt-get install nodejs-legacy
Git - Cloning HabitRPG/habitrpg
Now we want to get the Habitca code to run. First you'll want to create your own fork of the Habitica code. This can easily be done from the GitHub interface. You can find the Habitica repository here.
Once you have your own fork, you can run the following:
git clone https://github.com/YourUsername/habitrpg.git
git remote add upstream https://github.com/HabitRPG/habitrpg.git
You can then run git remote -v
and you should see output similar to this:
origin https://github.com/YourUsername/habitrpg.git (fetch)
origin https://github.com/YourUsername/habitrpg.git (push)
upstream https://github.com/HabitRPG/habitrpg.git (fetch)
upstream https://github.com/HabitRPG/habitrpg.git (push)
Of note, I put my Habitica code into /opt/
so it all lives in /opt/habitrpg
.
Configuring and Running Habitica
We're almost there, just a few more steps. I found that you need to install the following package in Ubuntu to when running npm install
.
apt-get install libkrb5-dev
Next run these commands to install some packages:
npm install -g gulp grunt-cli bower
bower install --allow-root
npm install
This should install everything that Habitica needs to run. Next you'll want to copy over the example configuration file:
cp config.json.example config.json
If you don't plan on using email then nothing needs to be done with the file. However if you plan on needing email to work you'll want to edit at least the ADMIN_EMAIL, SMTP_USER, SMTP_PASS and SMTP_SERVICE values.
Once that is done you should be ready to start up Habitica!
npm start
It may take a minute to start up, but when it does you should be able to visit http://localhost:3000.
Bonus Items - Nginx & Mailgun
Alright, so if you're like me and you've install Habitica on a remote VPS, obviously accessing http://localhost:3000 isn't going to work. This is were Nginx comes in and I use it as a proxy so I can access my Habitica instance at http://habitica.linuxbox.ninja instead. First you'll want to install Nginx:
apt-get install nginx
Next, you'll want to create a Nginx configuration file for Habitica:
cd /etc/nginx/site-available
nano habitica
Now you'll want to put the following into your habitica
file:
# Upstream configuration
upstream shout_upstream {
server 0.0.0.0:3000;
keepalive 64;
}
# Public
server {
listen 80;
server_name yourdomain.com; # domain of my site
location / {
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_redirect off;
proxy_pass http://shout_upstream;
}
}
Next, run this comamnd:
cd /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/habitica .
/etc/init.d/nginx restart
Now you should be able to access your Habitica instance at your own domain!
If you'd like to use email with your Habitica instance you can set it up with a wide variety of services. I needed to use email to reset my password so I had to get it setup and running. You will need to open the config.json file in your favorite text editor and locate the following lines:
"SMTP_USER":"SMTP_USERNAME",
"SMTP_PASS":"SMTP_PASSWORD",
"SMTP_SERVICE":"mailgun",
"SMTP_HOST":"smtp.mailgun.org",
"SMTP_PORT": 587,
"SMTP_TLS": true,
I used Mailgun to handle email for my Habitica instance, but there's quite a wide variety of popular email services this can work with. I also tested Gmail and confirmed that works fine as well.
One of the really nice things about Habitica is that when you save this file, the server will reload itself automatically and use any new configurations.
Summary
I am still learning about how Habitica works, how the MongoDB schema is setup as well as about MongoDB commands as well. It's fun and I think Habitica will be a fun way to keep track of tasks I need to be doing. Anyone is welcome to sign up for an account on the server as well!
Resources
This is a companion discussion topic for the original entry at https://jimmyb.ninja/post/1446239340