From owner-freebsd-questions Tue Dec 4 9:21:15 2001 Delivered-To: freebsd-questions@freebsd.org Received: from fe090.worldonline.dk (fe090.worldonline.dk [212.54.64.152]) by hub.freebsd.org (Postfix) with SMTP id 7F82F37B417 for ; Tue, 4 Dec 2001 09:21:08 -0800 (PST) Received: (qmail 30561 invoked by uid 0); 4 Dec 2001 17:21:06 -0000 Received: from 213.237.13.224.adsl.hc.worldonline.dk (HELO lapdancer.dk) (213.237.13.224) by fe090.worldonline.dk with SMTP; 4 Dec 2001 17:21:06 -0000 Subject: Re: How to make a start/stop/restart script From: =?ISO-8859-1?Q?S=F8ren?= Neigaard To: jconner@enterit.com Cc: freebsd-questions In-Reply-To: <200111271313.AA4194478@enterit.com> References: <200111271313.AA4194478@enterit.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Mailer: Evolution/0.13 (Preview Release) Date: 04 Dec 2001 18:19:23 +0100 Message-Id: <1007486364.2236.11.camel@lapdancer.dk> Mime-Version: 1.0 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 > 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 > > # 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 > >=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