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: <pre> pkg install node010 portmaster libzmq2 nasm git sqlite3 pkgconf pkg2ng </pre> * Install node010 and npm from the ports tree: <pre> portmaster www/npm </pre> *# *NOTE*: Make sure to check *[X]node010* when configuring the npm port * Install grunt-cli globally using npm: <pre> npm install -g grunt grunt-cli </pre> * Add a jsbin user to separate privileges: <pre> pw add user -n jsbin -m -s /bin/sh -c "JSbin" </pre> h2. Install JSbin * Install Switch the jsbin globally: user: <pre> su - jsbin </pre> * Clone JSbin from GitHub: <pre> git clone https://github.com/remy/jsbin.git cd jsbin </pre> * Install a few grunt-contrib node modules: <pre> npm install grunt-contrib-uglify grunt-contrib-jshint grunt-contrib-concat karma grunt-karma karma-sauce-launcher </pre> * Then install the developer dependencies: <pre> npm install --sqlite=/usr/local -g jsbin </pre> * Create a new config file and edit it as necessary: <pre> cp /usr/local/lib/node_modules/jsbin/config.default.json /usr/local/etc/jsbin.conf.json config.default.json config.local.json </pre> * Edit the jsbin config file: <pre> vi /usr/local/etc/jsbin.conf.json /home/jsbin/jsbin/config.local.json </pre> #* Also while editing the jsbin config file, set a session secret key: <pre> "session": { "secret": "v09sfyka2e32vdxa9k297d1" }, </pre> * Build the production environment files: <pre> cd /usr/local/lib/node_modules/jsbin npm install grunt-contrib-uglify grunt-contrib-jshint grunt-contrib-concat grunt build </pre> * Change the ownership of the jsbin site to the jsbin user: <pre> chown -R jsbin:jsbin /usr/local/lib/node_modules/jsbin </pre> * Test JSbin: JSbin in development mode: <pre> su - jsbin ./bin/jsbin jsbin -c /usr/local/etc/jsbin.conf.json </pre> * Go to http://localhost:3000 in a web browser * Exit from the jsbin user: <pre> exit </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 /usr/local/lib/node_modules/jsbin/bin/jsbin /home/jsbin/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 "cd /usr/local/lib/node_modules/jsbin; /home/jsbin/jsbin; /usr/local/bin/pm2 start /usr/local/lib/node_modules/jsbin/bin/jsbin; /home/jsbin/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