PM2 watch & reload, but only reload when script is not actively running - node.js

I have a PM2 instance (currently without watch & reload) that I would like to have reloaded only when the script, or any of its functions are not running. Essentially, I have a long-running function that can last 10 minutes or so, and if I auto reload from a file change (eg: a git pull), the script will halt upon reload of the instance.
So essentially, I'm trying to figure out how to only reload if there's no app activity.
Open to thoughts. I've seen a few similar cases after Googling, but I'm unable to find something for this exact scenario.

Related

how can I run gatsby serve as a service in centos?

or is there a third framework to deploy it? Now I use gatsby serve to run it in centos, but the server shuts down after I exit console window.
Generally for this sort of thing there are a few ways to do it, among which are:
the simplest one is appending an & after the command and running disown before exiting your terminal session, & makes it so that the process runs in the background and disown separates the process from it's parent so that it doesn't close when you exit. If you use this method I would recommend forwarding the output of the command to a file so that you can later review it after your session has closed, for example gatsby serve & > access.log
a better solution is using programs such as screen or tmux which create a terminal session that can be "closed" and reopened after, please take a look at the linked man page, or run man screen (or man tmux) on your system to see how to use them as this is beyond the scope of this question.
The best solution however is however something integrated in gatsby: the build command. This generates a standalone node.js application that can be deployed on a remote server, you would build your application and setup a server such as nginx for this

Python Plotly's Dash: How do you shut the web app running on a port or make changes to it? CTRL+C doesn't seem to be working

Am using Plotly's Dash and trying to run the sample app code which they have provided here: https://plot.ly/dash/getting-started#dash-app-layout
Am having trouble with the ports. The code on being run shows this in the console:
However , even after making changes to the code, the output in the web app shows no change.
Basically, when I'm implementing a different code: the web app continues to display the output from the previous run!
The CTRL+C doesn't seem to help and doesn't really quit or cause any change to the application. Please let me know what shall help.
I ran the new code using a new port(8049) and that worked but doesn't solve the initial basic issue!
I've had the same issues, and find that a full restart of the app is necessary to get some changes to propagate in the app after a file update.
In POSIX, you could run sudo killall python or similar. Looks like you're running Windows, so taskmanager or taskkill /F /IM python.exe.
The [1]: Looks like a Jupyter kernel is running? If so, try restarting the kernel.
For me CTRL+C doesn't work either, but CTRL+Pause/Break button stops execution.

How to Save Images from A Program Ran from Ubuntu Application Start-up Command

We're trying to run a program at start with Ubuntu's Application Start-up command. We're successfully starting the camera and viewing the images. But the images are not saving to the folder we expect them to be saved too.
The program works flawlessly when started manually from the terminal. Saving into the appropriate folder.
Does anyone have any idea of how to get the images saved but when started from the Application Start-up command upon start-up?
Thanks.
You're not providing a whole lot of details, so my answer may be totally off. To me it sounds like you've created an app that takes a picture with the webcam and saves it to disk. Now you want the app run it when the user logs in, so you've added your app to the list of Startup Applications. The app starts, takes a picture, but can't write it do disk. If that's the case, I'd consider:
Try adding debug logging to your app, so you can see why it fails opening the file. What ever language this app is written in, if opening a file fails, the API will tell you. This information is vital. The easiest is to print to stdout and then, when starting the app, forward it to a log .e.g. /usr/local/bin/myapp &>> /tmp/myapp.log.
Try writing to a location like /tmp where permissions aren't that much of an issue.
Try adding a delay before starting the app, see this list of various approaches on how to do this, the most simple being using this a the command: sleep 10 ; /usr/local/bin/myapp &>> /tmp/myapp.log
If this is all rubbish you need to add more details in your question.

Can't kill NodeJS app

One day, out of nothing, my app decided not to die.
After pressing ctrl + c when I inspect port it's still there and not only on my machine but also on server that is managed by PM2 so I need to go there each time and kill the process by hand. I tried to look for issues in my code and when I couldn't I just though that it's simply one of the dependencies fault and soon there will be a fix. It was slightly annoying but I could kill the process with kill -9 PID and I had most of the tasks I had on front-end side so it wasn't that big issue. Today, more than a week later problem it's still here.
I went back in history, picked a commit that I made weeks ago, where everything worked perfectly fine, switched NodeJS from 5.1.0 to 4.2.1, cleared npm cache, reinstalled all dependencies and I still see the problem.
I'm using LoopbackJS, but normally I start the app simply with "node server/server.js" and then the problem described above happens, but if I use "slc run" and then try to kill the app with ctrl + c it just hangs forever, I mean I can press ctrl+c as many times as I want and it's still running in console foreground.
If instead of pressing ctrl+c I kill the tab in console, app dies without problems.
This is what I see after running "lsof -i tcp:4000" when the app is supposed to be dead but is not
Edit:
Running and killing it with Strongloop process manager - slc start/slc stop works fine but it would be more convenient to use normal way of running NodeJS app (node server.js) during development and it doesn't change the fact that there is some issue and it would be better to not hide it under the carpet.
Out of anger I stripped out my app to the most basic elements. File by file, piece by piece and I found the answer.
The culprit was phantomJS - https://github.com/sgentle/phantomjs-node. PATCH version 0.8.2 introduced this bug. Fix was created almost a month ago, merged a week ago but not published on npm yet.

How to keep a Karma server running, but not run tests only until I manually tell it to?

I would like run Karma without having to shut down the server on every single run. I know that you can turn off single run and have watch running. However, I don't want my tests to re-run on every single save and would like to trigger them manually.
Is it possible to keep a live Karma server but prevent it from running my tests on every single save?
Figured it out. I can turn autoWatch in the config file, which I knew how to do before. After that, if you are running tests through Chrome, you can simply refresh the debug page.

Resources