I am trying to write a script for starting tomcat server which get disassociated from the shell once the execution of the script complete. For example please see below snapshot of the screen.
bash-3.00# ./startup.sh
Using CATALINA_BASE: /opt/tomcat/6.0.32
Using CATALINA_HOME: /opt/tomcat/6.0.32
Using CATALINA_TMPDIR: /opt/tomcat/6.0.32/temp
Using JRE_HOME: /opt/jdk1.6.0_26/
Using CLASSPATH: /opt/tomcat/6.0.32/bin/bootstrap.jar
bash-3.00# ps -eaf | grep tomcat
root 4737 2945 0 02:45:53 pts/24 0:00 grep tomcat
root 4734 29777 1 02:45:42 pts/24 0:19 /opt/jdk1.6.0_26//bin/java -Djava.util.logging.config.file=/opt/tomcat/6.0.32/c
Now as you can see that once the execution of the script complete the tomcat process is associated with pts/24 till I close the shell. But what I want is that even if the shell is kept open the process should show a behavior like below
bash-3.00# ps -eaf | grep tomcat
root 13985 2945 0 22:40:13 pts/24 0:00 grep tomcat
root 13977 29777 1 22:40:01 ? 0:22 /opt/jdk1.6.0_26//bin/java -Djava.util.logging.config.file=/opt/tomcat/6.0.32//
The operating System is Solaris. The various option I used to accomplish the same are using nohup, and disown but still the process is associated with shell.
The other mechanism is to put in crontab or use svc to make the process start as system comes up i.e. daemon or we can write a small C program which forks a process and goes away.
Here please note that the process is running in background.
But I want to achieve the same using a shell or perl script. So any thought on the same will help me a lot.
Thanks in advance.
Well, you could go and do all the hard work yourself, but why when there's a module for that: Proc::Daemon (Not sure if it works on solaris)
The documentation also describes the process used, which is useful for you to understand anyhow, if you decided to go ahead and craft your own daemonizing code.
( nohup ./script.bash & )
The parenthesized sub-shell exits immediately and ps -ef |grep script.bash returns:
501 59614 1 0 0:00.00 ttys005 0:00.00 /bin/bash ./script.bash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With