Can a standalone ruby script (windows and mac) reload and restart itself?

Posted by user30997 on Stack Overflow See other posts from Stack Overflow or by user30997
Published on 2010-04-13T23:17:32Z Indexed on 2010/04/13 23:23 UTC
Read the original article Hit count: 340

Filed under:
|
|
|
|

I have a master-workers architecture where the number of workers is growing on a weekly basis. I can no longer be expected to ssh or remote console into each machine to kill the worker, do a source control sync, and restart. I would like to be able to have the master place a message out on the network that tells each machine to sync and restart.

That's where I hit a roadblock. If I were using any sane platform, I could just do:

exec('ruby', __FILE__)

...and be done. However, I did the following test:

p Process.pid
sleep 1
exec('ruby', __FILE__)

...and on Windows, I get one ruby instance for each call to exec. None of them die until I hit ^C on the window in question. On every platform I tried this on, it is executing the new version of the file each time, which I have verified this by making simple edits to the test script while the test marched along.

The reason I'm printing the pid is to double-check the behavior I'm seeing. On windows, I am getting a different pid with each execution - which I would expect, considering that I am seeing a new process in the task manager for each run. The mac is behaving correctly: the pid is the same for every system call and I have verified with dtrace that each run is trigging a call to the execve syscall.

So, in short, is there a way to get a windows ruby script to restart its execution so it will be running any code - including itself - that has changed during its execution? Please note that this is not a rails application, though it does use activerecord.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about reload