Jump to content

Recommended Posts

With a few modifications to some internal DCS LUA files, you can make DCS load a Multiplayer server mission on launch.... :)

 

The method WILL break when DCS updates and have to be redone, and is not for the faint hearted.

 

Firstly, make sure you server is set to auto login on start or you can't use this method.

 

Step one: use Notepad++ or another good editor to edit C:\Eagle Dynamics\DCS World\MissionEditor\MissionEditor.lua

 

Find the function onShowMainInterface and put in the code snippet between "DEDICATED CODE" below:

 


-- used in  __EMBEDDED__
function onShowMainInterface()
--print("--onShowMainInterface()---")
   if tooltipSkin_ == nil then
       tooltipSkin_ = Gui.GetTooltipSkin()
   else
       Gui.SetTooltipSkin(tooltipSkin_)
   end
   prepareMissionPath()
   mmw.setLastWallpaper()
   openReturnScreen()

    -- START DEDICATED CODE -  ADD FROM THIS LINE    
       --
       if grgFirstRun == nil then
           grgFirstRun = true

           local net = require('net')
           local lfs = require('lfs')
           local Tools = require('tools')
           local mpConfig = Tools.safeDoFile(lfs.writedir() .. 'Config/serverSettings.lua', false)
           local dediConfig = Tools.safeDoFile(lfs.writedir() .. 'Config/dedicated.lua', false)
           
            if dediConfig and dediConfig.dedicated ~= nil and dediConfig.dedicated["enabled"] == true then
              net.set_name(dediConfig.dedicated["name"])
              net.start_server(mpConfig.cfg)
              net.log("Starting Dedicated Server...")
           end
       end
       --
       -- END DEDICATED CODE - ADD UP TO THIS LINE 
end

 

Step two: Create a file called dedicated.lua in C:\Users\<USER NAME>\Saved Games\DCS\Config and add:

 

dedicated = 
{

["enabled"] = false,
["name"] = "Server Player Name",

}

 

Step 3: Configure your server as normal using the normal server launcher and launch it once. This ensures the settings are saved to the normal config file.

 

Step 4: Quit DCS, edit the dedicated.lua in C:\Users\<USER NAME>\Saved Games\DCS\Config and set enabled to true like so:

 

dedicated = 
{

["enabled"] = true,
["name"] = "Server Player Name",

}

 

Step 5: Load DCS and marvel as after login it loads your multiplayer server!

 

If you ever want DCS to startup as normal so you can make modifications, edit the dedicated.lua and set enabled to false.

 

I highly recommend you do the registry tweak listed here so DCS doesnt show an error window and is easy to restart. http://forums.eagle.ru/showpost.php?p=2642403&postcount=7

 

Note: If you press fly, you'll only be able to see the DCS home screen (dont worry the server is running!) and if you hit f10 you can see the map. Dont press buttons on the DCS home screen!

 

Next Steps: Use a program to automate the DCS Server launch and restart when crashed.

 

After a quick google I've found this and I'm going to try a few once I have some time: https://www.raymond.cc/blog/keep-application-running-by-automatically-rerun-when-closed/

 

Please don't hold me responsible if you wreck your DCS.... :thumbup:

 

Thanks to Xcom, Greg and Crash for help and testing!

 

EDIT: Disable the windows error message so you can restart it easily - https://www.raymond.cc/blog/disable-program-has-stopped-working-error-dialog-in-windows-server-2008/


Edited by Ciribob
Fixed spelling mistake

Scripts: Complete Transport And Logistics Deployment - CTLD / CTLD Examples - Lots of example of how to use CTLD

CSAR Script - Downed Pilot Rescue / Dedicated Server Script - Automatically launch DCS Multiplayer server at startup

Range Scoring Script - Get scores and counts hits on targets for gunnery or bombs / SimpleSlotBlock - Multiplayer dynamic Slot Blocking Script

 

Projects: DCS-SimpleRadio Standalone - DCS Radio Integration for All Aircraft - NO TeamSpeak Required! :)

DCS-SimpleRadio Troubleshooting Post / DCS-SimpleRadio Free Support Channel on Discord

Link to post
Share on other sites

