Skip to content

Server Setup

Dmitry Paranyushkin edited this page May 4, 2019 · 24 revisions

The recommendations below are for setting up your own InfraNodus app running on Node.Js and Neo4J on a server. We will use WebFaction as an example.

1. Set up an account on WebFaction

  • Log into your WebFaction admin panel using your browser;
  • Create a domain;
  • Create an application with Node.Js pre-installed (they have this option);
  • Create a website that is hosted on that domain and runs that application;

2. Setting up Node

  • Using ssh log in to your server through Terminal:
ssh username@serverNUMBER.webfaction.com

(if you don't yet have an SSH key, check out a SSH setup guide here)

  • Once logged in,
cd webapps/your_app_name
  • Make Node (which is in the bin root folder) accessible anywhere (otherwise you'll have to use ./bin/node instead of simply node)
export PATH=$PWD/bin:$PATH
  • The app is probably already started (running hello-world.js script) so let's stop it
stop app
  • Set the process.env.PORT parameter globally to the right value (available in WebFaction CP)
export PORT=28721
  • Get into the folder where you want to install infranodus and get the master branch of repo:
git clone https://github.com/noduslabs/infranodus.git

(this will also create an origin)

• The repo doesn't have a configuration file, which you might want to create if you want to adjust Neo4j port, username, password parameters and set up the invite-only registration:

nano config.json

and then

  {
      "neo4j":  {
          "host": "localhost:7474",
          "username": "",
          "password": ""
      },
      "secrets": {
          "invitation": "invite_code"
      }
  }

3. Setting up Java

InfraNodus runs on Neo4J graph database, which runs in Java. So you need to download JRE 7 (Java Runtime Environment 7) Linux 64bit from Oracle's website. Then use this to copy it to your server's home folder:

  scp ~/Downloads/jre-7-linux-x64.gz username@server_number.webfaction.com: 

After that, untar it:

  tar -xf jre-7-linux-x64.gz 

A new folder jre1.7.0 will be created in the home folder. Let's add it into $PATH, so that version of Java is automatically used on the server:

nano .bashrc

to open the settings file... then add:

PATH=/home/username/jre1.7.0/bin:$PATH
export PATH

4. Installing and Setting Up Neo4J

Now that Java is installed and the app is there, let's install Neo4J. To quote WebFaction support:

  1. Install Java 7 as previously advised.
  1. Create a new 'custom app listening on port' application in our control panel to reserve a port for your Neo4J HTTP interface.
  1. Create a second 'custom app listening on port' application in our control panel to reserve a port for your Neo4J HTTPS interface.
  1. SSH into your server and run the following commands:

cd ~ wget http://dist.neo4j.org/neo4j-community-2.0.1-unix.tar.gz tar zxf neo4j-community-2.0.1-unix.tar.gz cd neo4j-community-2.0.1

  1. Edit conf/neo4j-server.properties to set org.neo4j.server.webserver.port and org.neo4j.server.webserver.https.port to the port numbers you were assigned in steps 1 and 2.
  1. Add the app from step 1 to a HTTP site.
  1. Add the app from step 2 to a HTTPS site.
  1. Start the neo4j server.

(you might want to add /bin folder of neo4j into $PATH so it's easier to launch it: use nano ~/.bashrc, make fixes, then source ~/.bashrc and perhaps close and open the terminal window again)

5. Automatic App Relaunching

Using pm2 now.

Install it on the server, then launch it

 pm2 start app.js --log ~/.pm2/logs/infralog20190505.log

To save all the log into one file for debugging. Sometimes PM2 doesn't write logs correctly. In that case

pm2 delete app

And then restart

##Old info##

To make it possible that the app runs while you're not inside the shell, use forever for Node.Js or it's also possible to do it using WebFaction's own scripts. By default they launch hello-world, but if you edit the start script at

 /home/your_username/webapps/your_nodejs_app/bin/start  

and change hello-world to app then it should work fine.

The cron job automatically relaunches it every 20 minutes.

To view current cronjobs:

crontab -l

To edit (make it more often, for example):

crontab -e

Alternatively: install forever.js and then launch the app with it.

nohup forever app.js > logs &

6. Additional Software

PhantomJS may be needed to be installed. In this case, download it from http://phantomjs.org/download.html

and then use the installation instructions on: http://docs.webfaction.com/software/home-install.html?highlight=install%20from%20source#installing-software-from-source

and once it's installed, add it's path to the $PATH variable:

export PATH=$HOME/phantomjs-1.9.8-linux-x86_64/bin:$PATH

This should be done by editing your ~/.bashrc e.g. nano ~/.bashrc and adding the string above to the PATH= string

Then restart config by $ source ~/.bashrc

7. Some interesting add-ons

If you're running InfraNodus on localhost:3000 (or any other port), you can access it via wi-fi network if you find out the localhost IP using

ifconfig in terminal

then look for en1 inet IP, e.g. 192.168.1.103 and add the port to it, i.e. 192.168.1.103:3000

You can’t perform that action at this time.