Server.rb with a Manager and Job Class?

(Christopher Aldridge) #1

all, I couldnt get this to work so I'm hoping that someone can offer
assistance..

I've got ~ 9 XP machines that run server.rb from
\\sambaserver\server.rb (for example)

When I make changes to \\sambaserver\server.rb, I'd like to tell the
clients to restart server.rb.

Initally, I figured I could do it as such
##forgive sytax as I can't see my original code from here..

//------------------------server-------------------------//
class server
     def handle_job
          puts "doing what server should do day to day"
     end

     def manage_server
          puts "shutting down server"
          IO.popen("start server.rb") ##opens new dos prompt
          drb_stop_service ##kills this drb service (or should)
     end
end

sleep 10 #### to allow this process to die, and free up the listening port
DRb.start_service ## for class server
//------------------------/server------------------------//

What seems to happen, is netstat displays a persistant established
session to the server port until the new server (opened with start)
exists with a drb error stating it cant bind to the listening port,
(due to the fact that the parent server.rb is utilizing it)

Any way around this? I'd really like to be able to manage these
servers with out manual restarts etc.

Cheers

(Konstantin Levinski) #2

I think you can put your server thing in a bat file which looks like:
#don't know what .bat files look like anyway, but still:

···

---
label :again
start server.rb
sleep 10
goto again:
---
and make #manage_server to shutdown server.

(Eric Hodel) #3

all, I couldnt get this to work so I'm hoping that someone can offer
assistance..

I've got ~ 9 XP machines that run server.rb from
\\sambaserver\server.rb (for example)

When I make changes to \\sambaserver\server.rb, I'd like to tell the
clients to restart server.rb.

Initally, I figured I could do it as such
##forgive sytax as I can't see my original code from here..

//------------------------server-------------------------//
class server
     def handle_job
          puts "doing what server should do day to day"
     end

     def manage_server
          puts "shutting down server"
          drb_stop_service ##kills this drb service (or should)

            exec "ruby server.rb" # use rbconfig.rb to find ruby

     end
end

sleep 10 #### to allow this process to die, and free up the listening port
DRb.start_service ## for class server
//------------------------/server------------------------//

What seems to happen, is netstat displays a persistant established
session to the server port until the new server (opened with start)
exists with a drb error stating it cant bind to the listening port,
(due to the fact that the parent server.rb is utilizing it)

Any way around this? I'd really like to be able to manage these
servers with out manual restarts etc.

exec might do it on win32, but I forget. You may need to walk through all your sockets and close them before exec(). ObjectSpace will find them for you.

···

On 22 Aug 2005, at 07:06, Christopher Aldridge wrote:

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

(Christopher Aldridge) #4

Not quite the solution that worked...

I ended up with three rb files.. client, manager and server

The server listens and handles 1 of two things:
def stop
     stop_service
     exit 0
end
def job
     return "hello client, the time is Time.now(blah blah)"
end

The manager runs on the server host and does 2 things:

def stop
     ## calls the server method that stops the service
     DRb.Object.New("druby://serverhost:serverport").Stop
end
def start
     ## spawns a new server
     IO.popen("c:/server.rb")
end

The client simply does 3 things
1) calls the server and gets output
2) calls the manager who calls server.Stop
2) calls the manager and kicks off a new job

This is probably hacky but the only way I could get it to work..

What I do know and what I found most annoying:
running a ruby service that stops itself and spawns a new version of
itself, will KEEP the port open until all process and sub-process are
dead.

I hope someone can prove me wrong but this is what I noticed from
trial and error.

thx again

···

On 8/22/05, Konstantin Levinski <konstantin.levinski@gmail.com> wrote:

I think you can put your server thing in a bat file which looks like:
#don't know what .bat files look like anyway, but still:
---
label :again
start server.rb
sleep 10
goto again:
---
and make #manage_server to shutdown server.