Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Process dies when launched in system startup script Post 302834481 by carpannav on Friday 19th of July 2013 04:53:27 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 06:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy