Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions

You are not logged in.

Announcement

#1 2015-07-21 19:04:25

devman
Member
Registered: 2014-09-20
Posts: 76

NodejsHelper with automated hosting

I have set up nodejshelper with redis on a site with automated hosting.  It is working for the main site: when the node server.js is running (manually from the command line so I can see the console) the admin and the client are both using node server.

However, it is not working for the instances.  When inspecting an instance web site it appears that it is not loading socket.io or recognizing that nodejshelper is a loaded extension.

How do the instances know to use the nodejshelper extension?

Configuration:
nodejs is handling the communication on port 31129 (had to open ports on firewall). Not using nginx for proxy at this point.

settings.js

var settings = {}

/**
 * Should we use publish notifications?
 * Redis have to be running on 127.0.0.1 and 6379 port.
 * Set false to disable
 * */
settings.use_publish_notifications = true;

// If you will be using only web application set this to true, will save some resource
settings.ignore_desktop_client = true;
settings.redis = {};
settings.redis.port = 6379;
settings.redis.host = '127.0.0.1';
settings.redis.options =  {};

settings.web = {};
settings.debug = {};

/**
 * Set path where socket.io is located, it can be also just socket.io
 * */
/* settings.socketiopath = '/usr/local/lib/node_modules/socket.io'; */
settings.socketiopath = '/etc/node_modules/socket.io';

/**
 * Set your settings
 * */
settings.web.host = "example.com";
settings.web.port = 31129;

/**
 * Enable debug output
 * */
settings.debug.output = true;

module.exports = settings;

nodejshelper_config

[== PHP ==]
<?php 
	$nodeJsHelperSettings = array (
		'prefix' => 'https://',
		'host' => 'example.com',
		'port' => ':31129',
	    'path' => '',
		'secure' => false,
		'use_cdn' => true,	// Should we use google provided socket.io.js library?, if you are using older version set it to false
		'use_publish_notifications' => true,
		'redis' => array (
					'scheme' => 'tcp',
					'host'   => '127.0.0.1',
					'port'   => 6379,
		),
		//'instance_id' => 0, // Set erLhcoreClassInstance::getInstance()->id for automated hosting extension support
		'instance_id'=> erLhcoreClassInstance::getInstance()->id
	);
?>


On the main web site that is working

var nodejshelperHostConnect = 'example.com:31129';var nodejshelperConfig = {use_publish_notifications:true,instance_id:'',path:'',secure:false,'typer':'','sync':true,'synctimeout':5};


What I have tried:
copying the extension folder for nodejshelper over to the extension folder in the client installation of LHC.
updating the settings.ini in the client installation to include nodejshelper.
clearing the cache
changed the nodehelperjs nodejshelper_config to use: 'instance_id'=> erLhcoreClassInstance::getInstance()->id  (I noticed that in the main web site it has instance_id:''  )

Is there a missing step in the instructions like updating the extension tables or something else?

Last edited by devman (2015-07-21 19:08:26)

Offline

#2 2015-07-22 06:08:23

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: NodejsHelper with automated hosting

1. Extension have to be configured in client instance, not manager.
2. To clear cache for client instance you have to clear cache using command line.
3. Everything else seems ok

Offline

#3 2015-07-22 07:42:55

devman
Member
Registered: 2014-09-20
Posts: 76

Re: NodejsHelper with automated hosting

I think I have the extension configured in the client instance. 
The extension folder was copied over with the same settings from the manager.
Node is running the server from the manager, but it would be the same if run from the client, right?
The clients have the settings.ini configured for the nodejshelper:

'extensions' => 
		  array (
			'nodejshelper',
			'instancecustomeroverride',
			'instancecustomer',
		  ),


I cleared the cache in the client folder one more time with :  php cron.php -s site_admin -c cron/util/clear_cache
And I cleared the browser cache for the web site for one of the instances.

Seems to be working ok now for the clients too!

I also adjusted nodejshelper_config so the instance_id in the manager uses  =>0 and the nodejshelper_config in the clients uses erLhcoreClassInstance::getInstance()->id

The correct instance ids are now displaying on the node console.

Last steps are to turn off debug and set up node as a service.

One more question:   what is the 'secure' setting for in nodejshelper_config (I don't see it used in the server.js)?
I have node set up to use ssl.  Do I need to set 'secure' to true?

Thanks!

Offline

#4 2015-07-22 07:47:35

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: NodejsHelper with automated hosting

It's used only if nodejs is runnign https mode, this is happening then nodejs is running under nginx as proxy. And nginx itself is https. This setting effects only browser connects to nodejs

Offline

#5 2015-07-23 23:18:57

devman
Member
Registered: 2014-09-20
Posts: 76

Re: NodejsHelper with automated hosting

Once I tested the configuration with node handling the traffic directly, I reconfigured it to use nginx as a proxy with ssl.  Also updated the ulimit to 40000 (googled how to do it), updated the calls to sockect.io cdn for the browser to 1.3.6 (to match the version installed), installed forever and ran it from Upstart so it loads at boot.  Everything seems to be working.  The only issues seem to be: IE 11 looks like it sticks to 'polling' instead of upgrading to a websocket; and if the node server is stopped the browsers get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when making the XMLHttpRequest.  Not sure what is going on with the first issue regarding IE,  but I think the second item is an nginx configuration (not sure if it is web site or LHC server issue yet; the errors stop as soon as node server is restarted).   The chats still work when the node server is stopped. 

To clarify the instructions for automated hosting, perhaps you could add a note on adding the extension to the client copy of LHC, changing the instance_id to use 'erLhcoreClassInstance::getInstance()->id' only in nodejshelper_config.php in the client copy, and clearing the cache for the clients via the command line.  Much of this was not clear when doing the initial install and not all of us are as familiar with LHC as you are :-).


Thank you for the help!

Offline

#6 2015-07-24 04:42:51

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: NodejsHelper with automated hosting

As for nodejs if it dies and polling stuff. Basically in my own enviroment i have cronjob which every day restarts nodejs server. I'm stlll don't know the reason it sometimes just dies or starts consuming to much memory or in general just does not accepts any connections.

Offline

Board footer