Building an initscript with start stop and restart

HI,
I have made the following init script with name code:
#!/bin/bash
# chkconfig: 3 99 99
# description: code
PATH="$PATH:/bin"
PORT=$(awk -F= '/^PORT=/{print $2}' /root/flockApps.properties)
FLOCK_APPS_CONFIG=$(awk -F= '/^FLOCK_APPS_CONFIG=/{print $2}' /root/flockApps.properties)
cd /root/flock-snippets/
mvn jetty:run -DFLOCK_APPS_CONFIG=${FLOCK_APPS_CONFIG} -DPORT=${PORT} &

Open in new window


when i do service code start. This script executes the mvn command which starts jetty.
but when i do service code stop the jetty does not stop...
I think i need to provide functions like start() and stop() and restart... Please clarify me on this

Also how do i write stop() as this will require me to kill running jetty instance :
if i type ps -ax | grep 'jett[y]'
I get two process ids. Which i need to kill.
Please help me write script for the same... how do i catch the output of the above command separate out pid and execute kill on them

Thanks
Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan SpringerCommented:
Is there a pid file?  Where is it and what is it called.  And, "ps -Af | grep jetty"
giltjrCommented:
Is there a special reason why you want to write your own instead of using one that may already be out there?  Simple google search of "jetty linux init script" turn up:

https://www.eclipse.org/jetty/documentation/current/startup-unix-service.html

https://gist.github.com/peterc/404672

Please read the comments at the bottom of the last link as there is a correct/fix to the script.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Duncan RoeSoftware DeveloperCommented:
Your script needs to process its 1st argument to determine whether it has to start, stop or restart. As you have it, it always does the same thing.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.