NodeJS is not working

From IVS Wiki
Revision as of 14:05, 22 August 2017 by IVSWikiBlue (talk | contribs) (Created page with "=Symptoms= If NodeJS is not working properly you may experience one or more of the following symptoms: * When starting or stopping a recording the buttons do not update. * Whe...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Symptoms

If NodeJS is not working properly you may experience one or more of the following symptoms:

  • When starting or stopping a recording the buttons do not update.
  • When opening the Observe tab, only the following message is displayed: [[ pageTitle() ]]

Nodejs.png

Diagnosis

There are several possible causes for these issues, but all are related to NodeJS.

Check Connection

To check the connection to NodeJS from the client computer do the following:

  1. Open the Valt application in google chrome
    Nodejs6.png
  2. Right click on the page and select Inspect from the menu
    Nodejs7.png
  3. Click on the Console tab
    Nodejs8.png
    If the client computer is unable to connect to NodeJS you will receive an error message like the one above.

NodeJS stopped

The nodejs service may be stopped or may have crashed. To check this do the following:

  1. Connect to the Valt appliance via SSH
  2. run ps -ax | grep node
Nodejs2.png Nodejs3.png
This is a system where NodeJS is not running. This is a system where NodeJS is running.

If NodeJS is not currently running, you can attempt to start it using the following command:

sudo service valtcontrols start

This command will only work on Valt appliances with the command line menu installed. On older Valt systems, or those that were upgraded without installing the command line menu, use the following command:

sudo /usr/local/bin/forever start /var/www/v3/nodejs/index.js

NodeJS is not listening

To check to see if NodeJS is listening for inbound connections do the following:

  1. Connect to the Valt appliance via SSH
  2. run nc -zv 127.0.0.1 8080
Nodejs5.png Nodejs4.png
This is a system where NodeJS is not listening. This is a system where NodeJS is listening.

Causes

Firewall

Issues connecting to NodeJS can be caused by a firewall on the network between the client PC and the Valt appliance. If port 8080 is not open between the PC and the Valt appliance, the client will be unable to connect to NodeJS. If this is the cause of the issue you will be unable to connect to NodeJS from the client pc, but NodeJS will be running and will be listening for inbound connections.

Antivirus

Issues connecting to NodeJS can be caused by a local antivirus on the client PC. If port 8080 is not open between the PC and the Valt appliance, the client will be unable to connect to NodeJS. If this is the cause of the issue you will be unable to connect to NodeJS from the client pc, but NodeJS will be running and will be listening for inbound connections.

Server.js Config Error

If the server has been configured to utilize SSL, but an error was made in the configuration of the server.js file, the NodeJS service may fail to start or may start, but may not listen for connections. This is most likely to occur if the SSL configuration has been performed manually instead of utilizing the provided scripts through the command line menu. This can also occur if a typo is made when entering the key and certificates into the command line menu.

  1. Connect to the Valt appliance via SSH
  2. run sudo nano /var/www/v3/nodejs/server.js
    Nodejs9.png
    The file should appear similar to the picture above. Specifically the following section:
var PORT_SSL = 8080; //working https port
var sslOptions = {
key: fs.readFileSync('/etc/apache2/ssl/boonefettercameras.chla.usc.edu.key'$
cert: fs.readFileSync('/etc/apache2/ssl/boonefettercameras.pem'), //path to$
ca: fs.readFileSync('/etc/apache2/ssl/boonefettercameras.pem') // path to ca
};
This should specify the path to the key file and the certificates. If there is a typo here, you can manually correct it.
If the certificate was installed using the command line, the easiest solution may be to disable SSL and reinstall the certificate.

Untrusted Certificate

If the server has been configured to utilize SSL and the certificate used was a self signed certificate or a certificate signed by an internal CA, you may encounter this error because the browser does not trust the certificate. The issue can be overcome in a variety of ways:

  1. Use a different browser
  2. Install the certificate and any required intermediate certificates on the computer
  3. Reissue the certificate with a SAN (can correct issues with google chrome when using an internal CA that is already trusted)
  4. Issue a certificate from a publicly trusted CA.

Re-issue the certificate with a SAN

  1. Connect to the Valt appliance via SSH
  2. run nano csr_details.txt
  3. Copy and paste the following into nano.
    [req]
    default_bits = 2048
    prompt = no
    default_md = sha256
    req_extensions = req_ext
    distinguished_name = dn
    [ dn ]
    C=US
    ST=New York
    L=Rochester
    O=End Point
    OU=Testing Domain
    emailAddress=your-administrative-address@your-awesome-existing-domain.com
    CN = www.your-new-domain.com
    [ req_ext ]
    subjectAltName = @alt_names
    [ alt_names ]
    DNS.1 = your-new-domain.com
    DNS.2 = www.your-new-domain.com
  4. Update the information to match your installation. This is the same information you would normally put in a CSR.
  5. Press ctrl X
  6. Enter Y
  7. Press Enter
  8. run openssl req -new -sha256 -nodes -out your-new-domain.com.csr -newkey rsa:2048 -keyout your-new-domain.com.key -config <( cat csr_details.txt )
    Make sure to update the csr and key path for your installation.

Wrong Key

If you enter the incorrect key or make a typo when specifying the path to the key file during configuration of SSL, NodeJS will not start. Typically this will also prevent apache from starting. The best solution to this is to disable SSL and then re-enable it and enter the correct key.

Certificate Error

A problem with the certificate will cause NodeJS to fail to start. The most likely cause of this is incorrect encoding on the certificate. The certificate should be PEM encoded. If this is the case, the following will occur:

  1. Apache will display the site in SSL
  2. NodeJS may appear to be running
  3. NodeJS will not be listening.
  4. Manually starting NodeJS with node /var/www/v3/nodejs/server.js will result in an error.

You can test the certificate by doing the following:

Run openssl x509 -in certificate.cer -text -noout

Nodejs10.png

An error similar to the picture above indicates the certificate is not PEM encoded.
Run openssl x509 -text -inform DER -in certificate.cer
This command should cause the certificate to display. If it does, the certificate is DER encoded instead of PEM encoded.
You can convert the certificate from DER to PEM using the following command:
openssl x509 -inform der -in certificate.cer -out certificate.pem

Once this is complete, reinstall the new certificate.