Simple perl multithreading for Alien::SeleniumRC - multithreading

Alien::SeleniumRC says about its start method that "This call will block until the server is killed."
I'd like to use it to start the Selenium server, run some Selenium tests, then shut down the Selenium server--all from a single perl script. What's the simplest clean way of achieving this? (By clean I mean that if something goes wrong, it will shut down the Selenium server on the way out so it doesn't need to be shut down manually.)

Related

What is the correct way to start and stop simple Node.js scripts

I'm trying to create a simple Twitter bot to learn some Node.js skills.
It works fine on my local computer. I start the script with node bot.js and then close it with Ctrl + C.
I've uploaded the files to a server (Krystal hosting). I've ssh'd into the server and then used $ source /home/[username]/nodevenv/twitterbot/10/bin/activate. Which I think puts me into a Node environment (I'm not really clear what is happening here).
From here I can run node bot.js. My Twitter bot runs fine and I can leave the terminal. What I've realised now is that I don't know how to stop this script.
Can someone explain how I should be doing this? Is there a command I can enter to stop the original bot.js process? Since looking into this it looks like perhaps I should have used something like pm2 process manager. Is this correct?
Any pointers would be much appreciated.
Thanks,
B
You can kill it externally by nuking the process from an OS command line or in an OS GUI (exact procedure varies by OS). Ctrl-C from the shell is one version of this, but it can be done without the command shell that it was started in too by nuking the process directly.
Or, you can add a control port (a simple little http server running on a port only accessible locally) that accepts commands that let you do all sorts of things with the server such as extract statistics, shut it down, change the configuration, tell it to clear caches so content updates take effect immediately, etc... Shutting down the server this way allows for a more orderly shut-down from code within the server. You can even stop accepting incoming connections, but wait for existing http connections to complete before shutting down, close databases normally, etc...
Or, you can use a monitoring program such as PM2 or forever that in addition to restarting the server automatically if it should ever crash, they also offer commands for shutting it down too (which will just send it certain signals kind of like Ctrl-C does).

How to cancel build automatically upon Sublime Text 3 exit?

Is there a way to ensure build is automatically cancelled upon ST3 exit if I forgot to manually do so? This is especially important for long-running tasks such as a live-update nodejs process for react webpack development in my case. Without it, I found nodejs process will continue listen on the port, preventing same build from launching later, at least on Windows.
I'm not entirely sure if this approach will work with node.js, but if I have a Python script that is taking too long or has reached an infinite loop I will cancel the Python task in Task Manager. Try looking for a node.js task and see if that works.

How to run another node.js script and then kill it

I want my testing script to be able to run my server and then kill it at the end of testing. In fact I will probably want to do this mulitple times in the testing script. I tired exec with shelljs. But that seems to me from running any commands after I start my server for testing it also seems like it would be hard to find the sever to kill it after starting it (especially on different OSes). How might I do such a thing?
On different OS you will need to find processId to kill it. This is tedious and not recommended process.
Use a wrapper around like pm2 or nodemon for servers.
In testing case you can make use of process.exit(0) and expose it in your make code.

Is there a way to tell what is keeping a node.js program alive?

I have a node.js program that's hanging after completing everything I want it to do. I'm fairly certain it is an open connection somewhere that is keeping the program from exiting. Is there a way to tell/debug what is keeping the program from exiting?
Unnecessary edit: This question is in no way similar to my question: How do I debug Node.js applications? . Thanks for playing tho..
There is an npm module Why is node running module which helps in "Node is running but you don't know why?"

Monitor starting/running/ending apps within node.js

Is there a way to monitor starting/running/ending apps within node.js?
Like "You just started LibreOffice Writer!".
It would be nice if any of you cracks could help me with this.
Edit:
I am searching for something that runs in the background and is triggered whenever I run a random application/script/whatever has a system-wide pid.
forever is a daemon manager for node.js that can do this.
http://thechangelog.com/post/6637623247/forever-node-js-daemon-manager
https://github.com/indexzero/forever
Or if you just want to start a process once and be able to manage it, you can use the builtin ChildProcess.
http://nodejs.org/docs/v0.4.9/api/child_processes.html

Resources