Project

General

Profile

Support #565

Updated by Daniel Curtis over 8 years ago

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

 h2. Prepare the system 

 * Start by updating the system and ports tree: 
 <pre> 
 pkg update && pkg upgrade 
 portsnap fetch extract 
 </pre> 

 * Install a few dependencies: 
 <pre> 
 pkg install bash git mongodb node npm bison 
 </pre> 

 * Start and enable mongodb at boot: 
 <pre> 
 echo 'mongod_enable="YES"' >> /etc/rc.conf 
 service mongod start 
 </pre> 

 * Add the rpg user 
 <pre> 
 pw add user -n rpg -m -s /usr/local/bin/bash -c "HabitRPG" 
 </pre>  

 h2. Install HabitRPG 

 * Download the develop branch from GitHub: 
 <pre> 
 cd /usr/local/www 
 git clone -b develop https://github.com/HabitRPG/habitrpg.git 
 cd habitrpg 
 </pre> 

 * Install grunt-cli npm package globally 
 <pre> 
 npm install -g grunt-cli bower phantomjs 
 </pre> 

 * Install the npm and bower packages: 
 <pre> 
 npm install 
 </pre> 

 * Create a config file from the example one: 
 <pre> 
 cp config.json.example config.json 
 </pre> 

 * Edit @config.json@ with your values for:  
 *# *ADMIN_EMAIL* 
 *# *SMTP_USER* 
 *# *SMTP_PASS* 
 *# *SMTP_SERVICE* 

 * Then seed the database with initial settings: 
 <pre> 
 node ./website/src/seed.js 
 </pre> 

 * Change ownership of the habitrpg directory to the rpg user: 
 <pre> 
 chown -R rpg:rpg /usr/local/www/habitrpg 
 </pre> 

 * Switch to the rpg user: 
 <pre> 
 su - rpg 
 cd /usr/local/www/habitrpg 
 </pre> 

 * Then run bower update: 
 <pre> 
 bower update 
 </pre> 

 * Start the web application using NPM: 
 <pre> 
 npm start 
 </pre> 

 h. HabitRPG Init Script 

 * Install pm2: 
 <pre> 
 npm install -g pm2 
 </pre> 

 * Create pm2 FreeBSD init script: 
 <pre> 
 vi /usr/local/etc/rc.d/habitrpg 
 </pre> 
 #* and add the following 
 <pre> 
 #!/bin/sh 

 # PROVIDE: habitrpg 
 # KEYWORD: shutdown 

 . /etc/rc.subr 

 name="habitrpg" 
 start_cmd="${name}_start" 
 stop_cmd="${name}_stop" 

 habitrpg_start() pm2_start() { 
    echo "habitrpg starting" 
    su - rpg -c "/usr/local/bin/pm2 start /usr/local/www/habitrpg/website/src/server.js; exit"   
 } 

 habitrpg_stop() pm2_stop() { 
    echo "habitrpg stopping" 
    su - rpg -c "/usr/local/bin/pm2 kill; exit"  
 } 

 run_rc_command "$1" 
 </pre>  

 * And make it executable: 
 <pre> 
 chmod +x /usr/local/etc/rc.d/habitrpg 
 </pre> 

 * Start and enable pm2 at boot 
 <pre> 
 echo 'habitrpg_enable="YES"' 'pm2_enable="YES"' >> /etc/rc.conf 
 service habitrpg </pre> 

 * Now start HabitRPG with pm2: 
 <pre> 
 pm2 start /usr/local/www/habitrpg/website/src/server.js 
 </pre> 

 This will start an HTTP server on port 3000, so pointing a web browser there will access the HabitRPG site 

 h2. Troubleshooting 

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

 h3. 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: 
 <pre> 
 bower update 
 grunt run:dev 
 </pre> 

 h3. 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: 
 <pre> 
 cd .bower-cache/ef2188def21eb1bbd1f1792311942a53/ 
 rm -rf 1.2.15-build.2360%2Bsha.6b18a56 
 </pre> 

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

 h2. Resources 

 * http://habitrpg.wikia.com/wiki/Setting_up_HabitRPG_locally 
 * http://habitrpg.wikia.com/wiki/Guidance_for_Blacksmiths#Git 
 * http://habitrpg.wikia.com/wiki/Installation_troubleshooting 
 * https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager 
 * https://github.com/ariya/phantomjs/issues/12963 
 * https://github.com/Unitech/pm2/issues/157

Back