LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   trying to mix jboss4 stop and start to one script <BASH> (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-mix-jboss4-stop-and-start-to-one-script-bash-4175503400/)

apss_evaluator 04-29-2014 10:24 PM

trying to mix jboss4 stop and start to one script <BASH>
 
1 Attachment(s)
Hi scripters,

I was trying to mix up 2 script files(start/stop.sh) to one. I'm just new to this stuff and has been experimenting since yesterday. Can you guys help me on what I missed.

the script goes with this:
* reports current PID
* stop jboss once it got the PID
* mv logs as backup # mv log log.$(date +%d%m%Y).$(date +%R:%S)
* start jboss
* reports its new PID

attached here is the newbie script

apss_evaluator 04-29-2014 10:26 PM

Quote:

Originally Posted by apss_evaluator (Post 5161645)
Hi scripters,

I was trying to mix up 2 script files(start/stop.sh) to one. I'm just new to this stuff and has been experimenting since yesterday. Can you guys help me on what I missed.

the script goes with this:
* reports current PID
* stop jboss once it got the PID
* mv logs as backup
* start jboss
* reports its new PID

attached here is the newbie script

seems my attachment is too messy, let me just paste it here

APP=jboss
APP_PAT='program.name=run.sh'
CARRIER=sarisari
MyStatus()
{
PID=`/bin/ps auxww | /bin/grep "${APP_PAT}" | /bin/grep "${CARRIER}" | /bin/grep -v grep | /bin/awk '{print $2}'`
if [ -z $PID ]; then
PID=0
fi
}

loop_status()
{
sleep 2
for i in 1 2 3 4 5 6 7 8 9; do
MyStatus
if [ "$PID" -eq "0" ]; then
echo "- stopped"
exit 0
fi
sleep 2
done
}

echo -n "Checking ${APP} for ${CARRIER} "
MyStatus
if [ "$PID" -eq "0" ]; then
echo "- not running"
exit 0
fi
echo ""
echo "Stopping ${APP} for ${CARRIER} (running with pid $PID)"
cd /opt/msp/pkg; ./jboss-${CARRIER}.init stop
loop_status
echo "- Still running"
echo "Issuing kill -9"
kill -9 $PID
loop_status
echo "jboss was killed moving log folder now"
mv /opt/msp/pkg/jboss-${CARRIER}/server/default/log log.$(date +%d%m%Y).$(date +%R:%S)
# Start Jboss4
sleep 3
echo "Starting ${APP} for ${CARRIER}"
cd /opt/msp/pkg; ./jboss-${CARRIER}.init start
echo "${APP} for ${CARRIER} (is now running with pid $PID)"
# End of Start script


All times are GMT -5. The time now is 06:19 AM.