Project

General

Profile

Support #647

Updated by Daniel Curtis almost 9 years ago

This is a guide on installing JSbin on FreeBSD. 

 *NOTE*: -After working on getting JSbin to install on FreeBSD for many hours, I was unable to get it working.- 

 *UPDATE*: I found that +JSbin works on node v0.10+, the default nodejs version for FreeBSD is v0.12. Once I installed the older version JSbin installed correctly. 

 h2. Prepare the system 

 * Make sure the system is up to date: 
 <pre> 
 pkg update && pkg upgrade 
 </pre> 

 * Install a few dependencies: portmaster 
 <pre> 
 pkg install node010 portmaster libzmq2 nasm git sqlite3 
 pkg2ng 
 </pre> 

 * Install node010 and npm from the ports tree: 
 <pre> 
 portmaster www/node010 www/npm 
 </pre> 
 *# *NOTE*: Make sure to check *[X]node010* [X]node010 when configuring the npm port 

 h2. Install JSbin with npm 

 * Install grunt-cli globally JSbin using npm: 
 <pre> 
 npm install -g grunt-cli --sqlite=/usr/local jsbin 
 </pre> 

 * Add Create a jsbin user to separate privileges: new config file and edit it as necessary: 
 <pre> 
 pw add user -n cd /usr/local/lib/node_modules/jsbin 
 cp config.default.json config.local.json 
 </pre> 

 * Test JSbin in development mode: 
 <pre> 
 jsbin -m -s /bin/sh -c "JSbin" 
 </pre> 

 * Go to http://localhost:3000 in a web browser 

 h2. Install JSbin from GitHub 

 * Switch the jsbin user: Create a working source directory: 
 <pre> 
 su - jsbin mkdir /usr/local/src && cd /usr/local/src 
 </pre> 

 * Clone JSbin from GitHub: 
 <pre> 
 git clone https://github.com/remy/jsbin.git 
 cd jsbin 
 </pre> 

 * Install grunt-cli globally using npm: 
 <pre> 
 npm install -g grunt-cli 
 </pre> 

 * Then install the developer dependencies: 
 <pre> 
 npm install -g --sqlite=/usr/local --dev 
 </pre> 

 h2. Running JSbin with PM2 

 * Create a new config file and edit it as necessary: Install pm2 globally: 
 <pre> 
 cp config.default.json config.local.json npm install -g pm2 
 </pre> 

 * Test JSbin in development mode: Add a jsbin user to separate privileges: 
 <pre> 
 ./bin/jsbin pw add user -n jsbin -m -d /usr/local/lib/node_modules/jsbin -s /bin/sh -c "JSbin" 
 </pre> 

 * Go Change the ownership of the global jsbin folder to http://localhost:3000 in a web browser 

 * Exit from the jsbin user: 
 <pre> 
 exit chown -R jsbin /usr/local/lib/node_modules/jsbin 
 </pre> 

 h2. Running JSbin with PM2 

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

 * Switch to the jsbin user: 
 <pre> 
 su - jsbin 
 </pre> 

 * Start jsbin using pm2: 
 <pre> 
 pm2 start /home/jsbin/jsbin/bin/jsbin bin/jsbin 
 exit 
 </pre> 

 h2. JSbin FreeBSD Boot Script 

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

 # PROVIDE: jsbin 
 # KEYWORD: shutdown 

 . /etc/rc.subr 

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

 pm2_start() { 
    echo "pm2 starting"  
    su - jsbin -c "/usr/local/bin/pm2 start /home/jsbin/jsbin/bin/jsbin; /usr/local/lib/node_modules/jsbin/bin/jsbin; exit"   
 } 

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

 run_rc_command "$1" 
 </pre>  

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

 * Start and enable jsbin at boot 
 <pre> 
 echo 'jsbin_enable="YES"' >> /etc/rc.conf 
 service jsbin start 
 </pre> 

 h2. Resources 

 * https://github.com/jsbin/jsbin/blob/master/docs/running-your-own-jsbin.md

Back