server.rb with a Manager and Job Class?

  • Thread starter Christopher Aldridge
  • Start date
C

Christopher Aldridge

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
 
K

Konstantin Levinski

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:
 
C

Christopher Aldridge

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
 
E

Eric Hodel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top