How to prevent child process from receiving INT signal?

Discussion in 'Ruby' started by Collin Vandyck, Sep 12, 2007.

  1. Hello

    I'm a bit new to Ruby, and I'm trying to set up a tomcat control script.
    The main loop of the control script will allow the user to start, stop,
    and configure various instances of Tomcat.

    In this scenario, if a user wishes to start a tomcat instance, he/she
    will type:

    % start 8080

    The script then will execute:

    command = "8080/bin/catalina.sh start"
    system command

    And then the catalina.sh script will then execute some java [options...]
    & in the background.

    The control is then returned to the main program loop. This works well.
    However, any CTRL-C that the main Ruby control loop receives is always
    propagated to the java process that is in the background, shutting down
    all of the servers that I have started using this script. I can't seem
    to control this propagation. I've added:

    trap("INT") {
    puts "Interrupt caught.."
    }

    Which works, but the interrupt still makes its way out to my child
    processes. Is there any way that I can have these programs continue to
    execute in the background?

    Thanks for any help.
    --
    Posted via http://www.ruby-forum.com/.
     
    Collin Vandyck, Sep 12, 2007
    #1
    1. Advertising

  2. I created a small code example that reproduces this:

    #!/usr/bin/env ruby

    def start(server)
    return if not server
    pwd = Dir.pwd
    command = "/usr/bin/java "
    command+=
    "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager "
    command+=
    "-Djava.util.logging.config.file=#{pwd}/#{server}/conf/logging.properties
    "
    command+= "-Djava.endorsed.dirs=#{pwd}/#{server}/common/endorsed "
    command+= "-Dcatalina.base=#{pwd}/#{server} "
    command+= "-Dcatalina.home=#{pwd}/#{server} "
    command+= "-Djava.io.tmpdir=#{pwd}/#{server}/temp "
    command+= "-classpath
    :#{pwd}/#{server}/bin/bootstrap.jar:#{pwd}/#{server}/bin/commons-logging-api.jar
    "
    command+= "-Xmx300m "
    command+= "org.apache.catalina.startup.Bootstrap "
    command+= "start "
    command+= ">> #{pwd}/#{server}/logs/catalina.out 2>&1 & "

    puts command
    pid = fork do
    Signal.trap('HUP', 'IGNORE')
    Signal.trap('INT', 'IGNORE')
    exec command
    end
    Process.detach(pid)
    end


    start 8080
    loop do
    puts "hi"
    sleep 1
    end

    After Tomcat is started, the console starts outputting "hi" every
    second. A CTRL-C will kill the loop and the tomcat process. Is it
    possible that the Tomcat process is also reading from STDIN? I have
    also tried trapping the INT signal on the parent process with no luck
    (the Tomcat process quits, but the main process does not)





    --
    Posted via http://www.ruby-forum.com/.
     
    Collin Vandyck, Sep 12, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,219
    Martien Verbruggen
    Jun 27, 2003
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,130
    David Schwartz
    Dec 9, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,646
    Old Wolf
    Jan 20, 2004
  4. Teresa
    Replies:
    2
    Views:
    650
    Rob Thorpe
    Apr 6, 2004
  5. Z W
    Replies:
    0
    Views:
    174
Loading...

Share This Page