[Solved] Process dies when launched in system startup script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Process dies when launched in system startup script
# 1  
Old 07-19-2013
[Solved] Process dies when launched in system startup script

Good morning!

I'm trying to add Maven to the system boot by the moment without success.
Testing the operation of the script I realize that the process isn't persistent when the program is launched with the start option.

---- #Startup Script ----
Code:
#! /bin/sh
# chkconfig: 345 99 1
# description: xxx
# processname: Application
#
. /etc/rc.d/init.d/functions

BIN="/projects/user/app/appsysv.sh start $VERSION"
PIDFILE="/projects/user/app/pid.file"
#LOG
LOGFILE="/projects/user/log/app.log"

start()
{
su - user -c "/etc/init.d/app start_internal" &
echo -n "Starting App ... "
echo
}

start_internal()
{
# Remember PID
echo $$ > $PIDFILE
# Exec application
exec $BIN >> $LOGFILE 2>&1
if [ $(cat $PIDFILE) -gt 0 ]; then
ps -p $(cat $PIDFILE) > /dev/null
        if [ $? -eq 0 ]; then
        echo "App started successfully"
        fi
fi
}

stop()
{
if [ -f ${PIDFILE} ]; then
kill $(cat $PIDFILE)
echo -n "App stopped"
echo
fi
}

case "$1" in
start)
start
;;
start_internal)
start_internal
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage $0 {start|stop|restart}"
exit 1
esac

And this is how the application is natively launched out of the system startup (the script which i'm pointing):
Code:
#!/bin/sh

#Set Maven
export M2_HOME=/opt/apache-maven-2.2.1
# Set Java environment
export JAVA_HOME=/opt/jdk1.6.0_22
PATH=$JAVA_HOME/bin:$PATH
# Oracle environment
export ORACLE_BASE=/home/oracle/app/oracle
export ORACLE_SID=db
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/client_1
export PATH=$ORACLE_HOME/bin:$PATH
source /projects/tcatnbia/app/nbis-execution/app.cfg
PIDFILE="/projects/user/app/pid.file"
start()
{dformat=`date '+%y%m%d_%H%M%S'`
 export MAVEN_OPTS="-server -Xms512m -Xmx2048m -XX:MaxPermSize=256m  -Xloggc:/projects/user/log/gc-${dformat}.log  -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7091  -Dcom.sun.management.jmxremote.authenticate=true  -Dcom.sun.management.jmxremote.password.file=app_jmxremote.password  -Dcom.sun.management.jmxremote.access.file=app_jmxremote.access  -Dcom.sun.management.jmxremote.ssl=true  -Djavax.net.ssl.keyStore=nbis_jmx_key  -Djavax.net.ssl.keyStorePassword=123456 -Duser.timezone=$TIMEZONE"
nohup mvn -e -o -Dapp.version=$1 -Dnbis.env=$ENV  -Dlocal.server.file.locn=$LOCAL_SERVER exec:java >  /projects/user/log/app-out.log 2>&1 &
}

stop()
{
if [ -f ${PIDFILE} ]; then
kill `cat $PIDFILE`
echo -n "App stopped"
echo
fi
}

case "$1" in
    start)
        start $2
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start $2
        ;;
    *)
        echo Usage:
        echo $0 'start [App_version]'
        echo 'or          restart [app_version]'
        echo 'or          stop'
        exit 1
esac
exit 0

Can anybody help to find out what's happening? When I check for the process, I find that the pid has changed in the pid.file but the process isn't running

Thank you so much.

Moderator's Comments:
Mod Comment Use code tags please, see PM.

Last edited by zaxxon; 07-19-2013 at 06:01 AM.. Reason: code tags
# 2  
Old 07-19-2013
Processes do not disappear just like that, so there has to be some abnormal program termination.

Try to start the process by hand, imitating the steps the script takes and look where it gets you. maybe there are some error messages the script would redirect to /dev/null which you will see this way. You can also check error codes and see if they are described in the programs documentation. Maybe the software produces a core dump, then you can analyse that or send it to the software's manufacturer.

I hope this helps.

bakunin
# 3  
Old 07-20-2013
Thanks for reading and replying Smilie
I've tried to manually reproduce the steps but there's no error shown (even without the output redirection)
Anyone have any advice for making the startup script work? It makes sense to launch the program with the & and the exec to make the process persistent?
Regards.
# 4  
Old 07-20-2013
Quote:
Originally Posted by carpannav
I've tried to manually reproduce the steps but there's no error shown (even without the output redirection)
OK, what about the error code?

Code:
# process_to_start
# echo $?

Is it zero? Any other value?

Quote:
Originally Posted by carpannav
It makes sense to launch the program with the & and the exec to make the process persistent?.
No. The difference between starting the process with and without the "&" is that it will be sent into background. Sending it into background will free the terminal you use for further commands, but not more.

"exec" will replace the script process with the started process. This makes sense for a startup script, which should neither end nor hang around left over after starting the process. In a debugging environment it will help you not at all because it will replace the shell process from which it where started with your programs process, effectively ending the terminal once it stops.

