-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check if server is already running? #60
Comments
I'm going to rewrite this section of code https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/Program.cs#L54 to use a lock file instead of a mutex as mutex doesn't work on Mono (without setting an environment variable see http://www.mono-project.com/Release_Notes_Mono_2.8#Shared_handles_are_disabled_by_default). It will then be a simple case of checking for the lockfile. Expect that to be done tonight (GMT) |
I just committed a fix for this. A lockfile is created with name "lockfile-" + port in the exe folder when the server is running. It is deleted when the stop server command is ran or ctrl-c is pressed. It isn't deleted when the process is aborted. The server has an exclusive lock on the file, so ideally to detect if it is running you should check for the existence of the file and also attempt to read it. |
It seems as if there is no lock file present when I run the server. |
The code to create the lockfile is here https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/Program.cs#L60. It gets created in the same location as OmniSharp.exe for me. |
Thanks for your reply. It appears I had to pull the new server subrepo manually, my mistake :). Having done so, I indeed get a lockfile at the pointed location. |
The lockfile is now checked correctly. The only thing that's left to do is the automatic call of the :stop server" function. Ideally the server is stopped when the last vim instance is closed. I don't think it is reasonably possible to do so without using external, os specific, commands. http://stackoverflow.com/questions/16798740/call-function-when-last-vim-instance-is-closing I will prompt the user instead, which I just implemented. |
The bug in #68 is related to this issue. |
Your code works as designed ( I think ) on Windows. Haven't been able to produce a scenario where 2 instances of the server are started. |
If I start the server (my fork) and run To check the correctness of my code, the little function |
I get 1 when I run that command. I guess file locking works differently on linux 😕 |
:( Too bad. I think my PR would work for windows users, but I haven't tested on windows. However, the merge should be postponed until the file locking works on linux too. |
Maybe this helps? http://cs.potsdam.edu/cgi-bin/man/man2html?1+mono Try setting environment variable MONO_STRICT_IO_EMULATION. Not near my linux machine to test, I'm afraid. If it works, it should be possible to set that from within the application server. |
Maybe something like this http://duplicati.googlecode.com/svn-history/r980/trunk/thirdparty/UnixSupport/File.cs is needed for Unix support. |
Looks good! Could that be pasted into Omnisharp straight? |
I guess so. Looks like it just needs a reference to Mono.Unix. Currently downloading a linux ISO so I can run some tests on linux when I'm away from home. Going slooowly though. |
I added the lock code mentioned above here OmniSharp/omnisharp-server@c0d0f4b but it just doesn't work and I'm ready to give up with it. I think that on linux the best way of doing this would be to grep the output of 'ps ef'. I'm closing this issue now but we continue this on #68 |
Proposal. Wouldn't it be neat to do the following? To check if the server is running, we can just send a request. If the request is properly answered, we know it is properly running, and otherwise not. I think this way is better than the way we do it now. Also it is going to be more compatible with multiple instances of omnisharp for multiple projects, even if they are started without providing the |
Any opinions about this? |
Seems like it would be ok so long as the exception comes back fast enough. |
Title explains. I want the check if the server is already running, before starting it.
The text was updated successfully, but these errors were encountered: