Project

General

Profile

Support #565

Install -HabitRPG- Habitica on FreeBSD

Added by Daniel Curtis almost 10 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Web Server
Target version:
Start date:
03/31/2014
Due date:
% Done:

100%

Estimated time:
3.00 h
Spent time:

Description

This guide is to document setting up a self-hosted HabitRPG node.

Prepare the system

  • Start by updating the system and ports tree:
    pkg update && pkg upgrade
    portsnap fetch extract
    
  • Install a few dependencies:
    pkg install node4 bash git gettext-tools gmake mongodb portmaster bison autoconf nasm
    
  • Install npm from ports:
    portmaster www/npm
    

    NOTE: Make sure to enable [X] NODE4 when configuring the www/npm port.
  • Install a few npm packages globally:
    npm install -g gulp grunt-cli bower phantomjs
    
  • Start and enable mongodb at boot:
    echo 'mongod_enable="YES"' >> /etc/rc.conf
    service mongod start
    
  • Add the rpg user
    pw add user -n rpg -m -s /usr/local/bin/bash -c "HabitRPG" 
    

Install HabitRPG

  • Download the develop branch from GitHub:
    cd /usr/local/www
    git clone -b develop https://github.com/HabitRPG/habitrpg.git
    cd habitrpg
    
  • Set the NPM registry:
    npm config set registry "http://registry.npmjs.org/" 
    
  • Install the npm and bower packages:
    npm install
    
  • Create a config file from the example one:
    cp config.json.example config.json
    
  • Edit config.json with your values for:
    1. ADMIN_EMAIL
    2. SMTP_USER
    3. SMTP_PASS
    4. SMTP_SERVICE
  • Change ownership of the habitrpg directory to the rpg user:
    chown -R rpg:rpg /usr/local/www/habitrpg
    
  • Switch to the rpg user:
    su - rpg
    cd /usr/local/www/habitrpg
    
  • Then run bower update:
    bower update
    
  • Start the web application using NPM:
    npm start
    

HabitRPG Init Script

  • Install pm2:
    npm install -g pm2
    
  • Create pm2 FreeBSD init script:
    vi /usr/local/etc/rc.d/habitrpg
    
    • and add the following
      #!/bin/sh
      
      # PROVIDE: habitrpg
      # KEYWORD: shutdown
      
      . /etc/rc.subr
      
      name="habitrpg" 
      start_cmd="${name}_start" 
      stop_cmd="${name}_stop" 
      
      habitrpg_start() {
         echo "habitrpg starting" 
         su - rpg -c "/usr/local/bin/pm2 start /usr/local/www/habitrpg/website/src/server.js; exit"  
      }
      
      habitrpg_stop() {
         echo "habitrpg stopping" 
         su - rpg -c "/usr/local/bin/pm2 kill; exit" 
      }
      
      run_rc_command "$1" 
      
  • And make it executable:
    chmod +x /usr/local/etc/rc.d/habitrpg
    
  • Start and enable pm2 at boot
    echo 'habitrpg_enable="YES"' >> /etc/rc.conf
    service habitrpg start
    

Troubleshooting

I encountered a couple of errors while starting the web application.

Failure to start grunt

failed to locate @import file ../bower_components/angular-loading-bar/build/loading-bar.css Warning: Stylus failed to compile. Used --force, continuing.

You need to update bower and restart the command:

bower update
grunt run:dev

bower update fails

Error: EEXIST, rename '.bower-cache/ef2188def21eb1bbd1f1792311942a53/1.2.15-build.2360%2Bsha.6b18a56'

If you encounter this or a similar error when issuing a bower update, perform the following:

cd .bower-cache/ef2188def21eb1bbd1f1792311942a53/
rm -rf 1.2.15-build.2360%2Bsha.6b18a56

The actual names of these directories may differ on your system.

Problem with OAuth client ID

I recently updated my self-hosted habitica and when I went to restart the app, it crashed complaining about:

TypeError: OAuth2Strategy requires a clientID option

I tracked this back to the Facebook and Google OAuth strategies. And since I use neither of those services, I decided to disable them entirely.

  • Edit the passport setup library file:
    vi /usr/local/www/habitrpg/website/server/libs/setupPassport.js
    
    • And comment out the parts that reference facebook and google:
      import passport from 'passport';
      import nconf from 'nconf';
      //import { Strategy as FacebookStrategy } from 'passport-facebook';
      //import { Strategy as GoogleStrategy } from 'passport-google-oauth20';
      
      // Passport session setup.
      //   To support persistent login sessions, Passport needs to be able to
      //   serialize users into and deserialize users out of the session.  Typically,
      //   this will be as simple as storing the user ID when serializing, and finding
      //   the user by ID when deserializing.  However, since this example does not
      //   have a database of user records, the complete Facebook profile is serialized
      //   and deserialized.
      passport.serializeUser((user, done) => done(null, user));
      passport.deserializeUser((obj, done) => done(null, obj));
      
      // TODO remove?
      // This auth strategy is no longer used. It's just kept around for auth.js#loginFacebook() (passport._strategies.facebook.userProfile)
      // The proper fix would be to move to a general OAuth module simply to verify accessTokens
      /*
      passport.use(new FacebookStrategy({
        clientID: nconf.get('FACEBOOK_KEY'),
        clientSecret: nconf.get('FACEBOOK_SECRET'),
        // callbackURL: nconf.get("BASE_URL") + "/auth/facebook/callback" 
      }, (accessToken, refreshToken, profile, done) => done(null, profile)));
      
      passport.use(new GoogleStrategy({
        clientID: nconf.get('GOOGLE_CLIENT_ID'),
        clientSecret: nconf.get('GOOGLE_CLIENT_SECRET'),
      }, (accessToken, refreshToken, profile, done) => done(null, profile)));
      */
      

Resources


Related issues

Copied from GNU/Linux Administration - Support #353: Setting Up A Self-Hosted HabitRPG NodeClosedDaniel Curtis03/31/2014

Actions

Also available in: Atom PDF