How to run JMeter server as a service in windows - windows

Is it possible to run JMeter server as a service in windows?
Currently I'm just logging in and running it manually, but from time to time I have to restart this machine and I would like to make JMeter server run automatically after each restart (even no user logs in after restart).

To create windows service sc create serviceName binpath= "path\to\exe"
You can also create a shortcut/bat file in the windows startup folder to start the JMeter. C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
You can also have a look at this - to start a program using windows task scheduler w/o user log in.

Related

run batch script after windows server restart

I am trying to run a script to startup some services after windows reboot.
I have tried one method: copying shortcuts of batch script in shell:startup folder. which eventually will start the scripts automatically but someone has to login to the system.
I am thinking about the possible ways to run the script after server restart without logon to the server.
Any help will be highly appreciated.
Create a Windows scheduled task and set it to run on system startup:

Stopping/starting an application pool and site on a server

I would like to write a script and run it from my local PC to stop and start an application pool and site that exists on a server.
Value of App Pool and Site - Test
Value of server - SERVER1
Any guidance would be much appreciated.
Run Command Prompt with Administrative rights, and type the following:
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"
or use the stop command. You could save this in a batch file, but it must be executed with higher privileges.
For the application pool on a remote server, you could use PsExec:
Psexec \\{Computer Name of ISS7 Server} C:\Windows\System32\inetsrv\appcmd recycle apppool my-app-pool

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?

Create shortcut to restart a service on another machine

We have a server that is on the same LAN as my work computer. I know you can use "net stop" and "net start" in a batch file to restart a service on the local machine, but is it possible to do that for a remote machine?
I know you can use \computer to browse a networked machine, for example, so is there some syntax that would be something like \computer net stop service or so on?
Right now I have to Remote Desktop into the machine, restart the service, then log off, which is a hassle.
Create a Desktop shortcut
in the cmd to run enter :
sc \\server stop service
sc is the service management tool
server is your remote server name or IP
and finally service is the name of the service you target
I figured it out - for anyone else wondering: you can use this command:
C:\Windows\System32\runas.exe /savecred /user:[domain\user] "C:\windows\system32\cmd.exe /c C:\Test.bat" Where your batch file with the sc \server stop service is in C:\Test.bat. (You can move that around obviously)

Run batch file as a Windows service

In order to run one application, a batch file has to be kicked off (which does things like start Jetty, display live logs, etc). The application will work only if this batch file is running. I am hence forced to have this batch file running and not logout from the Windows server.
Can this batch file be run as a service? I am experimenting with one of the suggestions from a similar question.
NSSM is totally free and hyper-easy, running command prompt / terminal as administrator:
nssm install "YourCoolServiceNameLabel"
then a dialog will appear so you can choose where is the file you want to run.
to uninstall
nssm remove "YourCoolServiceNameLabel"
There's a built in windows cmd to do this: sc create. Not as fancy as nssm, but you don't have to download an additional piece of software.
sc create "ServiceName" start= demand displayname= "DisplayName" binpath= [path to .bat file]
Note
start=demand means you must start the service yourself. Options include: boot, system, auto, demand, disabled, delayed-auto
whitespace is required after =
I did encounter an error on service start that the service did not respond in a timely manner, but it was clear the service had run the .bat successfully. Haven't dug into this yet but this thread experienced the same thing and solved it using nssm to install the service.
No need for extra software. Use the task scheduler -> create task -> hidden. The checkbox for hidden is in the bottom left corner. Set the task to trigger on login (or whatever condition you like) and choose the task in the actions tab. Running it hidden ensures that the task runs silently in the background like a service.
Note that you must also set the program to run "whether the user is logged in or not" or the program will still run in the foreground.
On Windows 2019 Server, you can run a Minecraft java server with these commands:
sc create minecraft-server DisplayName= "minecraft-server" binpath= "cmd.exe /C C:\Users\Administrator\Desktop\rungui1151.lnk" type= own start= auto
The .lnk file is a standard windows shortcut to a batch file.
--- .bat file begins ---
java -Xmx40960M -Xms40960M -d64 -jar minecraft_server.1.15.1.jar
--- .bat file ends ---
All this because:
service does not know how to start in a folder,
cmd.exe does not know how to start in a folder
Starting the service will produce "timely manner" error, but the log file reveals the server is running.
If you need to shut down the server, just go into task manager and find the server java in background processes and end it, or terminate the server from in the game using the /stop command, or for other programs/servers, use the methods relevant to the server.
As Doug Currie says use RunAsService.
From my past experience you must remember that the Service you generate will
have a completely different set of environment variables
have to be carefully inspected for rights/permissions issues
might cause havoc if it opens dialogs asking for any kind of input
not sure if the last one still applies ... it was one big night mare in a project I worked on some time ago.
While it is not free (but $39), FireDaemon has worked so well for me I have to recommend it. It will run your batch file but has loads of additional and very useful functionality such as scheduling, service up monitoring, GUI or XML based install of services, dependencies, environmental variables and log management.
I started out using FireDaemon to launch JBoss application servers (run.bat) but shortly after realized that the richness of the FireDaemon configuration abilities allowed me to ditch the batch file and recreate the intent of its commands in the FireDaemon service definition.
There's also a SUPER FireDaemon called Trinity which you might want to look at if you have a large number of Windows servers on which to manage this service (or technically, any service).
Since NSSM is no longer maintained, you can consider using WinSW. It has binaries that would work with or without .Net.
Basically you create an XML file and then install it. Here is a sample of a minimal XML:
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>myapp</id>
<!-- Path to the executable, which should be started -->
<!-- CAUTION: Don't put arguments here. Use <arguments> instead. -->
<executable>%BASE%\myExecutable.exe</executable>
</service>
And then you can install and start it:
winsw install myapp.xml
winsw start myapp.xml
Install NSSM and run the .bat file as a windows service.
Works as expected
My easest way is using opensource svcbatch (https://github.com/mturk/svcbatch/) as wrapper of CMD(BAT) in sc :
sc create myservice binPath= ""%cd%\svcbatch.exe" myservice.bat"

Resources