I have a c# code that installs rabbitmq 3.7.4, erlang 20.2 on windows server 2012 R2 and I need to know when the application (not the service) has started. After running rabbitmq-service install and rabbitmq-service start I'm looking for a command line that will indicate that the application is running. I'm aware of the wait pid_file, wait --pid pid command but can't locate the pid file on my machine. The documantaion says:
This command will wait for the RabbitMQ application to start at the node. It will wait for the pid file to be created if pidfile is specified
specified where?
rabbitmq-echopid.bat returns:
The system cannot find the path specified.
On Windows, RabbitMQ does not create a PID file by default, so you have to discover the PID and then pass it as an argument: rabbitmqctl.bat wait -P PID
To discover the PID, you can run the following using the name of your RabbitMQ node:
.\rabbitmq-echopid.bat rabbit#my-hostname
At this time, there is a bug where The system cannot find... will be echoed before the PID is echoed. I filed this bug and will have a fix in soon, but in the meantime you can edit the rabbitmq-echopid.bat script to change !TDP0! to %TDP0%.
You can also use any other Windows tool to find the PID of the erl.exe process running RabbitMQ - see the script for an example of wmic.exe, or you could use tasklist, or Powershell, etc.
On windows, you can run the following batch script:
START /B rabbitmq-server
START /wait cmd /c "rabbitmq-echopid.bat -n rabbit#`hostname` > rabbitmq_pid.txt"
set /p PID=<rabbitmq_pid.txt
echo %PID%
del rabbitmq_pid.txt
cmd /c "rabbitmqctl wait -P %PID%"
Note that for the rabbitmq-echopid command to work, you have to add an -n before the nodename.
Moreover, in the above batch script, the nodename is dynamically generated by combining "rabbit#" withe the hostname windows command (inside backticks).
Related
I am running a test.cmd file from a C# exe by creating a System.Diagnostics.Process.
The test.cmd is launching a JScript file using the Windows Scripting Host Command Line as below
C:\myfolder>CScript.exe //Nologo testxml.js
testxml.js is running on localhost
==== Begin regenerating Xml ====
Invalid root in registry key "HKCR\CLSID\{5D1D2C1E-F343-10D2-93B4-00902710D4AD}\
LocalServer32\\".
Failed to regenerate Xml for transaction
But the key actually exists in the registry. I am able to look into it and modify it manually.
I tried changing permissions to the registry key but no use.
Please help me on how to resolve this error.
I am using a Windows 10 x64 machine.
below is the code of my test.cmd
#echo off
Cscript.exe //B
goto start
:start
#echo on
CScript.exe //Nologo testxml.js
:end
#echo off
All the solutions I can find on this topic are very old and none of them appear to answer my question...
I am trying to create a windows service that can self update (or auto update by some external trigger). In the past, I had created a windows service that was installed with InstallShield and we were able to update auto update the service in a hacky way by making the service write a batch script to the local machine and then run the batch script, which would stop the service, overwrite the service executable and other files with the new ones, and restart the service. This surprisingly worked.
However, I have updated the service to use InstallUtil.exe and this auto update script no longer works... I assume it's something to do with the way InstallShield handles the service install vs how InstallUtil does it... but I can only make guesses as I don't fully understand what each is doing to the registry.
Since I can't just overwrite the files and restart the service with the InstallUtil method, I thought I'd write a batch script that runs sc.exe to stop the service, uninstall it entirely, write the new files, install the new service files, and then start it... unfortunately, I can't seem to get sc.exe to run from a windows service automatically because it requires admin permissions... I tried to force it to self-elevate to admin using this snippet, but it doesn't appear to work as a service (it works fine if I run it from command line not as a service)
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
Does anyone know how I can cause a windows service to self update? I can look into updating to a .NET Core Worker service if there is some method of self update in .NET Core that I'm unaware of... Any ideas are much appreciated... it really shouldn't be this hard to accomplish...
For reference, here is the batch script I am currently using (ignore odd variables and such as I am dynamically replacing some of them, it works great when launched manually, just doesn't work when the service tries to run it):
#echo off
setlocal enableextensions enabledelayedexpansion
::make sure to run whole script as admin (this restarts scripts as admin if not already in admin mode)
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
pushd %networkDirectory%
::stop running service
for /F "tokens=3 delims=: " %%H in ('sc query %serviceName% ^| findstr " STATE"') do (
if /I "%%H" NEQ "STOPPED" (
net stop %serviceName%
if errorlevel 1 goto :stop
)
::delete existing service after stopping
sc delete %serviceName%
)
:: install updated service files
set "releaseDir=%networkDirectory%\Release"
set "programFilesCopyDir=%ProgramFiles%\{_companyDirectory}\%serviceName%\Release"
:: copy service Release dir to local system program files
xcopy "%releaseDir%" "%programFilesCopyDir%" /S /Y /Q
::execute the install
pushd "%programFilesCopyDir%"
CALL %serviceName%.exe --install
::start service
sc start %serviceName%
For anyone else trying to accomplish this that stumbles on this... I ended up finding a solution. I use the same script posted in my question above, but I wrote code to set up a scheduled task with Windows Task Scheduler. The scheduled task runs the above script as a one time scheduled task. This works like a charm.
I used this NuGet package to write the Task Scheduler code I needed:
https://www.nuget.org/packages/TaskScheduler/2.8.20?_src=template
I have a little .exe written in c# .net that I want to run on the server every 24 hours. So naturally I would just use the Windows Task Schedular rather then doing the math myself. I have created the program, but I would like to create an installer that just set everything up. Is there a way to do this with like the Visual Studio set-up projects? If not is there like a powershell / batch script that could be used to run after installation?
Bottom Line: Automate the creation of the task.
You can use a powershell script or batch file to execute schtasks which is a command line interface to the task scheduler.
Then you simply need to run the script in order to setup the scheduled task.
There is also a managed wrapper that allows you to create schedules tasks in C#, if you would rather go that way.
I know this is an old question, but I figure this may help someone else:
You can use the following to run in cmd.exe
FOR /F %1 IN ("path to text file containing list of servers") do psexec.exe \\%1 -u
"username to execute schtasks under" -p "password" schtasks /Create /S %1
/RU "username that will run the task" /RP "password" /XML "xml file of
the task to install" /TN "name of the task"
This will loop through the list of servers in a text file (1 server per line) and use psexec to call schtasks on each server and install your task.
I have the following in a vbs file that i am trying to run from the command line:
strServerName = "ServerName"
strAppPoolName = "DefaultAppPool"
set objAppPools = GetObject("IIS://" & strServerName
& "/w3svc/AppPools/" & strAppPoolName & "")
objAppPools.Recycle()
And yet when I run the vbs from cmd line i get the following error:
Microsoft VBScript runtime error: ActiveX component can't create object: 'Get Object'_
I am running XP on my local machine, and the remote machine has IIS 7.
How can I get this to work?
I am not sure regarding the particular vb script but I would recommend using "appcmd" (http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe)
Add %windir%\system32\inetsrv to your path if it is not already
in a command prompt type: appcmd recycle apppool "apppool_name"
While not a vbs file command you could get vbs to execute this command line;
appcmd recycle apppool /apppool.name:string
The variable string is the name of the application pool that you want to recycle. For example, to recycle an application pool named Marketing, type the following at the command prompt, and then press ENTER:
appcmd recycle apppool /apppool.name:Marketing
Taken from technet
If it's too far away from what you want then my apologies.
Use powershell command to run it. Example:
Invoke-WMIMethod Recycle -Path "IIsApplicationPool.Name='W3SVC/APPPOOLS/apppoolname'" -Computer "WIN-Computername" -Namespace root\MicrosoftIISv2 -Authentication PacketPrivacy
Where apppoolname is your application pool name.
Where WIN-Computername is your remote/local server name
Use powershell to execute command remotely on the server:
Invoke-Command -ComputerName <YOUR_IIS_SERVER_NAME> -ScriptBlock { Restart-WebAppPool -Name <YOUR_APP_POOL_NAME> }
I just tried it from a Windows XP machine to Windows 2008R2 machine. It worked. So you are definitely on the right track.
If you are looking for an alternative way, try this from a command prompt. At least the error message will be a little more specific, when it doesn't work.
wmic /namespace:"\\root\MicrosoftIISv2" /node:"**serverName**" path IISApplicationPool where (name like '%**DefaultAppPool**%') call recycle
Have you got the IIS7 WMI Provider installed and enabled on the remote machine?
I think this doc covers most of what you need.
this covers pre req and how to browse the available management options...sure you'll be able to reset the app pool with a few tweaks...
I just stumbled upon this problem, and here's the fix:
There is a small windows tool called PsExec, which basically gives you command line remote access, and from there you can use apppool. You can just run this command from C#
psexec \\192.168.xx.xx %windir%\system32\inetsrv\appcmd recycle apppool /apppool.name:yourapppool
here's the tool: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
Following commands worked for me after trying everything !
cd %windir%\system32\inetsrv
appcmd.exe stop site /site.name:"test1.com"
appcmd.exe start site /site.name:"test1.com"
Obviously before these, you will run some ssh remote command as well
OK, so here's the scenario.
CruiseControl.NET (Version : 1.5.7256.1) runs a project to rebuild a database. The CruiseControl.NET windows service is running as a windows user we created for CC.NET. There are several tasks in the project but they all run fine. However, one of the tasks that runs is a console based utility I wrote in C# that generates a batch file and then runs it via an instance of the .NET Process class.
The batch file is generated properly and the process runs fine in C#. However the batch file that runs, runs the sqlcmd command line utility for SQLServer (Version 2005 SP3). sqlcmd runs as expected, but one of the options for sqlcmd never gets applied... -I (turning quoted identifiers on).
e.g.
sqlcmd -U %1 -P %2 -S %3 -d %4 -i someScript.sql -k -b -I >> %LogFileName%
The odd thing is if I run this from a command prompt on the continuous integration server, it runs with -I being applied.
I'm very confused. I'd understand if the sqlcmd failed because the user executing the process didn't have enough privileges and I'd understand if something went wrong on the SQLServer side if the SQLServer authentication failed, but for it to work but not apply an option to sqlcmd is mystifying.
Could it be it's because -I is the last parameter? Perhaps there's a missing space there or something.. have you tried switching parameter order?
(also, why are you running a C# console app that create a batch file and the invokes it? Can't cc.net run this file itself?)