From 785688ef8285baf3afcaf04cd2ecf84cfd94dbe4 Mon Sep 17 00:00:00 2001 From: danielr Date: Thu, 24 Jul 2008 18:56:29 +0000 Subject: [PATCH] - creating pid-file under linux - added modified init-script (using startYACY.sh instead of doing the same thing) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5017 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- addon/yacyInit2.sh | 113 +++++++++++++++++++++++++++++++++++++++++++++ startYACY.sh | 5 +- 2 files changed, 116 insertions(+), 2 deletions(-) create mode 100755 addon/yacyInit2.sh diff --git a/addon/yacyInit2.sh b/addon/yacyInit2.sh new file mode 100755 index 000000000..493044141 --- /dev/null +++ b/addon/yacyInit2.sh @@ -0,0 +1,113 @@ +#!/bin/sh +# +# init script for the HTTP Proxy: YaCy +# +# Provided by Matthias Kempka, 26.12.2004 +# edited by Loom, 2008-07-21 + +# installation directory +DAEMON_DIR=/home/daniel/workspace/yacy +# set to the user whose rights the proxy will gain +USER=daniel +# Default niceness if not set in config file +NICE_VAL=0 + +# Set this to the maximum number of minutes the script should try to shutdown +# yacy. You might want to increase this on slower peers or for bigger +# databases. +SHUTDOWN_TIMEOUT=10 + +# Don't run if not installed +test -f $DAEMON_DIR/startYACY.sh || exit 0 + +NAME="yacy" +DESC="YaCy HTTP Proxy" +PID_FILE="yacy.pid" + + +cd $DAEMON_DIR + +if [ -f $PID_FILE ]; then + pid=$(cat "$PID_FILE") +fi + +check_process() +{ + pidno="" + if [ $pid -gt 0 ]; then + pidno=$( ps ax | grep "$pid" | awk '{ print $1 }' | grep "$pid" ) + fi +} + +# checks if yacy.running exists every 2 seconds for a minute (exits after 60 seconds) +# returns true (0) if exists +check_runningFile() +{ + iteration=0 + while [ $iteration -lt 30 ]; do + echo -n "." + iteration=$(($iteration + 1)) + sleep 2 + if [ ! -f DATA/yacy.running ]; then + return 1 + fi + done + return 0 +} + +check_process +case "$1" in + start) + if [ -n "$pidno" ]; then + echo "already running" + exit 0 + fi + echo -n "Starting $DESC: " + #./startYACY.sh 2>error.log >/dev/null + start-stop-daemon --start --verbose --pidfile $PID_FILE --nicelevel $NICE_VAL\ + --chuid $USER --chdir $DAEMON_DIR --startas ./startYACY.sh\ + -- 2>error.log + echo "$NAME." + ;; + + stop) + if [ -n "$pidno" ]; then + echo -n "Stopping $DESC: " + cd $DAEMON_DIR + ./stopYACY.sh > /dev/null + # yacy has per default a delayed shutdown by 5 seconds + sleep 6 + timeout=$SHUTDOWN_TIMEOUT + echo "waiting that YaCy has finished (killing YaCy after $timeout minutes)" + while [ -n "$pidno" ]; do + check_runningFile + timeout=$(($timeout-1)) + if [ $timeout -eq 0 ]; then + start-stop-daemon --stop --pidfile $PID_FILE --oknodo --verbose + break + fi + echo -n ":" + check_process + #pidno=$( ps ax | grep $pid | awk '{ print $1 }' | grep $pid ) + done + echo "$NAME." + cd - + exit 0 + fi + echo "not running." + ;; + + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + N=/etc/init.d/yacyInit.sh + # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $N {start|stop|restart}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/startYACY.sh b/startYACY.sh index 82e3db116..5b986aa5a 100755 --- a/startYACY.sh +++ b/startYACY.sh @@ -2,6 +2,7 @@ JAVA="`which java`" CONFIGFILE="DATA/SETTINGS/yacy.conf" LOGFILE="yacy.log" +PIDFILE="yacy.pid" OS="`uname`" #check if OS is Sun Solaris or one of the OpenSolaris distributions and use different version of id if necessary @@ -126,9 +127,9 @@ if [ $DEBUG -eq 1 ] #debug then cmdline="$JAVA $JAVA_ARGS -Djava.awt.headless=true -classpath $CLASSPATH yacy" elif [ $LOGGING -eq 1 ];then #logging - cmdline="$JAVA $JAVA_ARGS -Djava.awt.headless=true -classpath $CLASSPATH yacy >> yacy.log &" + cmdline="$JAVA $JAVA_ARGS -Djava.awt.headless=true -classpath $CLASSPATH yacy >> yacy.log & echo \$! > $PIDFILE" else - cmdline="$JAVA $JAVA_ARGS -Djava.awt.headless=true -classpath $CLASSPATH yacy >> /dev/null &" + cmdline="$JAVA $JAVA_ARGS -Djava.awt.headless=true -classpath $CLASSPATH yacy >> /dev/null & echo \$! > $PIDFILE" fi if [ $PRINTONLY -eq 1 ];then echo $cmdline