I suspected you'd take an interest in this! Well if there wasn't a better example of using technology to automate a human action, this was it. I don't know what to say, but thank you seems to be an obvious start!

 

Does it detect when DCS is that state where its crashed but the process is still running? Any other states it can't cope with like Lua crashes? Should we supress Lua errors (ive found that leads it to crash instead)

 

Is there any additional testing you think is worth while?

 

Mike

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to post
Share on other sites
I suspected you'd take an interest in this! Well if there wasn't a better example of using technology to automate a human action, this was it. I don't know what to say, but thank you seems to be an obvious start!

 

Does it detect when DCS is that state where its crashed but the process is still running? Any other states it can't cope with like Lua crashes? Should we supress Lua errors (ive found that leads it to crash instead)

 

Is there any additional testing you think is worth while?

 

Mike

 

So currently the script just loads and starts multiplayer when DCS Launches, it wont automatically restart it.

 

From that link in the original post, I need to try a few of the programs listed to try automatically restarting DCS when it crashes or if its memory usage becomes too high. It would be great if you could try some as well on your dedicated server and let me know which work well!

 

In theory with this script, and one of those programs, down time of a server should be minutes at most and restarts automated :D

Scripts: Complete Transport And Logistics Deployment - CTLD / CTLD Examples - Lots of example of how to use CTLD

CSAR Script - Downed Pilot Rescue / Dedicated Server Script - Automatically launch DCS Multiplayer server at startup

Range Scoring Script - Get scores and counts hits on targets for gunnery or bombs / SimpleSlotBlock - Multiplayer dynamic Slot Blocking Script

 

Projects: DCS-SimpleRadio Standalone - DCS Radio Integration for All Aircraft - NO TeamSpeak Required! :)

DCS-SimpleRadio Troubleshooting Post / DCS-SimpleRadio Free Support Channel on Discord

Link to post
Share on other sites
So currently the script just loads and starts multiplayer when DCS Launches, it wont automatically restart it.

 

From that link in the original post, I need to try a few of the programs listed to try automatically restarting DCS when it crashes or if its memory usage becomes too high. It would be great if you could try some as well on your dedicated server and let me know which work well!

 

In theory with this script, and one of those programs, down time of a server should be minutes at most and restarts automated :D

 

I'm quite sure it's possible to write a quick app that does it; it would simply monitor the list of running processes every X seconds, and if there's no process listed called DCSWorld.exe, re-start it!

Link to post
Share on other sites

Yeah i was thinking, if you make DCS a service, windows should do it for you?

Scripts: Complete Transport And Logistics Deployment - CTLD / CTLD Examples - Lots of example of how to use CTLD

CSAR Script - Downed Pilot Rescue / Dedicated Server Script - Automatically launch DCS Multiplayer server at startup

Range Scoring Script - Get scores and counts hits on targets for gunnery or bombs / SimpleSlotBlock - Multiplayer dynamic Slot Blocking Script

 

Projects: DCS-SimpleRadio Standalone - DCS Radio Integration for All Aircraft - NO TeamSpeak Required! :)

DCS-SimpleRadio Troubleshooting Post / DCS-SimpleRadio Free Support Channel on Discord

Link to post
Share on other sites
Yeah i was thinking, if you make DCS a service, windows should do it for you?

Yeah, this manages restarting, what we need is a method to recognise a hung game.

 

Might I suggest a method? The game will need to create a heartbeat signal. In blue flag it would be your DynAB.lua, for others some other lua funciton that the external OS can recognise. If the files 'modified date' is not within parameters you know the game is no longer functioning and you can kill the process. It's a five line script in autoit, unfortuantely im not a developer and we should keep the languages consistent for support.

 

Autoit can use WMI calls for mem checks (im sure simple VBS can too), thats one thing it can do. I can't think of any symptoms other than that or 0% CPU. Its a shame I don't know how to interface things like the LUA process to commit a save or run an in game process before it does it as it might be more graceful and may catch things in time like a "save game state"

 

Any other snags?


Edited by Pikey
added wmi suggesiton

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to post
Share on other sites
Yeah, this manages restarting, what we need is a method to recognise a hung game.

 

Might I suggest a method? The game will need to create a heartbeat signal. In blue flag it would be your DynAB.lua, for others some other lua funciton that the external OS can recognise. If the files 'modified date' is not within parameters you know the game is no longer functioning and you can kill the process. It's a five line script in autoit, unfortuantely im not a developer and we should keep the languages consistent for support.

 

Autoit can use WMI calls for mem checks (im sure simple VBS can too), thats one thing it can do. I can't think of any symptoms other than that or 0% CPU. Its a shame I don't know how to interface things like the LUA process to commit a save or run an in game process before it does it as it might be more graceful and may catch things in time like a "save game state"

 

Any other snags?

 

Right now when a "DCS stopped running" occurs in our server it closes completely so that we can see it off in the map. So it doen't stay hanged.

 

Crash did it through the Windows somehow. I will tell him to post how. ;)

 

Greg

"ARGO" DCS UH-1H DLC SP Campaign

373vFS DCS World squadron (Greece) - www.buddyspike.net

"ARGO 2.0 Project Phoenix" UH-1H DLC Campaign - WIP

Link to post
Share on other sites

Might I suggest a method? The game will need to create a heartbeat signal.

 

Is it possible from a mission dev point of view to just update a file every five minutes that can be monitored? Doesn't have to contain anything and so memory usage and disk IO would be minimal. I don't know LUA, but I can certainly knock up a windows app or service that monitors change in that file and takes the appropriate action.

Link to post
Share on other sites
Is it possible from a mission dev point of view to just update a file every five minutes that can be monitored? Doesn't have to contain anything and so memory usage and disk IO would be minimal. I don't know LUA, but I can certainly knock up a windows app or service that monitors change in that file and takes the appropriate action.

 

Crash is your man for this :)

He should be on tonight as nobody really knows what he has in the server... It's a mystery :P

 

Example

2016-02-16 21:40,1,0,DCS.exe: running / ram: 2283.0 / swap: 2903.8

2016-02-16 21:45,-1,-1,DCS.exe: running / ram: 2348.9 / swap: 2967.2

2016-02-16 21:50,0,0,DCS.exe: running / ram: 2308.2 / swap: 2917.9

2016-02-16 21:55,3,15,DCS.exe: running / ram: 2617.7 / swap: 3263.3

2016-02-16 22:00,7,20,DCS.exe: running / ram: 2879.8 / swap: 3523.3

2016-02-16 22:05,14,30,DCS.exe: running / ram: 2938.0 / swap: 3590.8

2016-02-16 22:10,14,32,DCS.exe: running / ram: 2960.2 / swap: 3595.2

2016-02-16 22:15,17,35,DCS.exe: running / ram: 2991.8 / swap: 3618.6

2016-02-16 22:20,17,35,DCS.exe: running / ram: 3035.3 / swap: 3662.0

2016-02-16 22:25,20,37,DCS.exe: running / ram: 3053.8 / swap: 3677.2

2016-02-16 22:30,20,37,DCS.exe: running / ram: 3108.2 / swap: 3734.9

2016-02-16 22:35,21,35,DCS.exe: running / ram: 3164.3 / swap: 3789.0


Edited by gregzagk

"ARGO" DCS UH-1H DLC SP Campaign

373vFS DCS World squadron (Greece) - www.buddyspike.net

"ARGO 2.0 Project Phoenix" UH-1H DLC Campaign - WIP

Link to post
Share on other sites
Is it pulling the mission from the serverSettings.lua?

 

And is it the [1] it uses or how could you know what misison will load?

Yes it pulls it all from server settings so you just configure using the normal server config screen.

 

It'll load which ever mission is at the top of the list unless you've set the list to shuffle.

Scripts: Complete Transport And Logistics Deployment - CTLD / CTLD Examples - Lots of example of how to use CTLD

CSAR Script - Downed Pilot Rescue / Dedicated Server Script - Automatically launch DCS Multiplayer server at startup

Range Scoring Script - Get scores and counts hits on targets for gunnery or bombs / SimpleSlotBlock - Multiplayer dynamic Slot Blocking Script

 

Projects: DCS-SimpleRadio Standalone - DCS Radio Integration for All Aircraft - NO TeamSpeak Required! :)

DCS-SimpleRadio Troubleshooting Post / DCS-SimpleRadio Free Support Channel on Discord

Link to post
Share on other sites

We use a VB script on the VA server that simply monitors for DCS.exe to die. We also did the registry tweak so the crash window doesn't hang on the screen. I'll dig around the forums tonight to provide the info anyone may need.

 

Sent from my SM-G920V using Tapatalk

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

Link to post
Share on other sites

NB thanks to -=42VFG=-SPECTER for this:

So we are testing a little snippet to manage DCS with powershell. This is checking for not only the DCS.exe process but also its state, looking for "UNRESPONSIVE". This should cover times when DCS hangs but its going to take a lot of testing really to get there. Note that you get some "unresponsive" times when loading large misisons especially and a brief flicker on loading of DCS and potentially other times we haven't tested out.

 

Change the file path to your own, couldn't be bothered with getting the registry as we were in a rush.

 

The script samples the process 10 times over the $startup_sleep time and if it finds every check has been ' unresponsive', kills the server (in the server hung scenario)

It also checks the process exists once every ten seconds, else starts it.

 

There's one thing missing....If DCS goes to plan and the mission stays up, eventually it will collapse due to memory so the DCS process needs restarted to be graceful, I've not ran it until the process collapses so it's really untested. Schedule a DCS kill at 3am or an OS reboot to manage that.

 

You will need to put the PS into server 'startup' via a shortcut or registry or something...

POWERSHELL (.ps1):

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

$dcs_exec = "H:\Apps\DCS World\bin\DCS_updater.exe"

$startup_sleep = 100

$process_check_sleep = 10

if (-Not (Test-Path $dcs_exec)) {

Write-Host "The path to the DCS binary is not correct and doesnt exist, please correct and re-launch this script"

exit

}

while (1) {

if (get-process DCS -ErrorAction SilentlyContinue) {

$non_responsive_counter = 0;

for ($i=1; $i -le 10; $i++) {

if (get-process DCS -ErrorAction SilentlyContinue) {

if ((get-process DCS).Responding) {

Write-Host "DCS is Running - " + $((Get-Date).ToString())

sleep $process_check_sleep

}

else {

$non_responsive_counter++

}

}

else {

if (Test-Path $dcs_exec) {

Invoke-Item $dcs_exec

}

else {

Write-Host "The DCS Binary doesnt exit so exiting"

exit

}

Write-Host "DCS isnt running - Starting - Sleeping for $startup_sleep seconds to allow DCS to come up - " + $((Get-Date).ToString())

$non_responsive_counter = 0;

sleep $startup_sleep

break

}

}

if ($non_responsive_counter -ge 10) {

 

Write-Host "DCS has become unresponsive - stopping and starting the process" + $((Get-Date).ToString())

Stop-Process -processname DCS -ErrorAction SilentlyContinue -Force

Write-Host "Sleeping for 5 seconds to allow the process to stop"

sleep 5

if (Test-Path $dcs_exec) {

Invoke-Item $dcs_exec

}

else {

Write-Host "The DCS Binary doesnt exit so exiting"

exit

}

Write-Host "Restarting DCS Sleeping for $startup_sleep seconds to allow DCS to come up -" + $((Get-Date).ToString())

sleep $startup_sleep

continue

}

else {

$non_responsive_counter = 0;

}

}

else {

if (Test-Path $dcs_exec) {

Invoke-Item $dcs_exec

}

else {

Write-Host "The DCS Binary doesnt exit so exiting"

exit

}

Write-Host "DCS isnt running Starting - Sleeping for $startup_sleep seconds to allow DCS to come up - " + $((Get-Date).ToString())

sleep $startup_sleep

continue

}

}

 

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to post
Share on other sites
Right now when a "DCS stopped running" occurs in our server it closes completely so that we can see it off in the map. So it doen't stay hanged.

 

Crash did it through the Windows somehow. I will tell him to post how. ;)

 

Greg

 

Hey Greg, this is what I did for that, disable Windows Error Reporting:

 

[HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting]
"DontShowUI"=dword:00000001

It keeps that "DCS Stopped Working" window from popping up and allows our autorestart to bring DCS back up.

 

We use a variation of this for our VB script autorestart.....

 

PondLife's Auto DCS server restart monitor:

