?
Solved

Daemon script

Posted on 2003-02-20
8
Medium Priority
?
962 Views
Last Modified: 2013-12-27
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 ################
0
Comment
Question by:arvind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:Nery
ID: 7994212
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


 
0
 
LVL 5

Author Comment

by:arvind
ID: 7996561
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 ..
0
 
LVL 2

Expert Comment

by:blowfish
ID: 7997507
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?

0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Expert Comment

by:CadburyCat
ID: 8022379
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)
0
 

Expert Comment

by:SpideyMod
ID: 8209872
arvind, please maintain this question.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 5

Author Comment

by:arvind
ID: 8214634
Tried this but not working -- same daemon script are working on development system -- but on production system
0
 

Expert Comment

by:SpideyMod
ID: 8217648
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
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8375290
PAQ'd and 100 points refunded

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question