How to prevent child process from receiving INT signal?

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.

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)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs