NSSM service not executing batch script but was created and starts successfully - windows

I want to automatically start my node server on the VM's reboot using the following batch script
#echo off
cd /D c:/Application Services/servers/dashboard/server
echo Starting Dashboard Server In Production: port 8446
npm run prod
the "prod" script is defined as
"prod": "set PORT=8446&&set NODE_ENV=production&&node --no-warnings ./bin/www"
When run on it's own, the batch script works and localhost:8446 gives a response
When I start the service I created with NSSM the script doesn't seem to run here's how I created the service
nssm install DashboardService
The GUI popped up and I selected the path to the batch file
The service installed and started successfully but localhost:8446 didn't give back a response indicating to me that the service didn't execute the batch script
There's another service that is just like this one already on my system and I checked to make sure my service was set up the exact same way. I changed my service to execute the batch script the working service was executing and my service successfully ran that batch script so it's not a problem with nssm or the service manager but with the batch script.
I based my batch script off the working:
#echo off
cd /D c:/IOEServices/node-servers
echo Starting GraphQL Server
node src/index.js
So my question is, why isn't the batch script executing when prompted by services and starting the node server?

Related

How to run a bat script on multiple windows servers at once?

I am trying to run a .bat script that uninstall 32/64 bit agents and re-install 64-bit agents on almost 100 window servers.
Can you please guide me how this can be done?
I already tried running for one server to test
psexec \\<windows server> -u <username> -p <password> <command>
But fails with error
COULD NOT START PSEXESVC service on <windows server>
Do we need such service on all machines? Please suggest any other way?
PSEXEC is not a standard windows feature /service.
If you wish to use PS Exec you will need to install it on all of the relevant systems first.
Otherwise, your options are:
CMD:
A) Does the "Agent" Installer you are using allow you to install / uninstall to a given server in it's command line syntax?
If so utilize that.
B) Put the Installer in central location (the Active Directory Netlogon Folder is great for this) along with a CMD script to run the uninstall and install processes.
Then Use SCHTasks to connect to each server and create a Scheduled task that runs using an administrative Username and password for that server, and set it to run with the highest privileges, set the action to be the path to the CMD script in netlogon that you have previously tested and nwo is working, set the task to run 1 minute in the future, or on demand (If on demand you then run schtasks again to execute the task).
Powershell:
Work on getting a working CMD Script to run and use Invoke Command to run that command script on the remote systems. As in Option B from CMD options you can keep the CMD script and Agent installer in the netlogon folder.

NSSM: Can't edit a service I created

I am using NSSM to create a service, however, after creation I need to set some parameters, such as AppDirectory, AppNoConsole, etc.
I am able to create the service using the GUI, but I want to do it via cmd, for which I have a batch file that goes like this:
nssm install MyService "%Java_Exe_Path%" "-Xmx1024M -classpath \bin\start.jar;\lib\*;. com.myapp.class.subclass start"
nssm set MyService AppDirectory "%DIR%"
nssm set MyService AppNoConsole 1
Thing is I am getting errors that read:
Can't open service! OpenService(): Access is denied.
Or
OpenService(): The specified service does not exist as an installed service.
Notes: When I run the cmd file I get asked for admin rights (guessing to run the install), but to edit (set) I am not being requested permissions, neither I get asked permissions if I run the set command directly via commandline (also getting an error of access denied).
Can anyone help?
Thanks!
Got the same problem, my solution is always run this script as an administrator:
How to request Administrator access inside a batch file

Execute exe-file over ssh from Jenkins

I'm having a issue with CI where after i deployed a build i can't get the new version to start. In Jenkins the console output just keeps spinning when it hit the part of the batch file to start the exe-file and then times out.
I have tried both to run it inside the batch file and from the SSH command line but i can't get it to start on our Windows server.
Any suggestions?

How to see opened cmd running at batch script when it is scheduled to run using windows scheduler

I've written batch script and added that in windows scheduler service.
It runs fine and I can access my deployed app which I'm deploying using that service but I want command promote to get open and see that command running when that service is in progress.
How to do that?

Running a batch file from Jenkins hangs and does not return to the Jenkins job

I am using the "Send files or execute commands over SSH after the build runs" option in my Jenkins job configuration. I am running a .bat file on a remote server. The .bat file is starting an authentication server. The authentication server needs to remain up and running on the remote server.
The authentication server is delivered with a .bat file to start and stop the server. When I run the delivered .bat file my jenkins job hangs and never completes. The delivered .bat file named startAuth.bat looks like this:
call java -jar Auth.jar db migrate Auth.yml
call java -jar Auth.jar server Auth.yml
Based on some end user restrictions, I cannot modify the startAuth.bat file, so I have create another .bat file to call startAuth.bat named runStartAuth.bat. It looks like this:
cd c:\tmp
start runStartAuth.bat
exit /b
My thinking was by using "start" the .bat should be run in a separate process, one that could remain up and running until the next Jenkins job run, and the calling .bat would exit with the exit /b line. Unfortunately, the Jenkins job seems to ignore the exit and just spins and spins.
What am I doing wrong?
I'm not really an expert with Jenkins ... but I think since the slave agent JVM wrapper over your batch file knows that the child process has not yet finished, it will not return control to the executor.
Instead, can you try having the same commands on the Jenkins slave node configuration ? I believe you will have slave launcher prefix command in the Advanced section of the slave node.

Resources