Project

General

Profile

Support #565

Updated by Daniel Curtis about 9 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 bash: 
 <pre> 
 pkg install bash 
 </pre> 

 * Install git: 
 <pre> 
 pkg install git 
 </pre> 

 * Install and set up MongoDB 
 <pre> 
 pkg install mongodb 
 </pre> 
 #* Start and enable mongodb at boot: 
 <pre> 
 echo 'mongod_enable="YES"' >> /etc/rc.conf 
 service mongod start 
 </pre> 

 * Install and set up NodeJS, NPM, and PhantomJS: 
 <pre> 
 pkg install node npm phantomjs 
 </pre> 

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

 h2. Install HabitRPG 

 * Fork the repository on your computer 
 <pre> 
 cd /usr/local/www 
 git clone https://github.com/HabitRPG/habitrpg.git 
 </pre> 

 * Switch to the develop branch: 
 <pre> 
 cd habitrpg 
 git checkout develop 
 </pre> 

 * Install grunt-cli npm package globally 
 <pre> 
 npm install -g grunt-cli bower 
 </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 
 </pre> 

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

 h2. Run HabitRPG  

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

 h3. Autostart HabitRPG 

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

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

 # PROVIDE: pm2 
 # KEYWORD: shutdown 

 . /etc/rc.subr 

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

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

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

 run_rc_command "$1" 
 

 </pre>  

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

 * Start and enable pm2 at boot 
 <pre> 
 echo 'pm2_enable="YES"' >> /etc/rc.conf 
 </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