Tuesday 15 March 2011

shell - how to run and stop a bash script in a init.d process? -



shell - how to run and stop a bash script in a init.d process? -

i have process script , want run , stop (if running) bash script.

i've tried pkill -x test doesn't seem work. in case believe need if statement, see if test.sh running..

edit: in stop added for inps ax | grep 'test' | awk '{print $1}'; kill -9 $i; done

that seems prepare it.. need more testing

here code:

#!/bin/bash # chkconfig: 2345 20 80 # description: description comes here.... # source function library. . /etc/init.d/functions prog="test" newline=$'\n' start() { str=$"starting $prog ${newline}" echo "$str" /var/www/html/test.sh # code start app comes here # example: daemon program_name & } stop() { str=$"stopping $prog ${newline}" echo "$str" pkill -x test # code stop app comes here # example: killproc program_name } case "$1" in start) start ;; stop) stop ;; restart) ${0} stop sleep 1 ${0} start ;; status) ;; *) echo "usage: $0 {start|stop|status|restart}" esac exit 0

any ideas?

maybe if script test.sh puts file in /var/run it's pid. can utilize variable $$ that. for process pid ps , grep in init script , killing easy.

bash shell service process init

No comments:

Post a Comment