Project

General

Profile

Support #647

Install JSbin On FreeBSD

Added by Daniel Curtis over 9 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Web Server
Target version:
Start date:
08/28/2015
Due date:
% Done:

100%

Estimated time:
2.00 h
Spent time:

Description

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.

UPDATE: This guide has been updated for FreeBSD 10.

WARNING: JSbin will only run on nodejs 0.10; as of 1 Oct. 2016 the ports tree does not have www/node010; so an older snapshot of the ports tree must be used. JSbin will not run on FreeBSD 10 otherwise.

Prepare the system

  • Make sure the system is up to date and ports tree is installed:
    pkg update && pkg upgrade
    
  • Use the version of the ports tree with node010:
    svn checkout svn://svn.freebsd.org/ports/branches/2016Q3 /usr/ports/
    
  • Add the following to the make.conf file to use nginx while compiling passenger:
    echo 'OPTIONS_UNSET+= DOCS NLS X11 EXAMPLES' >> /etc/make.conf
    echo 'OPTIONS_SET+= NODE010' >> /etc/make.conf
    
  • Install a few dependencies:
    pkg install portmaster libzmq2 nasm git sqlite3 pkgconf autoconf python gmake
    
  • Install node010 and npm2 from the ports tree:
    portmaster www/node010 www/npm2
    
  • Install grunt-cli globally using npm:
    npm install -g grunt grunt-cli
    
  • Add a jsbin user to separate privileges:
    pw add user -n jsbin -m -s /bin/sh -c "JSbin" 
    

Install JSbin

  • Install jsbin globally:
    npm install --sqlite=/usr/local -g jsbin
    
  • Create a new config file and edit it as necessary:
    cp /usr/local/lib/node_modules/jsbin/config.default.json /usr/local/lib/node_modules/jsbin/config.local.json
    
  • Edit the jsbin config file:
    vi /usr/local/lib/node_modules/jsbin/config.local.json
    
    • Modify the env, timezone, and url settings:
        "env": "production",
        "timezone": "PST",
        "url": {
          "host": "jsbin.example.com",
          "prefix": "/",
          "ssl": true,
          "static": false,
          "runner": false
        },
        "session": {
          "secret": "v09sfyka2e32vdxa9k297d1" 
        },
        "store": {
          "adapter": "sqlite",
          "sqlite": {
            "location": "jsbin.sqlite" 
          },
        },
      
  • Build the production environment files:
    cd /usr/local/lib/node_modules/jsbin
    npm install grunt-contrib-uglify grunt-contrib-jshint grunt-contrib-concat
    grunt build
    
  • Change the ownership of the jsbin site to the jsbin user:
    chown -R jsbin /usr/local/lib/node_modules/jsbin
    
  • Test JSbin:
    su - jsbin
    jsbin
    

    NOTE: Press Ctrl+C to kill the test server when finished.
  • Exit from the jsbin user:
    exit
    

Running JSbin with PM2

  • Install pm2 globally:
    npm install -g pm2
    
  • Switch to the jsbin user:
    su - jsbin
    
  • Start jsbin using pm2:
    pm2 start /usr/local/lib/node_modules/jsbin/bin/jsbin
    exit
    

JSbin Init Script

  • Create a jsbin FreeBSD init script:
    vi /usr/local/etc/rc.d/jsbin
    
    • and add the following
      #!/bin/sh
      
      # PROVIDE: jsbin
      # KEYWORD: shutdown
      
      . /etc/rc.subr
      
      name="jsbin" 
      
      jsbin_port="3000" 
      jsbin_proxy="off" 
      
      start_cmd="${name}_start" 
      stop_cmd="${name}_stop" 
      
      jsbin_start() {
         echo "pm2 starting" 
         su - jsbin -c "cd /usr/local/lib/node_modules/jsbin; /usr/bin/env PORT=${jsbin_port} JSBIN_PROXY=${jsbin_proxy} /usr/local/bin/pm2 --name ${name} start /usr/local/lib/node_modules/jsbin/bin/jsbin; exit"  
      }
      
      jsbin_stop() {
         echo "pm2 stopping" 
         su - jsbin -c "/usr/local/bin/pm2 delete ${name}; exit" 
      }
      
      run_rc_command "$1" 
      
  • And make it executable:
    chmod +x /usr/local/etc/rc.d/jsbin
    
  • Start and enable jsbin at boot
    echo 'jsbin_enable="YES"' >> /etc/rc.conf
    echo 'jsbin_proxy="on"' >> /etc/rc.conf
    service jsbin start
    

Install Nginx

  • Install Nginx
    pkg install nginx
    
  • Start and enable nginx at boot:
    echo 'nginx_enable="YES"' >> /etc/rc.conf
    service nginx start
    
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
    
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    
    • And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      
      events {
          worker_connections  1024;
      }
      
      http {
          include       mime.types;
          default_type  application/octet-stream;
          sendfile        on;
          keepalive_timeout  65;
      
          # Load config files from the /etc/nginx/conf.d directory
          include /usr/local/etc/nginx/conf.d/*.conf;
      }
      
  • Add a default site server block:
    vi /usr/local/etc/nginx/conf.d/www.example.com.conf
    
    • Add the following:
      server {
          listen 80;
          server_name jsbin.example.com;
          root /usr/local/lib/node_modules/jsbin/public;
          index index.html;
      
          location @jsbin {
              proxy_pass http://localhost:3000;
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_redirect off;
              proxy_set_header X-Accel-Buffering no;
              proxy_set_header Connection '';
              proxy_http_version          1.1;
              proxy_buffering             off;
              proxy_cache                 off;
              proxy_set_header X-Forwarded-Proto https;
      
          }
      
          location / {
              add_header  Pragma "public";
              add_header  Cache-Control "public, must-revalidate, proxy-revalidate";
              add_header  Last-Modified $sent_http_Expires;
              add_header  Access-Control-Allow-Origin *;
              try_files $uri $uri/ @jsbin;
          }
      
      }
      
  • And restart nginx:
    service nginx restart
    

Resources

#1

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
#2

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
  • Status changed from New to Rejected
#3

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
  • Status changed from Rejected to In Progress
  • % Done changed from 0 to 50
#4

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
  • % Done changed from 50 to 80
#5

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
#6

Updated by Daniel Curtis over 9 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 80 to 100
#7

Updated by Daniel Curtis over 9 years ago

  • Status changed from Resolved to Closed
#8

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#9

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#10

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#11

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#12

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#13

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#14

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#15

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#16

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#17

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#18

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#19

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#20

Updated by Daniel Curtis almost 9 years ago

  • Description updated (diff)
#21

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
  • Target version changed from FreeBSD 9 to FreeBSD 10
#22

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#23

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#24

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#25

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#26

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#27

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)
#28

Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)

Also available in: Atom PDF