Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Concept for a server uptime keeper

tgp1994tgp1994 Member Posts: 6
Hi there everyone, I'm one who generally hosts servers in Garry's Mod, a Source engine mod. Being widely open to many submodifications, it's difficult to keep that program up without it crashing. It gets particularly annoying when it freezes with an error, and needs me to manually reboot it. So anyways, I was kind of hoping that someone may be able to guide me through making a VB.Net program capable of

A)Detecting and keeping track of the specific server's process
B)Pinging it through the port I want
C)Ability to kill it when it freezes or an error pops up

I am pretty new to VB.Net, but I am (sort of) coming along.

Thanks in advance.

If anyone wants any more details, they can of course ask, too.
«1

Comments

  • seancampbellseancampbell Pennsylvania, USAMember Posts: 684 ✭✭✭
    Wish I could help ya, I have never done anything like that before.

    Sounds like you'd want to write a windows service that resides on the server that keeps hanging up. The program would probably need permissions to reboot the computer, another thing I have never done from an app before.

    If you run into any problems with code you've written, feel free to post up specific errors or lines of code you're having trouble with.

    I tend to be better at solving specific issues, usually am not successful at helping new coders write applications, only help them understand why they are having errors with specific code

    -sean c
  • tgp1994tgp1994 Member Posts: 6
    Thanks for replying.

    I think I may have misspoken when I said server. By server, I actually meant a game server, which is just a simple executable on my otherwise home computer. I think that might make this program more easier, anyways. I seem to have a few problems here and there, but it wouldn't be too much for me to ask if you could join the #vb.net irc chatroom on irc.gamesurge.net? I think it just might make faster communication.
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    What sort of communication foundation are you using?

    If your whole server is freezing on a single call then I'm guessing you are not properly threading your server.

    Also - what does your framework look like and what pattern strategies are you using?

    ><//~Psightoplasm`~
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    Also a huge part of debugging any server is having proper logging. Every service call should be writting to a log file or db.

    Also your application or system event logs may have something in them if there was any kind of resulting exception.
    ><//~Psightoplasm`~
  • tgp1994tgp1994 Member Posts: 6
    Well, I think this is more of an unavoidable crash, since it's developer doesn't seem to give a crap about what the end users think. And since the game, (server), has such a large community of modders, anything can really make it crash. Anyhow, I believe most of the crashes occuring to it come from just it running out of resources. It does however create a .MDMP file, which I gather is for debugging, but if it's an error in the code, there's nothing I can do about it. That's why I'm trying to make this program.
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    Actually - there are alot of profilers available that can give you a wealth of info on what's going on in a .net assembly - if you are trying to pinpoint a performance issue check this out:
    [link=http://www.red-gate.com/products/ants_performance_profiler/walkthrough1/step5.htm]Red-Gate Performance Profiler[/link]
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    It sounds like you are saying that you do not have access to the source code for this thing - do you have at least access to the executing assemblies?

    If not there isn't going to be much you can do.

    If you absolutely can't get ahold of source for this thing but you CAN get ahold of the compiled assembly (as long as it is not signed) one very painfull option for you is to download Reflector from www.Red-Gate.com and just dissassemble the thing back into source and patch it back together into a solution.
  • tgp1994tgp1994 Member Posts: 6
    I think we might be getting a little off track here. This server, Garry's mod, has tons of dlls, and I'm not very interested in doing the developers dirty work to fix their own program. I wouldn't even know how, since it's in C++. However, I want to sort of help by making my own program, in VB.Net, that will restart that serving program is it crashes, and if it can't ping/open a socket to it.

    I hope that helps.
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    ok - I'm sorry, I assumed you wanted to actually solve the underlying problem and made all sorts of foolery here.

    So what you want to do is:
    - Work with the existing crappy system without making any alterations.
    - Be able to detect when the server has stopped responding.
    - Upon detecting a dead server, close the process and restart it.


    This is actually fairly simple to do. What you are actually looking at designing is an "application host".

    Now to my understanding the server process itself is not actually crashing, but is "locking" up or just stops responding to requests. So it won't help to detect if the application crashes.

    While "pinging" will tell you that the actual server machine is up and running, it will not actually tell you if the server application is responsive or not. You will need to find a "heartbeat" command that you can tap into. So if there is some already-existing request that you can send to the server and get a response from that doesn't require any significant processing time - this is what you should use.

    So I can't tell by this thread what kind of communication solution the server application is using to communicate with clients. In order to make a heartbeat call you will need to find this out and create appropriate interfaces in your host.

    Here is a very simple implementation of what you will be building:

    [code]
    static class Program
    {
    private static Process _server = null;

    [STAThread]
    public static void Main()
    {
    RestartServer();
    while (true)
    {
    Thread.Sleep(TimeSpan.FromMinutes(10));
    if (_server.HasExited
    || !_server.Responding
    || !HeartBeat())
    {
    RestartServer();
    }
    }

    }

    public static void RestartServer()
    {
    if (_server != null && !_server.HasExited) _server.Kill();
    _server = Process.Start("TheEvilServer.exe");
    }

    public static bool HeartBeat()
    {
    // Code here to check responsiveness
    return true;
    }
    }

    [/code]

    You are basically taking ownership of the running process of the server here and monitoring it's status every 10 minutes.
    If your server has stoped responding, crashed or exited, or does not respond to a heartbeat - then it will be forcibly restarted.

    ><//~Psightoplasm`~
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    Sorry - forgot what forum this was. Here that is in VB:
    [code]
    Module Module1
    Dim _server As Process = Nothing

    Sub Main()
    RestartServer()
    While (True)
    Threading.Thread.Sleep(TimeSpan.FromMinutes(10));
    If (_server.HasExited Or Not _server.Responding Or Not HeartBeat()) Then
    RestartServer()
    End If
    End While
    End Sub

    Sub RestartServer()
    If (Not _server Is Nothing and Not _server.HasExited)
    _server.Kill()
    End If
    _server = Process.Start("TheEvilServer.exe")

    End Sub

    Function HeartBeat() As Boolean
    ' Code here for checking responsiveness
    Return True;
    End Function

    End Module

    [/code]
    ><//~Psightoplasm`~
«1
Sign In or Register to comment.