I'm using Kubernete to run a node script in a permanent loop. When the pod is created, it runs "npm start" which start the script with default parameters in loop mode.
It works perfectly for that.
I also sometimes need to run some node commands in the pod.
(eg: node dist/index run --parameter=xyz)
For that I use kubectl :
kubectl exec -it PODNAME NAMESPACE --
/bin/ash
It allows me to run the script with other parameters as I wish BUT
I don't find a way to put the main process ('npm start') on hold while I run my others commands.
I want the loop to be paused while I execute those node commands (They can't run in parallel). I tried to kill the main processed which are shown by typing "ps -aef" but it doesn't work. It either restart automatically (restartPolicy: Always) or it make the pods go in error and I can't type my node commands.
Any idea on how to achieve this ?
What you could do is send a signal to the main process, SIGUSR2 is meant for this kind of purpose. You can catch the signal with an event handler and set a variable, then let your normal code check the variable at intervals or at set points in the code to judge wether it should do stuff.
On the CLI side of issuing the pause you can simply use the kill command to send the signal to the process.
See also:
https://nodejs.org/api/process.html#process_signal_events
http://man7.org/linux/man-pages/man7/signal.7.html
how to use kill SIGUSR2 in bash?
But, maybe you shouldn't try to pause a pod, simply gracefully let it shut down, and pick up remaining workloads later, in a new pod? Would probably be a cleaner way to go about it, but depends on what you're trying to achieve ofcourse.
Related
I'm working with HTMLhint but it just run with the command line is a plugin, I want this action to run like a test. Is it possible do it and how? I was googling but I don't find a way to do that.
Do you mean you'd like it to run every time you push code? Or, would you like it to run locally in your editor every time you save/as you type?
Every time you push code: look into TravisCI or another type of continuous integration. These services can run items on your code, including linters, each time you push new commits.
Every time you save/as you type: this depends on what your editor requires to run the lint. For example, Sublime Text has Sublime Linter which can automatically run any type of linter after installation of the corresponding package.
I grep the karma repository and it seems like no logic is using that field besides simply being set in the config.
Does anyone know what is that field for?
For some reason I have to set it to 20000 or else my karma test Disconnects
It's referenced as noActivityTimeout internally, in this file:
https://github.com/karma-runner/karma/blob/de55bc63205c656eb5f5534894aa4ae92228efb8/lib/browser.js
Basically, the effect of the line is supposed to be that the test stops running if no activity is detected in the amount of time specified by the config. This helps the tests stop when your code is in an infinite loop or otherwise not responding (maybe it has an async test condition and the test never resolves)
I have a EC2 instance, and I would like to write a script (never done them before) so that every time I start my E2 instance in the AWS console, the following files are run automatically.
Lets say I have a file called example.js which contains this:
var test(){
console.log('hello world');
}
test()
And then I have a similar file called example2.js
Everytime I run my EC2 instance, I need to ssh into it and do node example.js and node example2.js in order to run the functions.
However, I would like to write a startup script so that when the EC2 instance state is turned to running (i.e. online), I would like the command node example.js and node example2.js executed by themselves.
Is this possible? If yes, where do I put this script?
I have a Centos image running on my EC2 instance, and the EC2 instance is turned off at night, and turned back on in the morning - hence the script will simplify things!
I read this link, however cannot quite figure it out in my case: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
Any help will be appreciated. Thanks
use pm2. It's an excellent solution for managing node processes. Also can start the processes when you boot the machine.
ref: http://pm2.keymetrics.io/docs/usage/startup/
here is another good tutorials: https://futurestud.io/tutorials/pm2-restart-processes-after-system-reboot
Specific to EC2, you can use the 'User Data' option, available when you create your instance. It takes a script as input that will be executed at launch.
Here's how it looks like :
To add user data to your instance, wait until the night so you don't disrupt yor apps, then right click on it and do "Create Image".
Once the image is created, you can use it to spawn a "new" instance, with user data, and delete the old one without losing anything. Don't forget to reassign the elastic IP of the old instance :)
More information/documentation on aws.amazon.com
Fatal Windows exception, code 0xc0000005.
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
This error pops up randomly when I am recursively opening a new page using casperJS. It's not all that random, it shows up after a couple of iterations (maybe around 50).
I don't think it's a memory leak, because I am monitoring the memory usage while running the script, and have closed all the heavy memory applications.
I've seen people reporting this issue on github, but I don't think it has a fix yet.
Is there a way I can let my machine to rerun Casper script after it detects a crash? (i.e. auto run $casperjs run.js after it detects the crash)
I was thinking to use shell script to do this, but not sure exactly how to detect the crash.
Of course, any ideas on fixing this crash would be good too.
Not sure if this helps, but I am putting my Casper code here too:
var runCasper = function(){
casper.start('https://www.example.com', function() {
// Do something
});
casper.then(function() {
// Do something
runCasper();
});
casper.run();
}
One thing you can try is keep checking if the casper/phantom process is running. you can do this by writing a status file at the start and end of each run. Check out https://stackoverflow.com/a/15283576/2231632 for using filesystem within casper. Code snippted from that answer:
var fs = require('fs');
var utils = require('utils');
var data = fs.read('testdata.dat');
utils.dump(data);
And then add a shell script that frequently reads this file and if a particular process is in 'running' phase for over 10 minutes or so, you can re-run casper from the shell script.
Ideally, every recursion should have a exit condition and you can't keep on recursing forever. What is it that you want to achieve by recursively opening the same page again and again?
I have a test file on a remote machine and I want to walk through it with node-inspector. So, on the remote machine (Vagrantfile):
node-inspector &
mocha --debug-brk foo.test.js
Then, on my dev machine I open Canary and go to:
http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858
However, I'm not able to debug my test, since the debugger will break at the first line in node_modules/mocha/bin/_mocha, and my test file isn't visible in the Sources tab:
I tried setting a breakpoint inside _mocha, on line 398:
runner = mocha.run(program.exit ? exit : exitLater);
But when I try to 'step into', to see the run function execute, it doesn't step in. I can see output in the console, so it does execute though. If I set a breakpoint directly in the run function, it won't break there.
Also, the test file never appears in the "Sources" tab so I can't set breakpoints in it. I also tried adding a debugger statement to it but it still doesn't break there.
How can I make node-inspector show the test file, and step through it ?
node v0.12.0
node-inspector v0.10.0
mocha v2.2.4
I frequently run into this, and I don't know if there's a better solution (if there is I'll be glad to hear it), but I find I have to let the debugger advance to a point where it becomes aware of the additional files I want to debug. Without seeing more of your code I can't give a more specific suggestion about where to advance to, but try to figure out where the test files will be loaded in the source files that are available and advance to there. It'll gradually add more files to the Sources panel as code runs.
There are actually 2 problems:
breakpoints not respected
test files not visible
The first problem was fixed in the recently released node-inspector#v0.10.1. So, breakpoints will be respected anywhere.
There is still the second issue. As #JMM said, the list of files in the 'Sources' tab is dynamic, and test files won't appear there when the process breaks. What I ended up doing is setting a breakpoint just before the test function is run, in mocha/lib/runnable.js#266, on this line:
var result = fn.call(ctx);
fn is the test function. Once you step into it, the test file will appear in the Sources tab and the debugger's cursor will be on the first line of the test function.