Every morning when i restart Azure VM then i want to run batch file automatically.
This batch file is starting selenium grid. So what i did is added Task scheduler and created trigger to start script at Startup.
Then i tried to run the task manually but it doesnt do anything.
Although it may not be mandatory to paste code for batch file but still here it is
cmd /C start/MIN java -jar selenium-server-standalone-3.141.59.jar -role hub -port 4445
cmd /C start/MIN java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://localhost:4445/grid/register
I have windows server 2012. When i manually click batch file then it run but not working via startup script
You can add the batch file to system registry
to execute if any user log in: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
to execute if only current user log in: [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
or
[HKEY_LOCAL_MACHINE\SOFTWARE\wow6432node\Microsoft\Windows\CurrentVersion\Run]
[HKEY_CURRENT_USER\SOFTWARE\wow6432node\Microsoft\Windows\CurrentVersion\Run]
Related
I launch the Node apps using the json file with pm2 using the command line pm2 start pm2.json and it always launched without any issues. However, I wanted to launch it via the Windows Service. So I created a run.bat in the same folder where my pm2.json is present
and added the same command line pm2 start pm2.json in the run.bat. Then I used nssm.exe to set the run.bat as Windows Service. However, it always shows its status as Paused and never started the apps.
The event viewer shows the logs that the run.bat existed with 1:
However, it still works fine using the command line pm2 start pm2.json
How to start the command line pm2 start pm2.json through the Windows Service?
I have setup auto scaling policy to launch an windows 2016 AMI EC2 instance once certain thresholds are crossed.
After windows is booted up, I want to open command prompt, change to a particular directory and start my node http server.
I have specified the following command in user data while setting up launch configuration.
start cmd /k cd c:\pizza-luvrs-master|npm start
My instances are getting launched but the commands are not getting executed!
the problem is in lauching command window itself. rest of the command is fine.
any solutions?
Assuming that the image you use in your auto scaling group is working correctly, you can copy your command into a .cmd file and then add it to the Task Scheduler. You should set the trigger to "At Startup".
I wish to know how can I schedule a custom script to run whenever I restart a service.
My use case is that I have to run several commands whenever I restart my Tomcat Service. I want to know if there is a way I can write a script and schedule it to run whenever I restart the Tomcat service.
I have setup the tomcat script as a systemd service. I am using Cent OS 7 x64.
I have been able to achieve this by creating another service and incorporating the Tomcat service's start stop in the new service. The new service acts as a wrapper service which first starts tomcat and then executes the commands that we need to run as soon as tomcat starts.
Then while stopping, it stops tomcat and runs clean up commands.
EDIT: I found another way of doing this on unix & linux stackexchange.
Simply create an new systemd .service file in /etc which includes and overrides part of the one in /lib. For example, create /etc/systemd/system/tomcat.service to contain
.include /lib/systemd/system/tomcat.service
[Service]
ExecStartPre=/home/meuh/myscripttorun some pre args here
ExecStartPost=/home/meuh/myscripttorun some post args here
Any ExecStartPre lines will be executed before the ExecStart line, and similarly any ExecStartPost will run after tomcat has started.
I have following in a windows batch file, that I want to execute at startup, so I have created a service using NSSM.
start /min cmd /k
mongod --dbpath "D:\weather_station\weather_data" --repair
mongod --dbpath "D:\weather_station\weather_data"
I do this to start the mongodb server for my nodejs application.
I get an error:
Unexpected status SERVICE_PAUSED in response to START control
and in the files for I/O redirection (nssm logs), I get "'mongod' is not recognized as an internal or external command,operable program or batch file."
Now this script runs fine, if I directly execute it from windows, and mongod is installed and works fine.
I dont know, why nssm wont open a new command prompt and execute this service.
Is this the best way to start the mongodb server as a windows service ?
The first line with start /min cmd /k is completely useless in my point of view. Remove it.
A batch file is executed by the application defined in environment variable ComSpec. ComSpec has usually the value C:\Windows\System32\cmd.exe. The command start is (nowadays) an internal command of cmd.exe to start an application as a separate process.
You use start to start one more cmd.exe with the option to keep the minimized window open even after all applications started by this command line process finished. So all you get with the first line is a new minimized command prompt window doing nothing than waiting for user input.
cmd.exe used to execute the commands in the batch file continues immediately parsing the second command line which begins with mongod.
mongod is not an internal command of cmd.exe. Therefore mongod is interpreted by cmd.exe as the name of an executable file.
But this file name of the executable is without file extension and without path. So cmd.exe must search for an executable.
The environment variable PATHEXT contains a list of file extensions separated by semicolons for executables. This list is used now to find mongod.com or mongod.exe or mongod.bat or mongod.cmd, ...
So my first advice for you is: Specify mongod with file extension, i.e. mongod.exe
As there is no file path, cmd.exe searches first in current working directory for mongod.com or mongod.exe or ... and next in all directories specified in environment variable PATH separated by semicolons.
PATH contains a list of directories. But there is not only one PATH. There is system PATH and a PATH for the current user account as it can be seen in Advanced system settings in Windows Control Panel after clicking on button to open the dialog for viewing and changing the environment variables.
The PATH used by all applications is a combination of system PATH and used user account PATH.
You get the error message
'mongod' is not recognized as an internal or external command, operable program or batch file
as the directory containing mongod.exe is either listed in user PATH of your user account, or could be found in current working directory on running the batch file manually by you. But mongod.exe is not specified in system PATH nor PATH of the account used to run this batch file as service. And the working directory on execution of the batch file as service is also a different one, usually C:\Windows\System32 to get working batch files if just standard applications of Windows are specified in the batch file without file extension and file path.
The solution is therefore quite simple:
Specify mongod.exe with full path and in double quotes if the path contains one or more spaces.
"C:\Program Files (x86)\whatever\mongod.exe" --dbpath "D:\weather_station\weather_data" --repair
"C:\Program Files (x86)\whatever\mongod.exe" --dbpath "D:\weather_station\weather_data"
If mongod is a console application and not a GUI application, and mongod itself also does not start a separate process and then terminates immediately before this separate process finished, you do not need anything else. The batch file with those 2 lines is all you need.
Otherwise you would perhaps need:
start "Repair Data" /min /wait "C:\Program Files (x86)\whatever\mongod.exe" --dbpath "D:\weather_station\weather_data" --repair
start "..." /min /wait "C:\Program Files (x86)\whatever\mongod.exe" --dbpath "D:\weather_station\weather_data"
For help on command start enter in a command prompt window help start or start /?.
As a beginner in writing batch files take a look on Microsoft article about the Windows Commands.
I am trying to launch a local webserver instance of PhantomJs on a Azure Web (or Worker) Role to use with HighCharts for rendering server side charting images.
PhantomJs comes as just a simple .exe that can be launched as a webserver with the following command:
phantomjs highcharts-convert.js -host 127.0.0.1 -port 3003
... and then local HTTP POST requests can be made against it.
I have included this command in a startup.cmd batch script that is configured to execute with my Azure Web Role when published via ServiceDefinition.csdef:
<Startup>
<Task commandLine="startup.cmd" executionContext="elevated" taskType="background" />
</Startup>
startup.cmd:
START phantomjs highcharts-convert.js -host 127.0.0.1 -port 3003
EXIT /B 0
From what I can tell, this appears to execute fine on startup, however, the process does not stay running. It just executes and closes. For example, I can remote into the box, find the deployment and execute startup.cmd manually (in which a command window opens and stays open), and everything works fine.
How do I execute the PhantomJs exe webserver upon instance startup to where it continues running and does not close?
I have tried setting taskType to simple and background in the ServiceDefinition.csdef declaration, yet it doesn't seem to change anything.
It could be a timing issue if it is executing. You could add something like:
ping 1.1.1.1 -n 1 -w 300000 > nul
before you execute the script.
You could also pipe out to a log file so if its executing you can see what it is doing. >> log.txt.
If its not executing I would probably look at the path given its executing in the background and not interactively.
Turns out that I did not have the supporting .js files set to "Copy To Output Directory", so the startup.cmd could not find them.
Thanks to Steve for the output logging suggestion, which allowed me to see the error that it could not find "highcharts-convert.js".