Link to home
Start Free TrialLog in
Avatar of arvind
arvindFlag for India

asked on

Daemon script

I had created one Daemon script on Linux..Now I would like to port this daemon script to SunOS 5.8(Intel/Sparc. In linux there is a command called Daemon but in Solaris thereis no such command. Why I'm asking this question as I faced following problems:
[1] started my program(java based)with nohup but after closing telnet session program got killed * user run program thru SU.
[2] Started program with & (background) again same case after closing telnet program got killed.

User shell is ksh so I would like to run my program as daemon in Soaris. So if user session killed my program will not affected. Here are the linux init script which I like to convert in soalris:

################################
###
### (Make sure #!/bin/sh is the first line of the file and the file
### has execute permissions for root.) ################################
#!/bin/sh

# Source function library.
. /etc/rc.d/init.d/functions

#SET THE FOLLOWING LINE TO YOUR JAVA_HOME
export JAVA_HOME=/usr/java/bin

#SET THE FOLLOWING LINE TO YOUR CORRECT MMP_HOME
export MMP_HOME=/usr/local/mmp

export PATH=$PATH:$MMP_HOME/server:$JAVA_HOME/bin:$JAVA_HOME/jre/bin

#IF YOU NEED SPECIAL CLASSES IN YOUR CLASSPATH
#AT STARTUP, ADD THEM TO YOUR CLASSPATH HERE
#export CLASSPATH=

RETVAL=0

# See how we were called.
case "$1" in
start)
cd $MMP_HOME/server
echo -n "Starting MMP daemon: " 
daemon $MMP_HOME/server/startserver.sh
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mmp
;;
stop)
echo -n "Stopping MMP daemon: " 
killproc mmp
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mmp
;;
restart)
echo -n "Restarting MMP daemon: " 
$0 stop
sleep 2
$0 start
;;
esac


########### Anybody can help me ################
Avatar of Nery
Nery

Are you sure you program got killed ?
When you start a script(called a.sh, i.e),in background,
you can´t see you a.sh anymore. You´ll see the all the commands inside the script a.sh.

Try this: start your script again, and write down, the process number and after close your conection, login again and issue the folowing command: ps -fe | grep xxxx
(xxx is the number of process you wrote down).

Probably your process still running.


Something like this:

nohup a.sh &
5458     <<<----- (process number)

exit

After login again...
ps -fe | grep 5458

Bye


 
Avatar of arvind

ASKER

Hi nery,

You are very right but I'd tested previously. script got killed after logout... May be some restriction(security policy) on system side...This is the reason I would like init script which we will run as SU ..
The sample script that you provided above, makes a call to another script named startserver.sh.  What is going on in that script?  That is the script starting the java program, right?  Can you show us the line of code used to run the java program?  

I think that the problem is that when you invoke java, you will need to redirect /dev/null to stdin, and redirect stdout and stderr into a disk logfile, and put the process in the background (all in the same command).  

Something like this, assuming we are already in the correct application directory, and that the PATH, JAVA_HOME, and CLASSPATH variables are set and valid:

  cp /dev/null app_stdin.txt
  java com.domain.App.ClassName < app_stdin.txt 1>> app_stdout.log 2>> app_stderr.log &

Does this help?

Hello,

I have had a very difficult time putting a few jobs in the background.  This is what I have tried to resolve the problem.


One job calls another job from the background.  ie <go> calls <a> in the background.

1) ./go scri
        #!/bin/ksh
       
        ./a &

where a is your program startup scricpt.


2) start the jobs with at

ie:  at now
      >/export/home/BIG_DOG/a
      >{CNTRL-D}

This will definately put the job in the backgound, and will stay running when you exit your session.

The realy problem is that your job is being forked to PID 1. (This is a guess)
arvind, please maintain this question.

SpideyMod
Community Support Moderator @Experts Exchange
Avatar of arvind

ASKER

Tried this but not working -- same daemon script are working on development system -- but on production system
arvind,
Thanks for returning to clarify to the experts.  If no responses in a couple of weeks, feel free to request a refund in the Community Support area.

SpideyMod
Community Support Moderator @Experts Exchange
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial