LowPowerLab Forum

Software support => Pi Gateway => Topic started by: HeneryH on October 28, 2015, 11:24:32 PM

Title: Easiest way to restart gateway.js (for code changes) ?
Post by: HeneryH on October 28, 2015, 11:24:32 PM
New to node js.

Rebooting the whole pi seems like overkill.  How do you get the system to notice changes to gateway.js? 

Reload the browser?  Nothing, it is automatic?
Title: Re: What is the easiest way to restart gateway?
Post by: Felix on October 29, 2015, 09:47:10 AM
It's not automatic.
Log in your pi, do a pkill node, that kills the gateway.js process. If you're using my image the gateway.js process will automatically be restarted by the process monitor.
Perhaps I should look into a way to do a "gateway process restart" right from the UI...
Title: Re: What is the easiest way to restart gateway?
Post by: HeneryH on October 29, 2015, 01:58:14 PM
Quote from: Felix on October 29, 2015, 09:47:10 AM
It's not automatic.
Log in your pi, do a pkill node, that kills the gateway.js process. If you're using my image the gateway.js process will automatically be restarted by the process monitor.
Perhaps I should look into a way to do a "gateway process restart" right from the UI...

Automatic restart would be a very low priority in my opinion.  So long as I know how to do it from the ssh :)

Rebooting for every code change is a waste. 

Thanks
Joe
Title: Re: What is the easiest way to restart gateway?
Post by: Felix on October 29, 2015, 03:01:58 PM
Quote from: HeneryH on October 29, 2015, 01:58:14 PM
Quote from: Felix on October 29, 2015, 09:47:10 AM
It's not automatic.
Log in your pi, do a pkill node, that kills the gateway.js process. If you're using my image the gateway.js process will automatically be restarted by the process monitor.
Perhaps I should look into a way to do a "gateway process restart" right from the UI...
Rebooting for every code change is a waste. 
Definitely, I always just run pkill node when I am working on code changes, the process monitor is great for restarting gateway.js automatically.
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: Sergegsx on October 29, 2015, 04:28:00 PM
 Felix, any place I can read more about this process monitor and how it works and the code behind it?

Thanks a lot
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: detroit_johnny on October 29, 2015, 06:40:04 PM
I figured out I could use sudo stop gateway from the command line followed by a few seconds later typing sudo start gateway but instead just using pkill node sounds a lot faster!!  Thanks all!
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: Felix on October 29, 2015, 07:05:22 PM
Quote from: Sergegsx on October 29, 2015, 04:28:00 PM
Felix, any place I can read more about this process monitor and how it works and the code behind it?
It's called upstart (http://upstart.ubuntu.com/cookbook/), I wrote about adding this in this blog post (http://lowpowerlab.com/blog/2015/08/27/gateway-log-engine-upgrade/).
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: jkarras on November 04, 2015, 09:46:43 PM
A simple way to auto restart while developing is to use the node.js application nodemon (http://nodemon.io/). It monitors the files for changes and auto restarts the application upon change.
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: Felix on November 05, 2015, 09:17:49 AM
Quote from: jkarras on November 04, 2015, 09:46:43 PM
A simple way to auto restart while developing is to use the node.js application nodemon (http://nodemon.io/). It monitors the files for changes and auto restarts the application upon change.
Nice suggestion, thanks. In my searches for a solution i stumbled upon nodemon but I didn't try it, perhaps I should. What I really needed was a solution that would start the script at boot and also restart it in case it dies, so that also acts as a process monitor when the script is stopped manually.
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: jkarras on November 05, 2015, 09:34:06 PM
Nodemon can be used in that fashion to a degree. One option to look at is monit (https://mmonit.com/monit/).

Why the desire to move away from the built in process managers in Ubuntu and the like?
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: Felix on November 05, 2015, 10:14:08 PM
Quote from: jkarras on November 05, 2015, 09:34:06 PM
Why the desire to move away from the built in process managers in Ubuntu and the like?

Is lack of expertise in Linux a good reason?  ;D
If you have a native solution that is always the best over 3rd party tools. Is monit one of them natives?
Title: Re: Easiest way to restart gateway.js (for code changes) ?
Post by: jkarras on November 10, 2015, 01:11:24 AM
Quote from: Felix on November 05, 2015, 10:14:08 PM
If you have a native solution that is always the best over 3rd party tools. Is monit one of them natives?

Monit is a 3rd party app. Nice thing about it is that you can tell it to monitor more than just the process. Check for an open port or other such things.

That said if you just want a simple startup script i'd just stick with a upstart/systemd what ever your distro of choice uses. Because then you can tie the startup of nginx and other dependencies to your script natively.