From: mark ---- <mar...@ho...> - 2011-02-24 16:56:16
|
Hi This is a shell script I wrote to start and stop htdig when it is running on a fedora or Centos or redhat linux machine. This was not an easy script to write htdig is a very noisy program to kill from a bash script which made it very difficult to kill . Which made it very difficult to get to work with the Fedora service script system. The issue solved were kill -9 pid returning "Killed" or "terminated". You can not trap a SIGINT signal ie -9 where as you can trap a SIGTERM signal from pkill Please include this script in future releases of htdig and install it into /etc/init.d from the make install process. Best wishes Mark Adam Tkac <atkac@redhat com> Here is the script #!/bin/sh # # htdig: 345 81 35 # description: Starts and stops the htdig search engine # Source function library. . /etc/rc.d/init.d/functions ### This library is called from # See how we were called. case "$1" in start) echo -n "Starting htdig search engine : " rundig=$(pgrep rundig) # find all the process if [ -z "$rundig" ] # check that another instants of rundig is not running before then # before running rundig rundig& # rundig as a background task. fi echo "OK" ;; stop) echo -n "Stopping htdig search engine : " # Notes # ===== # this checks to see is there is a pid process number for the process say "rundig" # if there is a process it kills it off # send annoying "killed" or "terminated messages to junk bin { comand } 2>/dev/null # then the final rundig=$(pgrep rundig) # find all the process htdig=$(pgrep htdig) htmerge=$(pgrep htmerge) htnotify=$(pgrep htnotify) htfuzzy=$(pgrep htfuzzy) # check the process has a PID job number and if it does kill it quitely if [ "$rundig" ] ;then trap " $(pkill rundig | 2>/dev/null )" SIGTERM ;fi if [ "$htdig" ]; then trap " $(pkill htdig | 2>/dev/null )" SIGTERM ;fi if [ "$htmerge" ]; then trap " $(pkill htmerge | 2>/dev/null )" SIGTERM ;fi if [ "$htnotify" ]; then trap " $(pkill htnotify | 2>/dev/null)" SIGTERM ;fi if [ "$htfuzzy" ]; then trap " $(pkill htfuzzy | 2>/dev/null)" SIGTERM ;fi echo "OK" ;; #status) # echo "" #;; restart) echo -n "Restarting htdig search engine : " echo " " echo -n "Stopping htdig search engine : " rundig=$(pgrep rundig) # find all the process htdig=$(pgrep htdig) htmerge=$(pgrep htmerge) htnotify=$(pgrep htnotify) htfuzzy=$(pgrep htfuzzy) # check the process has a PID job number and if it does kill it quitely if [ "$rundig" ] ;then trap " $(pkill rundig | 2>/dev/null )" SIGTERM ;fi if [ "$htdig" ]; then trap " $(pkill htdig | 2>/dev/null )" SIGTERM ;fi if [ "$htmerge" ]; then trap " $(pkill htmerge | 2>/dev/null )" SIGTERM ;fi if [ "$htnotify" ]; then trap " $(pkill htnotify | 2>/dev/null)" SIGTERM ;fi if [ "$htfuzzy" ]; then trap " $(pkill htfuzzy | 2>/dev/null)" SIGTERM ;fi echo "OK" echo -n "Starting htdig search engine : " rundig& echo "OK" echo -n " Restart complete done." ;; *) echo "Usage: htdig search engine {start|stop|restart}" exit 1 esac |