Building an initscript with start stop and restart

I have made the following init script with name code:
# chkconfig: 3 99 99
# description: code
PORT=$(awk -F= '/^PORT=/{print $2}' /root/
FLOCK_APPS_CONFIG=$(awk -F= '/^FLOCK_APPS_CONFIG=/{print $2}' /root/
cd /root/flock-snippets/

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

Rohit BajajAsked:
Who is Participating?

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

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"
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:

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

From novice to tech pro — start learning today.