http://forums.eagle.ru/showthread.php?t=114361

.

.

.

.

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

Link to post
Share on other sites

Checking for unresponsive is a bad way of doing this.

 

The app can become unresponsive to the UI if it is busy. It doesn't mean it's crashed at all. You could end up restarting the server when the map changes.

 

You're better at looking at CPU time instead. This can be done in C#

Link to post
Share on other sites
Checking for unresponsive is a bad way of doing this.

 

The app can become unresponsive to the UI if it is busy. It doesn't mean it's crashed at all. You could end up restarting the server when the map changes.

 

Agreed.

 

The Windows Reporting registry change I noted above seems to help us on 90% of the DCS.exe crashes. Rarely do we ever discover the mission in a bad state AND DCS.exe is still active.

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

Link to post
Share on other sites
  • 3 weeks later...

And back again to restore the file change for the update! I've had this working for weeks now, its really awesome.

 

FWIW I settled for the "is DCS running, if not, launch it" simple app. I've now got power management sleeping and restarting the server every day and its fuilly unattended, which is awesome!

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to post
Share on other sites

This C# console app should do it. Written without testing, but theoretically it should work

 

using System;
using System.Diagnostics;
using System.Linq;
using static System.DateTime;
using static System.Diagnostics.Process;

namespace Restarter
{
   class Program
   {
       static void Main(string[] args)
       {
           MonitorProcess();
       }

       public static void MonitorProcess()
       {
           const int restartThreshold = 60;

           var p = GetProcesses();
           var dcsProcess = p.FirstOrDefault(process => process.ProcessName.ToLower().Contains("dcs")); //don't put .exe, just the process name                        

           if (dcsProcess == null)
           {
               Console.WriteLine("Could not find the DCS process");
               return;
           }
               
           var checkTime = Now.AddSeconds(restartThreshold);

           do
           {
               var responding = dcsProcess.Responding; //Is the process responding?

               if (Now == checkTime && !responding)  //Is it checkTime and is the process not responding?
               {
                   dcsProcess.Kill(); //Kill the process
                   dcsProcess = StartProcess(dcsProcess); //Make a new process and start it
                   MonitorProcess(); //Restart the monitoring process
               }
               else
               {
                   if (responding) //Process is still responding
                       checkTime = Now.AddSeconds(restartThreshold);
               }

               System.Threading.Thread.Sleep(5000);
           } while (true);
       }

       public static Process StartProcess(Process dcsProcess)
       {

           //Wait 5 seconds before starting again
           var waitTime = Now.Add(new TimeSpan(5));

           do
           {
           } while (Now <= waitTime);

           var startInfo = dcsProcess.StartInfo;
           return Start(startInfo);
       }
   }
}

 

If not responding for more than 60 seconds it will kill the process then restart it with the same parameters. DCS must be running first.


Edited by 112th_Rossi
Link to post
Share on other sites

After you said checking for responsiveness is bad I just did that as it's simpler and the unresponsive part does get messy fast, especially during the launch of the app. There's 101 ways of doing that I wrote mine in Autoit if anyone wants the binary.

Checking for unresponsive is a bad way of doing this.

 

The app can become unresponsive to the UI if it is busy. It doesn't mean it's crashed at all. You could end up restarting the server when the map changes.

 

You're better at looking at CPU time instead. This can be done in C#

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to post
Share on other sites

It's bad but I would still consider it. The script above checks for responsiveness over time.

 

There's no guaranteed way of checking to see if an application has frozen.

 

If you want to reboot after crashes you'll need to turn off Just In Time debugging to stop the app crash window appearing.

Link to post
Share on other sites

Well the first script I posted will wait for a customisable amount until the mission is loaded (need to tune the number as it is a long load time right to the mission launch) then it will sample responsiveness over seconds that are also configurable eg check once every 10 seconds for a total amount of seconds. But this is why I said it gets messy because there are so many exceptions to this unresponsive behaviour that formulating a pattern isn't programmatically reliable.

 

Having said that, I've not had DCS misbehave in the same way as before so it's not as important as it was to study that type of failure. With a reboot every 24 hours my server has avoided the out of memory issues that were a massive cause of DCS "seizing".

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...