[Solved] MCServer Questions: Running as Service / Running in VS - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Discussion (https://forum.cuberite.org/forum-5.html) +--- Thread: [Solved] MCServer Questions: Running as Service / Running in VS (/thread-1560.html) |
[Solved] MCServer Questions: Running as Service / Running in VS - TealFrog - 08-31-2014 Hello all, I have two issues/questions that I am hoping someone may be able to assist me with.
RE: MCServer Questions: Running as Service / Running in VS - xoft - 08-31-2014 Hello, and welcome to the forum. What wrapper are you using, the Java Service Wrapper - http://sourceforge.net/projects/wrapper/ ? I don't know much about it, but I would expect that it manipulates the input stream handles somehow, which makes MCS believe that its input stream has closed, which is a signal for the server to shut down gracefully. I'd recommend using the original Microsoft tool, srvany.exe, as the wrapper; unfortunately finding a proper download is troublesome these days. Or perhaps look through the Java Service Wrapper's documentation if it says anything about the input stream, and perhaps a way to make it not close the stream. As for running from VS, you're really close. Just open the solution in VS, get the Solution Explorer window (by default docked to the left), find the MCServer project there, right-click it and select "Set as startup project". As it is, there's no way for CMake to set the startup project while it generates the solution file, and VS defaults to the first project in the solution, which unfortunately is CMake's internal housekeeping project, so it cannot be run directly. The next step is to set the Working directory, so that the server can find its stuff when it starts up. Right-click on the project once again, select Properties, and in the dialog, navigate to Configuration Properties -> Debugging in the tree on the left side, then change Working directory to "..\MCServer" (without the dblquotes). Note that if you switch to a different configuration (release / profile / ...), you'll need to do this again, or you can simply select All configurations in the Configuration combo at the top of the dialog before changing the value. That's it, now you should be able to run without any problems. I recommend one more thing - set up MS Symbol servers in order to improve the debugging accuracy. In VS, use the Tools -> Options menu, navigate the left tree to Debugging -> Symbols, make sure that Microsoft Symbol Servers is checked in the list and that the cache directory under the list is valid, select the "All modules, unless excluded" radio button and confirm the changes in the dialog. The first debugging session that you start afterwards will take quite some time to start, don't worry, it's a one-off action, VS is downloading public symbols for all the MS system DLLs that MCServer uses from MS servers, so that you get complete stack traces. It took my computer some three minutes to display the MCServer console and another three minutes for the server to start; YMMV. With the new settings, whenever you hit a breakpoint or a crash, the callstack window will have the most accurate callstack available, instead of only guessing through half the entries. RE: MCServer Questions: Running as Service / Running in VS - xoft - 08-31-2014 I have added a GitHub issue to make it more easy to start MCS as a service: https://github.com/mc-server/MCServer/issues/1360 RE: MCServer Questions: Running as Service / Running in VS - TealFrog - 08-31-2014 The wrapper I'm using is actually off of GitHub, I took a look at the Java one earlier on Source Forge and forgot that I used the one off of GitHub instead. (my mistake). GitHub winsw, http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/ I know of the srvany.exe utility and that is great suggestion. As you mentioned it is quite old. I want to say it was part of NT 4.0 resource kit and/or possibly Win2K resource kit. I probably have it some where. The GitHub, WinSw works for executables and Java. The C# source is available and I'm compiling it, so I can manipulate it as well. I'll try the suggestions and look into it a bit further. A huge thank you for both posts. RE: MCServer Questions: Running as Service / Running in VS - TealFrog - 09-01-2014 The suggestions worked. I was able to get the MCServer server to run under MSVS by changing the setting related to the startup project. I also successfully added the debugging symbols. This was a great suggestion. I am used to configuring symbols under WinDbg, but it never dawned on me to do this under MSVS, but then again most of my development has either been done by either using notepad or vi as an IDE. As far as using the wrapper to run the MCServer server as a service, the wrapper does close stdin. I added some additional C# code to keep the stream open. The MCServer server runs and I'm able to connect using the Minecraft client; however, once connected and inside the MCServer Minecraft world the world crashes with an uncaught exception and the error mentioning an invalid parameter being passed to a function. The error appears to occur with the deletion of a pointer as part of a linked list (STL) of world blocks or similar. Unless this is a bug being introduced by the wrapper, my next step will be to look at the MCServer code to have it run without the stdin console. I was sort of hoping to avoid this. For what it is worth the error is occurring in, Code: void cSetChunkData::RemoveInvalidBlockEntities(void) Code: delete *itr; I'm not a huge fan of Java (though it does have its place) and I really think that MCServer has some huge advantages being written in C++. I'm hoping that MCServer works out as I'm not crazy about the alternatives. Thanks. RE: MCServer Questions: Running as Service / Running in VS - xoft - 09-01-2014 Thanks for the good news. The iterator problem is known and a fix is pending in the pull requests, should be available later today. RE: MCServer Questions: Running as Service / Running in VS - xoft - 09-01-2014 Fix merged. [Solved] RE: MCServer Questions: Running as Service / Running in VS - TealFrog - 09-02-2014 Awesome! Using the most recent MCServer merged source there is now no more crashing. The MCServer server runs as a service using the winsw project. Hopefully, I can follow up with some details later to help others. Thanks again and taking the time to educate me a bit. RE: [Solved] MCServer Questions: Running as Service / Running in VS - TealFrog - 09-09-2014 For anyone who wishes to replicate the process and run MCServer as a service using the same method, this is how I accomplished it. This is a high level overview of the process with the required information. I am making the assumption that the person doing this is either comfortable with the steps, i.e. using GitHub, using Microsoft Visual Studio, modifying and compiling source code or is willing to seek out the information and do some research on any unfamiliar areas. Having knowledge about compiling source code, using Visual Studio, GitHub and working with Windows Services is very helpful. Anyone is capable of doing this if they have the tenacity to seek out the information on the Internet. To cover all of the details related to every requirement and individual step would probably be better suited for a Wiki article or other "how to" article. Do the following:
Code: <service> You will have to modify it based on your configuration, but it should be very similar. I have attached a .zip file that contains the service wrappper, winsw.exe and the source file, main.cs, that contains the modified C# source code. The executable is a Windows x86 33-bit requiring .Net. Best of luck. RE: [Solved] MCServer Questions: Running as Service / Running in VS - xoft - 09-09-2014 Excellent, thank you for this guide! |