YvesR
YvesR

Reputation: 6222

How do I shutdown/interact a rubyw.exe started task

It looks like my google search skills are to bad, I couldn't find answers for some questions:

I call ruby tasks from a C# Service. Beside some several stuff in the service to get infos form registry, prepare tasks etc. I do finally:

      m_mProcess.StartInfo = new ProcessStartInfo { FileName = Command, Arguments = Argument, WorkingDirectory = WorkDir, CreateNoWindow = true };
      m_mProcess.Start();
      Pid = m_mProcess.Id;

Filename is "ruby.exe". I tried a lot of stuff to make it possible to send a CTRL-SIGNAL-BREAK to the started task when I stop the service (see more details here which results in a fail: Start a EXE file from a service and stop it by sending SIGBREAK).

So for now I just stop the process with Process.GetProcessById(Pid).Kill();.

This brings just one problem. I start a thin server with the ruby task which opens and listen on a tcp port. When I kill the process the port is blocked by windows by design for 2-3minutes (not sure how long exactly - and didn't find out to disable this feature).

So far for the prequel. Now to my actual issue :).

I was thinking of using rubyw.exe instead of ruby.exe and by that find any way to interact with the task. My hope is that it is possible to shutdown/stop a rubyw.exe task correctly without blocking any ports. I already changed the service to start with rubyw.exe to test any side effects or problems instead of using ruby.exe (can't find any so far, yet). But I still have to kill the process until I find a way to shutdown the process correct.

Upvotes: 1

Views: 782

Answers (1)

peter
peter

Reputation: 42192

There are probably more elaborate solutions to such a problem but i handle it simple by managing a system environmentvariable. So when i start a script i give the variable the value "running", if i want to stop it my calling program changes it to "stop". The script monitors the variable and when it finds a "stop" if closes nicely and just before quitting sets the value to "stopped" so that the calling program knows the script is indeed stopped. It's a solution that works in any environment and with any languages(s) but of course you need access to the Rubyscripts to change them.

Upvotes: 1

Related Questions