LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   Start/Stop/Status init scripts (https://www.linuxquestions.org/questions/solaris-opensolaris-20/start-stop-status-init-scripts-677075/)

Rocket2DMn 10-17-2008 08:51 AM

Start/Stop/Status init scripts
 
I am writing a custom legacy init script in Solaris 10 for testing purposes, which will be executing a dummy java program called SocketEcho. The problem is, I do not know how to stop the program correctly.
"pidof" is not available (from what I can tell).

I will start the program with
Code:

/opt/SocketEcho/SocketEcho
That SocketEcho script simply runs
Code:

java SochetEcho
in that same directory which has the class file. This works fine when executed manually (will test script functionality later), then I send it to the background.

Now I have to stop the program with
Code:

/etc/init.d/solarisSocketEcho stop
When running
Code:

ps -ef | grep SocketEcho
I see the process listed as
Code:

java SochetEcho
Since pidof is not available, I have tried using pkill, but
Code:

pkill "java SocketEcho"
does not seem to be doing anything, so I have to bring the program to the foreground and ctrl-c. Simply using the ps command, cutting the PID and running it through kill is not really an acceptable solution as this does not carry over well to other scripts. I'm hoping somebody here has a better idea or knows what I am doing wrong. Thanks in advance.

stuart_cherrington 10-17-2008 09:13 AM

OK, you can't enclose the pkill argument with "quotes". to use pkill to stop the "SocketEcho" script you need to to "pkill -f SocketEcho". Obviously as root, if you did a pkill java this would stop the last java process that ran, which may not be what you want. but as you'll probably only have one SocketEcho running this will pattern match for it and stop the ID.

As the /etc/init.d/SocketEcho stop, this will only work if the /etc/init.d/SocketEcho script contains a 'stop' flag. You can put my above pkill -f... command in the 'stop' section of the init.d script so the process can be stopped upon reboot.

Cheers,

Stuart

Rocket2DMn 10-17-2008 09:26 AM

Ah, I thought I had tried that, but I guess I was doing something wrong before (or that I had misunderstood the -f option). I was skeptical of using quotes, but since my efforts to stop the program by passing SocketEcho had failed, that's all I had to run with.

That seems to have done the trick, thank you.


All times are GMT -5. The time now is 08:31 PM.