I am new to Azure batch. I am working in windows environment.
My requirement is, a node js server should be running before any batch task runs on machine.
I have tried to start the node server in job preparation task as well as pool start task with following task command line statement
cmd /c start node.exe my_js_file.js
But as soon as start task completes , Node server running on machine dies.
If I do not use start in above command , node server starts and keeps running but start task also keeps running and never completes.
What can I do to start node js server in background in azure batch.
I have also tried to start node server when a new task executes (which is a command line application). But as soon as task completes, node process also gets killed.
0
votes
1 Answers
0
votes
In order create a detached process that runs forever, you have two options. Either option can be done from a job prep task or a start task, but be warned that if you have multiple jobs requiring the same node.js server context to start, you may encounter errors. Please ensure that if utilizing this at the job-level, that you specify a job release task that kills the long running process correctly. Also be aware that if you allow multiple tasks to be co-scheduled on the same node, that there can be interaction conflicts if they require the same long-lived process.
- The recommended way is to install a Windows service that runs your command. There are various ways to bootstrap a service, including use the commandline sc program or the myriad of helper programs to do this on your behalf.
- If you do not want to (or cannot) install a Windows service, you can create a C++ program that invokes your command as a "breakaway process." Please consult the MSDN CreateProcess documentation and ensure that you specify the
CREATE_BREAKAWAY_FROM_JOBflag fordwCreationFlags. This task must be run with elevated (administrator) privileges. It's also recommended that you start your process in a folder outside of the startup task working directory that is default (such that compute node restarts don't affect possible files that you may generate in the current working directory).