[CentOS] System V Init Script

James Bensley

jwbensley at gmail.com
Wed Jun 3 09:29:08 UTC 2009


Hey Listees,

I have a question (hopefully quite simple) about the system V init scripts
in /etc/init.d. I have an app installed and for some reason it had no system
V init script. It has been installed a long while now so I can't quite
remember whats going on but basically I remember I wrote the init script my
self and the app is enabled as a service which chkconfig to run at system
levels 3, 4 and 5. However when I wrote the script I only ever added a
"start" and "stop" clause to it (why I can't remember?), now I need to add a
"restart" clause but I'm having an issue.

I have pasted the code below from my "restart" clause but from what I can
tell, it is killing the app but not restarting it, I think because the
killing process is still in action so when it start the app again it just
gets killed straight away. If I enter "/etc/init.d/my_app restart" the app
is terminated but does not start again, entering "/etc/init.d/my_app start"
immediately after fires it up straight away so there is no problem there;
can someone suggest a better way as my scripting is very begginnerish (if
thats a word) and I don't doubt for a second I am doing this in a very
inefficient manner:

<snipety snip snip>

restart)
echo -n "Stopping my_app: "
pgrep my_app | while read PIDS; do # I have chosen this method because
my_app spawns various child processes
kill -9 $PIDS                                   # and they all need to DIE!
(Killing the parent process would kill the child processes
done                                              # however there are
actually two parent processes so this seems like a good idea?)
echo -n "Starting my_app: "
/usr/local/my_app/sbin/my_app_bin &
exit $?
;;

<snip snap snorum>


Any input is greatly appreciated!

Regards,
James ;)

-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V-
PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++
------END GEEK CODE BLOCK------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.centos.org/pipermail/centos/attachments/20090603/d60df8e9/attachment.html>


More information about the CentOS mailing list