PondLife Posted September 22, 2013 Posted September 22, 2013 (edited) So re-starting the dcs server after a crash is currently a manual process due to the cmd line limitations of DCS. I've come up with a solution using a VB script to monitor DCS and a "AutoHotkey" script to re-start it. Example files attached to the post Demo Vid: You'll need to download and install AutoHotkey from http://www.autohotkey.com/ I've tested this on windows 7 pro 64 bit Basically the VB script monitors for the DCS process and starts the autohotkey script if DCS is not running. The VB scripts then loops at a pre-defined interval to monitor the server. Autohotkey is a UI test tool which can enter mouse clicks etc to test an application. It can also obviously be configured to start DCS and select and load missions using the DCS GUI. YOU WILL need to create a new hotkey script to match the GUI properties of your DCS window but this is fairly straightforward. The VB script: '**************************************** '* Application Restart Script * '* based on http://www.intelliadmin.com * '* amended by s77th yeti for DCS * '* AutoHotkey is also needed in order * '* to re-start the dcs server * '**************************************** set Service = GetObject ("winmgmts:") set Shell = WScript.CreateObject("WScript.Shell") '**************************************** '* Set variables * '**************************************** 'Name of the DCS exe we want to watch sEXEName = "DCS.exe" 'Path of the folder the AutoHotkey script is in (Don't forget the trailing \) sHotKeyPath = "C:\utils\bin\" 'Hot key script name sHotKeyScript = "DCS_mon.ahk" 'polling interval for the monitor in milliseconds (10000 is 10 seconds) sScriptInterval = "10000" '**************************************** '* NO NEED TO EDIT BELOW THIS LINE * '**************************************** 'Loop until the system is shutdown or user logs out while true bRunning = false 'Look for our application. Set the flag bRunning = true 'If we see that it is running for each Process in Service.InstancesOf ("Win32_Process") if Process.Name = sEXEName then bRunning=true End If next 'Is our app running? if (not bRunning) then 'No it is not, launch it Shell.Run Chr(34) & sHotKeyPath & sHotKeyScript & Chr(34) end if WScript.Sleep (sScriptInterval) wend The autohotkey script: #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. Run "C:\Program Files\Eagle Dynamics\DCS World\bin\DCS.exe" --net-mode gui sleep 20000 send {Enter} Sleep, 10000 click, 654, 1020 left Sleep, 10000 click, 1348, 449 left Sleep, 10000 click, 1415, 1019 left Exit Edited September 22, 2013 by PondLife
PondLife Posted September 22, 2013 Author Posted September 22, 2013 (edited) addendum OOps, forgot some stuff.... In order for the script to work, you need to ensure a few things: 1. Ensure The DCS network config file has "pause_on_load = false" set. The file can usually be found here: C:\Users\YOUR USER NAME\Saved Games\DCS\Config 2. In order to handle/bypass the crash dialogue box which appears after a DCS server crash, you need to set a couple of registry keys. IMPORTANT - this will effect all application crashes you have on your server, instead of a dialogue box saying "bla bla stopped working" close the application or get a solution online" (or words to that effect) the application will crash straight to a dump file without any prompting. The DCS process will then hang around for about 6 seconds before closing. I STRONGLY recommend you backup your registry before making any changes. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting] "ForceQueue"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\Consent] "DefaultConsent"=dword:00000001DCS_Servermon.zip Edited September 27, 2013 by PondLife
HiJack Posted September 22, 2013 Posted September 22, 2013 (edited) Thanks. Will check tomorrow. Could you also do a check in the log folder for .crash files and jump the server if one is present? But that script should rename the current log folder and track forlder with current date and time before restarting the server. Like "Log_09.22.20133-100535" and "Tracks_09.22.20133-100535" as the folder names. Edited September 22, 2013 by HiJack
PondLife Posted September 22, 2013 Author Posted September 22, 2013 Thanks. Will check tomorrow. Could you also do a check in the log folder for .crash files and jump the server if one is present? But that script should rename the current log folder and track forlder with current date and time before restarting the server. Like "Log_09.22.20133-100535" and "Tracks_09.22.20133-100535" as the folder names. You could do that but it would have a high overhead and would slow the script down. The vbs script catches the fact DCS is not running, if it is running the hotkey script does not run, if DCS is not running it runs the hotkey script which bounces the server. Note that the DCS "zombie process only hangs around for a few seconds before it dies and the bounce of the server occurs. The amount of time the dcs process hangs around after a crash dump is set in: (I think) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting] "ServiceTimeout"=dword:0000ea60
HiJack Posted September 24, 2013 Posted September 24, 2013 Tested but does not work for me. The scripts are based on a fixed screen resolution and window size. If you manage your servers remotely and use “TeamViewer”, “VNC” or “TightVNC Viewer” to do all the management you can change the resolution/size of windows and make the script nonfunctional. We need a dedicated server with admin tools from ED soon to really make something that works permanently. I can’t understand why this is not obvious for ED.
HiJack Posted September 24, 2013 Posted September 24, 2013 (edited) To get this to work you need to get the current screen resolution settings and maby DCS World window size and then calculate the possitions for the script. And will it work when there is no desktop view? Edited September 24, 2013 by HiJack
Pman Posted September 24, 2013 Posted September 24, 2013 We need a dedicated server with admin tools from ED soon to really make something that works permanently. I can’t understand why this is not obvious for ED. Confirmed that it wont be coming until the Edge release
PondLife Posted September 26, 2013 Author Posted September 26, 2013 Tested but does not work for me. The scripts are based on a fixed screen resolution and window size. If you manage your servers remotely and use “TeamViewer”, “VNC” or “TightVNC Viewer” to do all the management you can change the resolution/size of windows and make the script nonfunctional. We need a dedicated server with admin tools from ED soon to really make something that works permanently. I can’t understand why this is not obvious for ED. I'm not quite sure what you're saying here... are you trying to run the Hotkey script on your local machine and interact via a VNC viewer window? this is never going to work. You need to run everything on the server and re do the hotkey script for your environment on the server. It should really matter if its a window as a long as the reference window size is the same on start up, which it will be if you leave it alone. I'll install the scripts on our remote server which we manage with radmin and try and prove the concept.
PondLife Posted September 26, 2013 Author Posted September 26, 2013 To get this to work you need to get the current screen resolution settings and maby DCS World window size and then calculate the possitions for the script. And will it work when there is no desktop view? Correct and no it will not work if there is no window view on the server. I was not aware you could fully start the DCS server (and load missions) in no gui mode.... 2
sslechta Posted September 26, 2013 Posted September 26, 2013 Hey Pondlife, Got your script working perfectly on my local PC but when I implement it on the VA server, DCS.exe dies right after the first person joins the server. Any ideas? P.S. - +1 from me on this script. Steve (Slick) ThrustMaster T.Flight Hotas X | TrackIR5 Pro | EVGA GTX 1070 | Win10 64-bit Professional | Dell Precision 7920 Workstation | 1 TB SSD | 128 GB Memory | Dual Intel Xeon Platinum 2.0 GHz 16 Core Processors (64 Total w/HT ON) | 24" Dell Monitor
sslechta Posted September 26, 2013 Posted September 26, 2013 To provide more detail, I installed AutoHotKey on my PC and the server using the 64-bit install option since both machines are 64-bit. My PC is Win8 while the server is on Server 2012. You think some of the "No Need to Edit Below this Line" code is having problems on Win 2012? Steve (Slick) ThrustMaster T.Flight Hotas X | TrackIR5 Pro | EVGA GTX 1070 | Win10 64-bit Professional | Dell Precision 7920 Workstation | 1 TB SSD | 128 GB Memory | Dual Intel Xeon Platinum 2.0 GHz 16 Core Processors (64 Total w/HT ON) | 24" Dell Monitor
PondLife Posted September 27, 2013 Author Posted September 27, 2013 (edited) Hey Pondlife, Got your script working perfectly on my local PC but when I implement it on the VA server, DCS.exe dies right after the first person joins the server. Any ideas? P.S. - +1 from me on this script. So I've just implemented this on the S77th server and it appears to be working fine. We had a few people join the server and everything was OK. The only thing I can think is it may be is that that AutoHotkey app had multiple instances running because someone shut down the server and didn't kill the scripts using the bat file. Just to be sure everything stops when you run the stop bat I've edited it slightly: taskkill -T -F /IM wscript.exe taskkill -T -F /IM AutoHotkey.exe Edited September 27, 2013 by PondLife
PondLife Posted September 27, 2013 Author Posted September 27, 2013 To provide more detail, I installed AutoHotKey on my PC and the server using the 64-bit install option since both machines are 64-bit. My PC is Win8 while the server is on Server 2012. You think some of the "No Need to Edit Below this Line" code is having problems on Win 2012? I haven't tested this on server 2012 or windows 8. To debug it you could do something like this: it does the same but for notepad.exe. If this works the VB script is fine. Also just to add, the script is now working perfectly on the S77th server and re-starts DCS after about 3 minutes on crash. '**************************************** '* Application Restart Script * '* based on http://www.intelliadmin.com * '* amended by s77th yeti for DCS * '* AutoHotkey is also needed in order * '* to re-start the dcs server * '**************************************** set Service = GetObject ("winmgmts:") set Shell = WScript.CreateObject("WScript.Shell") '**************************************** '* Set variables * '**************************************** 'Name of the DCS exe we want to watch sEXEName = "notepad.exe" 'Path of the folder the AutoHotkey script is in (Don't forget the trailing \) sHotKeyPath = "%windir%\system32\" 'Hot key script name sHotKeyScript = "notepad.exe" 'polling interval for the monitor in milliseconds (10000 is 10 seconds) sScriptInterval = "10000" '**************************************** '* NO NEED TO EDIT BELOW THIS LINE * '**************************************** 'Loop until the system is shutdown or user logs out while true bRunning = false 'Look for our application. Set the flag bRunning = true 'If we see that it is running for each Process in Service.InstancesOf ("Win32_Process") if Process.Name = sEXEName then bRunning=true End If next 'Is our app running? if (not bRunning) then 'No it is not, launch it WScript.Echo "notepad is not running, do you want to launch it?" Shell.Run Chr(34) & sHotKeyPath & sHotKeyScript & Chr(34) end if WScript.Sleep (sScriptInterval) wend
sslechta Posted September 27, 2013 Posted September 27, 2013 taskkill -T -F /IM wscript.exe taskkill -T -F /IM AutoHotkey.exe As soon as I saw the kill for AutoHotKey, I was hopeful. Looks like that did the trick! I cannot thank you enough for your help on this! Here's to more server uptime! :drink: Steve (Slick) ThrustMaster T.Flight Hotas X | TrackIR5 Pro | EVGA GTX 1070 | Win10 64-bit Professional | Dell Precision 7920 Workstation | 1 TB SSD | 128 GB Memory | Dual Intel Xeon Platinum 2.0 GHz 16 Core Processors (64 Total w/HT ON) | 24" Dell Monitor
PondLife Posted September 27, 2013 Author Posted September 27, 2013 As soon as I saw the kill for AutoHotKey, I was hopeful. Looks like that did the trick! I cannot thank you enough for your help on this! Here's to more server uptime! :drink: No problem, I'll update the zip attachment with the new stuff.
PondLife Posted September 27, 2013 Author Posted September 27, 2013 A few tweaks Added logging, added hotkey kill to stop script, added comments to vb script and hotkey script. Please don't try this if you're not reasonable capable of understanding what the files actually do..... You'll also need to add a log location for the log file and tell the vb script where it is. YOU MUST CHANGE THE HOTKEY SCRIPT MOUSE COORDINATES to match your environment!DCS_Servermon_2.zip
sslechta Posted September 27, 2013 Posted September 27, 2013 PondLife, I think we'll definitely add the logging, thanks. When DCS.exe has been crashing it has not been coming back up. 1) It's looking like AutoHotKey has been opening several instances of itself up when we look in there. 2) This server is headless and has no normal monitor. Wondering if the script only works when we're connected to the server. DCS launched fine as soon as we connected and saw the desktop. We'll see what we get when we enable logging. Steve (Slick) ThrustMaster T.Flight Hotas X | TrackIR5 Pro | EVGA GTX 1070 | Win10 64-bit Professional | Dell Precision 7920 Workstation | 1 TB SSD | 128 GB Memory | Dual Intel Xeon Platinum 2.0 GHz 16 Core Processors (64 Total w/HT ON) | 24" Dell Monitor
PondLife Posted September 27, 2013 Author Posted September 27, 2013 PondLife, I think we'll definitely add the logging, thanks. When DCS.exe has been crashing it has not been coming back up. 1) It's looking like AutoHotKey has been opening several instances of itself up when we look in there. 2) This server is headless and has no normal monitor. Wondering if the script only works when we're connected to the server. DCS launched fine as soon as we connected and saw the desktop. We'll see what we get when we enable logging. The only reason you'll get AutoHotkey starting multiple instances is if: 1. You haven't entered the coordinates correctly in the autohotkey script and its not actually starting DCS properly 2. The sleep times in the autohotkey script need tweaking 3. The window size and coordinates change every time on DCS startup for some reason The logging will only tel you if DCS is not running and what the DTS of this is. I could add logging to every action of the autohotkey script but that would increase the over head. There maybe a problem with headless servers.... (there probably is)I haven't tested on one and we don't have one. My suggestion would be: 1. Just run the autohotkey script to see if it start dcs properly 2. If it doesn't you'll could try redoing the coordinates for the mouse clicks 3. If that doesn't work then I suspect it's because the server is headless The only option you then have is to have a client running all the time with an open window. Thats not optimal obviously....
Pman Posted September 27, 2013 Posted September 27, 2013 Got it to work on headless (I think) If you connect via RDP the problem is that the server "locks" behind you, similar to hitting ctrl, alt and del to lock a pc To prevent this, go to start, then run, then use this command tscon 1 /dest:console This will disconnect a server session without logging out behind you Pman
xcom Posted November 1, 2015 Posted November 1, 2015 Sorry to raise this old Thread. Anyone altered this for the open beta? I can do it but thought someone already had it done.... [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
sslechta Posted November 2, 2015 Posted November 2, 2015 Hi Xcom. All you need to do is change your mouse click coordinates for the locations of the new buttons from 1.5. Should work fine after that. Steve (Slick) ThrustMaster T.Flight Hotas X | TrackIR5 Pro | EVGA GTX 1070 | Win10 64-bit Professional | Dell Precision 7920 Workstation | 1 TB SSD | 128 GB Memory | Dual Intel Xeon Platinum 2.0 GHz 16 Core Processors (64 Total w/HT ON) | 24" Dell Monitor
xaoslaad Posted March 10, 2017 Posted March 10, 2017 (edited) Thanks for all this. I was able to extend it to run two copies of the game by also looking at the executable path since I run two servers, one release, one alpha. To this end I also have it move the windows to opposite corners of the screen and added some additional timeouts after running an ahk script. If both were to crash at once I doubt starting both on top of each other would end well. Since I threw the vbs in my startup and wanted to leave a little breathing room for things to settle I start with a 60 second pause before going into the while loop. I also had to be a little more robust and look for the window and activate it, which was not a problem until I added the script to my startup. And I have it check for a listening port since it seems that after a crash it can take awhile for the game to run. If we're not listening, we're not a server, so we terminate the process and try again. And I have it run as an unprivileged user for fun as well. Very helpful and nice idea though. Thanks again for the basic idea. WScript.Sleep (60000) '**************************************** '* Application Restart Script * '* based on http://www.intelliadmin.com * '* amended by s77th yeti for DCS * '* AutoHotkey is also needed in order * '* to re-start the dcs server * '**************************************** set Service = GetObject ("winmgmts:") set Shell = WScript.CreateObject("WScript.Shell") set fso = CreateObject("Scripting.FileSystemObject") '**************************************** '* Set variables * '**************************************** 'Name of the DCS exe we want to watch sEXEName = "DCS.exe" alpha = "C:\Program Files\Eagle Dynamics\DCS World 2 OpenAlpha\bin\DCS.exe" release = "C:\Program Files\Eagle Dynamics\DCS World\bin\DCS.exe" sHotKeyPath = "C:\Users\User\Documents\" sHotKeyAlphaScript = "dcs_alpha.ahk" sHotKeyReleaseScript = "dcs.ahk" alphaport = "10309" releaseport = "10308" '**************************************** '* NO NEED TO EDIT BELOW THIS LINE * '**************************************** Function PortMonitor (port) command = "cmd /C netStat -an |find "":" & port & """ > " & sHotKeyPath & "port_status.txt" Shell.Run command, 0, True PortMonitor = fso.GetFile(sHotKeyPath & "port_status.txt").size end Function 'Loop until the system is shutdown or user logs out while true alphaport_status = PortMonitor (alphaport) releaseport_status = PortMonitor (releaseport) if alphaport_status = 0 then for each Process in Service.InstancesOf ("Win32_Process") if Process.Name = sEXEName and Process.ExecutablePath = alpha then Process.Terminate() End If next End If if releaseport_status = 0 then for each Process in Service.InstancesOf ("Win32_Process") if Process.Name = sEXEName and Process.ExecutablePath = release then Process.Terminate() End If next End If alphaRunning = false releaseRunning = false for each Process in Service.InstancesOf ("Win32_Process") if Process.Name = sEXEName and Process.ExecutablePath = alpha then alphaRunning=true End If if Process.Name = sEXEName and Process.ExecutablePath = release then releaseRunning=true End If next if (not alphaRunning) then 'No it is not, launch it Shell.Run Chr(34) & sHotKeyPath & sHotKeyAlphaScript & Chr(34) WScript.Sleep (60000) end if if (not releaseRunning) then 'No it is not, launch it Shell.Run Chr(34) & sHotKeyPath & sHotKeyReleaseScript & Chr(34) WScript.Sleep (60000) end if WScript.Sleep (10000) wend RunAs DCS, youruserpasswordgoeshere Run "C:\Program Files\Eagle Dynamics\DCS World\bin\DCS.exe" --net-mode gui Sleep, 60000 WinActivate, ahk_exe C:\Program Files\Eagle Dynamics\DCS World\bin\DCS.exe Sleep, 2000 WinMove, A, , 1271, 0 click, 1085, 360 left Sleep, 2000 click, 640, 780 left Sleep, 2000 click, 680, 780 left Exit RunAs DCS, youruserpasswordgoeshere Run "C:\Program Files\Eagle Dynamics\DCS World 2 OpenAlpha\bin\DCS.exe" --net-mode gui Sleep, 60000 WinActivate, ahk_exe C:\Program Files\Eagle Dynamics\DCS World 2 OpenAlpha\bin\DCS.exe Sleep, 2000 WinMove, A, , -7, 770 click, 1085, 360 left Sleep, 2000 click, 640, 780 left Sleep, 2000 click, 680, 780 left Exit Edited March 14, 2017 by xaoslaad
Recommended Posts