Looks like you will have to call tech support, which i suggest you do. A non-functional program which just exits instead of doing work is bad enough, but leaving no error message, exit code or anything hints at very sloppy (irresponsible) softare development. You might want to drop this software and use another one instead.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 07-23-2013
Hi,

Quote:
OK, what about the error code?
Code:
# process_to_start # echo $?
Yes the return value it's zero.

I didn't made the answer well...anyway I guess the combination of both in this situation makes sense.

Unfortunately I'm only the sysadmin, I cannot decide in the software development side and the support of this part isn't helping.

Finally I found where was the problem, it was in the variables charge, I needed to do:
Code:
su user -c $cmd

instead of:
Code:
su - user -c $cmd

Thanks! Smilie
# 6  
Old 07-23-2013
Thanks for the follow-up. You might want to consider making the startup script which sets the necessary environment executable for the user (instead for anybody else) and call this via su - user -c /path/to/script instead of setting the environment here (as the one user) and calling the executable there (as the other user). Personally i think it is a cleaner way to put the environment and the call of the executable together, but that might be personal preference.

Still, i stand by what i said before: if a program can't go on for some reason, that is OK, but it should tell the user so, either via a logfile entry, error message, return code or whatever. Anything else is not acceptable and programmers neglecting this rule should be made administrators of their own software for some time just to understand what they are doing. Make them analyse each and every coredump for each and every program shutdown they neglect to adorn with some diagnostic message or program action.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

[Solved] Startup script errors?

The below text is displayed on the console -> sbin/rc2.d/S130pfilboot: -l: not found. /sbin/rc2.d/S131ipfboot: -l: not found. /sbin/rc2.d/S590Rpcd: -l: not found. /sbin/rc2.d/S700acct: -l: not found. /sbin/rc2.d/S900drd: -l: not found. /sbin/rc3.d/S823hpws22_apache: -l: not found.... (4 Replies)
Discussion started by: pplayford
4 Replies

2. Shell Programming and Scripting

how to delete files at booting of system (system startup)

hi all I have a problem how to write a shell script which delete files/folder form directory whenever system boot and copy last updated folder/file in the specified directory.pse help me ASAP. i write a script which copy files in directory.I want when system boot up using script it check whether... (1 Reply)
Discussion started by: shubhig15
1 Replies

3. Shell Programming and Scripting

[Solved] File System Monitoring Script

Hello Scripts Guru I had created a shell script to monitor the threshold of the file system, but some where it is not giving the correct output. Request to all to hel me out I am getting the following output /dev/vg00/lvol3 mounted on 1865224 10% / is 2097152% /dev/vg00/lvol1 mounted on... (2 Replies)
Discussion started by: indrajit_renu
2 Replies

4. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

5. Shell Programming and Scripting

Find shell process pid launched throug `at`.

Hi. I was testing some staff and wrote simple script, which only writes date to log every 15 seconds. Like that #1.sh while true;do echo `date` >> 1.log sleep 15 done And than i ran this process with `at -s -f 1.sh now`. And now it is running and i don't know how to catch it. I tryed... (1 Reply)
Discussion started by: kukuruku
1 Replies

6. Solaris

Cron Job -- auto start process when it dies

I would like to setup a Cron job to check weather X process is running or not. if it is not running then start that X process with a log message.... can any one help writing a script? thanks (3 Replies)
Discussion started by: chandravadrevu
3 Replies

7. UNIX for Dummies Questions & Answers

Lastlog and launched process

Hello there, I "discovered" an interesting command lastlog, but I couldn't find, until now:cool:, if it's possible to get a list of the launched process by users and root during a certain of time... ...any idea would be really appreciated!!! Thanks in advance. Giordano Bruno (3 Replies)
Discussion started by: Giordano Bruno
3 Replies

8. UNIX for Advanced & Expert Users

is there a way to find out the tty from which the process is launched

Hi all, There is an application which can be launched once on our box and there are several suspected users telnet into the system with the same login ID. Is there a way that i can find out from which tty the application is launched? If so, i can get the user name from the "finger"... (1 Reply)
Discussion started by: sleepy_11
1 Replies

9. Solaris

stop a process to start at system startup

Hi all! I'm running Solaris 10 and have a question about how i can stop a certain program to start at system startup,for example, as it is now sendmail is starting but i don't need sendmail,on the other hand so would i be very glad to get cups up and running at startup, anyone who can explain where... (3 Replies)
Discussion started by: larsgk
3 Replies

10. UNIX for Dummies Questions & Answers

Process launched by user who logs out, continue running ?

Lets say a user starts a process (either a shell script or a Perl script) and before that process finishes, he logs out (either intentionaly or network problems or ...), does the process continu running ? Default shell is Korn. This is because at my job (being trained), there are tasks to run... (2 Replies)
Discussion started by: Browser_ice
2 Replies
Login or Register to Ask a Question