brandentanga / tastynoodles

A simple webserver written in Ruby
MIT License
1 stars 0 forks source link

tastynoodles stop fails when pid in PID file doesn't match any running process. #1

Open brandentanga opened 10 years ago

brandentanga commented 10 years ago

See below when sending a stop command through the script.

brandentanga tastynoodles$ tasty stop
./tastynoodles.rb:62:in `kill': No such process (Errno::ESRCH)
    from ./tastynoodles.rb:62:in `stop'
    from ./tastynoodles.rb:72:in `<main>'
brandentanga tastynoodles$ ls
LICENSE.txt     README.txt      status          tastynoodles.tmproj
PID         source_me.txt       tastynoodles.rb
brandentanga tastynoodles$ ps aux | grep tasty
brandentanga    6001   0.0  0.0  2434892    548 s000  S+    1:42AM   0:00.00 grep tasty
brandentanga    4942   0.0  0.0  2468412   1244   ??  S    12:55AM   0:00.00 ruby ./tastynoodles.rb start
brandentanga tastynoodles$ tasty kill -9 4942

This is the section of code where the failure occurs

def read_pid
  pid = -1
  begin
    pid = File.read("./PID")
  rescue Exception => e
    my_puts "read_pid failed, error message is: #{e.message}"
  end
  return pid
end

Notice that the exception never gets called.

brandentanga commented 10 years ago

The section of code above is wrong. The server reads the pid file, but errors when sending the kill signal.