Jenkins won't kill node.exe? - node.js

I've got a Jenkins job set up to run a node.js server in the background, perform some tests on it (through a batch script, using Nightwatch), and then kill off the node server using the TaskKill batch command. Here's the command line script I have for the build:
START /B node ../app.js
runtests.bat
taskkill /F /IM node.exe
The build runs and passes, but it never seems to kill node. At the end of the console output I get:
Process leaked file descriptors. See https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors for more information
And I can see the node.exe process still running in my Task Manager.
If I run the same commands in my own command prompt it works fine, and kills node. It's just that Jenkins doesn't seem to execute that last command at all.
Any ideas? Am I maybe taking the wrong approach altogether?

Well I managed to get it working by installing the Hudson Post Build Task plugin, and just killing node in a post-build command. Still not sure why it wasn't working before though.

Related

npm ping is opening command prompt windows

I want to ping certain IPs in a project, and I am using npm ping package for this.
https://www.npmjs.com/package/ping
When I run the service, its running fine. But when is run my service in the PM2, the command prompt windows are showing up, each time the ping action is done in that service(I am pinging in loops to monitor an IP).
What is the reason for this and please suggest an alternative solution.
The same problem happened to me while using forever to run my script in background.
I've found that using START /B node script.js on windows instead of forever worked just fine and the command prompt didn't showed up. I don't know much about PM2 but maybe you should be able to prefix your command with START /B somewhere in PM2 or just run your script by yourself.

Starting node js application using grunt on machine start up

I am new to both linux and Node js basically we have developed Node js application in Windows and I need to deploy it on Debian 8 Jessie and I am able to deploy it on linux and for this I need to install npm, node js, grunt cli etc.
And to run my application I just need to type grunt using terminal and application starts.
But the problem I need to start server every time after reboot of system by typing grunt in terminal.
So need solution how can I start my application/server on machine start.
Also let me know how this stuff works!!.
Thanks
as always there is more than one way
rc.local
the prefered way. rc.local will be executed on system startup.
to edit the file use your favourite text-editor (e.g. nano) nano /etc/rc.local and add your script before the last line containing exit 0
/usr/bin/myscript -arg1 -arg2
exit 0
cronjob
if there is also the need for recurring tasks (e.g a daily backup), cronjob could be a good choice to keep things together.
Within your terminal type sudo crontab -e to edit your cronjobs.
there add your command with the #reboot time argument.
#reboot /usr/bin/myscript -arg1 -arg2

View nodejs running scripts

Im using nightwatch and cucumberjs to make automated tests. After the execution I send a mail report of the status of the tests, but sometimes, when the tests completes it get stuck and doesnt send the mail report. I believe there is something inside my tests that doesn't close correctly but I don't know how I can see what is still running.
How can I display a list of the current processes that are still executing?
EDIT: Sorry for the confusion, by processes, I mean inside my nodejs program, not windows process
Linux:
Open termial.
Run the top command.
Windows:
Open task manager.
View running processes.
For Linux -
ps -ef | grep node
This will match all the processes with keyword node in it.
You can replace node with appropriate process name.
For Windows -
tasklist | FIND "node"

Daemonize a perl script at startup Linux

I have a custom version of CENTOS that I need to run a perl script as a daemon in at all times.
To do this I want to get it to run on startup as a daemon.
When the machine is on I can daemonize the script with the command
daemonize /var/myfolder/myscript.pl
And this works fine.
So I have an rc1 script which has a number of commands that run when the machine starts, and the very last line in it is where I try to daemonize that script. Everything else in the rc1 script runs fine, and the script doesn't output any errors, however when I check to see if the daemon is running on start up, it isn't running.
Is there another way that I can get the script to run on startup? Or any ideas on why this method doesn't work?
Proc::Daemon offers what you're looking for.
See this previously asked question: How can I run a Perl script as a system daemon in linux?
The problem was that #INC hadn't fully loaded all of the modules by the time my script was called, and so my daemon wasn't running. I used the PERL5LIB command to add the appropriate directories.
PERL5LIB='/perl:/custom/lib:/usr/local/lib64/perl5' /var/myfolder/myscript.pl &
where /perl; /custom/lib and /usr/local/lib64/perl5 are the directories which were missing from #INC

Linux Invoke custom script during OS shutdown

I wrote a simple JAVA application which runs as a service. When my application is up and running, I maintain the PID in a file which will be used while stopping the application.
Issue:
When I restart the OS the stop script is not called (not sure how to make this happen) and the old PID is left as it is in the PID file. Now, after reboot (which start my app) when I stop the app using stop script now my stop script will try to clean up all the PID listed in the file. Most of the time, I will get "No such process". But there are chance the same PID might have been used for some other process
Question:
How I can make sure my stop script will be invoked when I shutdown ore reboot the OS? I am looking a solution for RHEL environment.
I think your are looking for a init script. (startup/shutdown services at different run levels)
This is a good reference
http://blog.rimuhosting.com/2009/09/30/one-java-init-script/
this has a good refernce to Linux init.d scripts
http://coreymaynard.com/blog/creating-a-custom-initd-script-on-fedora/
Hope it helps
If you are looking for scripts that run after reboot, I guess you can write the script in /etc/rc.local and then you can start your service.
This script will run after all your init scripts have run while your machine starts. Using this you can delete the old PID file.

Resources