Skip site navigation (1)Skip section navigation (2)
Date:      04 Dec 2001 18:19:23 +0100
From:      =?ISO-8859-1?Q?S=F8ren?= Neigaard <neigaard@e-box.dk>
To:        jconner@enterit.com
Cc:        freebsd-questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: How to make a start/stop/restart script
Message-ID:  <1007486364.2236.11.camel@lapdancer.dk>
In-Reply-To: <200111271313.AA4194478@enterit.com>
References:  <200111271313.AA4194478@enterit.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Looong time, no time :) But now I have the time to work with this again.

I tried to fool around on my Linux box, but I cant seem to understand
this ps|grep thing. Sometimes when I do a "ps -aux" I get some Java
processes with the string "mailsmsgateway" in them, but if I do a "ps
-aux|grep mailsmsgateway" I get nothing?? Why?

/S=F8ren

On Tue, 2001-11-27 at 19:13, jconner wrote:
>=20
> ---------- Original Message ----------------------------------
> From: S=F8ren Neigaard <neigaard@e-box.dk>
> Date: 27 Nov 2001 18:57:11 +0100
>=20
> >Sorry for the offtopic mail, but I know you guys know the answer :)
>=20
> This isn't really off-topic :)
>=20
> >
> >How do I make a script that can start/stop/restart a Java process?
> >Somting about probing the process string, but how do I do it!?
> >
> >It has to work on both Unix and Linux too :)
>=20
> I won't go into the specifics of it but it is not that difficult to do.  =
Your questions more like you're interested in knowing how to kill the proce=
ss vs starting the process.  The other thing is that you are wanting it to =
work on multiple *nix boxen which means a lil bit more work (but not much).
>=20
> First, you need to learn case...esac statements.
>=20
> case $1 in
>    start) do something here;;
>    stop)  do something here;;
>    *) default message (usually an echo to STDOUT for usage)
> esac
>=20
> You will also want to use the case..esac statement for the multiple OS's.=
..
>=20
> case $(uname -s) in
>    FreeBSD) psargs=3D"u $LOGNAME";;
>    SunOS)   psargs=3D"-f -u $LOGNAME"
>    *) exit 10;;
> esac
>=20
> Once that is set then in you stop) section of the first case statement yo=
u can call the ps with the $psargs set in the second case statement.
>=20
> Here, let me wrap this up with a small example using what I have up there=
.
>=20
> <code>
> # Start/Stop script (simple and unfinished)
> # Example by Jim Conner (MJ, TN;CHT, NC;LA, CA)
>=20
> funcUsage() {
>     echo "ERROR: $1"
>     cat << EOM
> Usage: $shProgName [start|stop|etc etc]"
>=20
> explanation
> EOM
> }
>=20
> service=3D"/usr/sbin/somebinary"
> config=3D"/etc/someconfig"
>=20
> case $(uname -s) in
>    FreeBSD) psargs=3D"u $LOGNAME";;
>    SunOS)   psargs=3D"-f -u $LOGNAME";;
>    *) exit 10;;
> esac
>=20
> case $1 in
>    start) [ ! -x $service ] && funcUsage "Can't find $service or its not =
executable";;
>    stop)  pid=3D$(ps $psargs | \
>           grep $(basename $service) | \
>           grep -v grep | \
>           awk '{print $2}') # usually the second field, season to taste
>=20
>           kill -9 $pid;;
>    *) funcUsage " Unknown command: $1"
> esac
>=20
> </code>
>=20
> This code is NOT complete nor is it tested but it gives a simple idea abo=
ut what to do (I hope).  Check out the other run scripts in /usr/local/etc/=
rc.d/.  Those may have some healthy ideas.
>=20
> - Jim
>    stop)  ps $psargs | grep -v ;;
>=20
> >--=20
> >..............................
> >Med venlig hilsen/Best regards
> >S=F8ren Neigaard
> >Registered Linux User #239437
> >
> >
> >To Unsubscribe: send mail to majordomo@FreeBSD.org
> >with "unsubscribe freebsd-questions" in the body of the message
> >
>=20
>=20
--=20
..............................
Med venlig hilsen/Best regards
S=F8ren Neigaard
Registered Linux User #239437


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1007486364.2236.11.camel>