diff options
| author | f1ori <f1ori@6c8d7289-2bf4-0310-a012-ef5d649a1542> | 2008-08-10 15:26:13 +0000 |
|---|---|---|
| committer | f1ori <f1ori@6c8d7289-2bf4-0310-a012-ef5d649a1542> | 2008-08-10 15:26:13 +0000 |
| commit | c2d49cc01e7726e853070858b95ee9ca013fb4fb (patch) | |
| tree | b48005e5459a56223686e8624d2b1b1ec4f8aceb /addon/yacyInit.m4 | |
| parent | 6a550c64f170a56a98ce684161ba9751b26638f8 (diff) | |
* add build target "deb" to create debian packages from svn
still needs testing...
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5051 6c8d7289-2bf4-0310-a012-ef5d649a1542
Diffstat (limited to 'addon/yacyInit.m4')
| -rw-r--r-- | addon/yacyInit.m4 | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/addon/yacyInit.m4 b/addon/yacyInit.m4 new file mode 100644 index 000000000..630f44ae0 --- /dev/null +++ b/addon/yacyInit.m4 @@ -0,0 +1,289 @@ +dnl automatically generate initscripts for different distros +dnl by Florian Richter <Florian_Richter@gmx.de> +dnl +define(helptext, `Usage: + m4 -DopenSUSE yacyInit.m4 > yacy.init.openSUSE +or: m4 -DDebian yacyInit.m4 > yacy.init.Debian +or: m4 -DFedora yacyInit.m4 > yacy.init.Fedora +or: m4 -DArchLinux yacyInit.m4 > yacy.init.ArchLinux +')dnl +ifdef(`openSUSE',, ifdef(`ArchLinux',, ifdef(`Fedora',, ifdef(`Debian',,````errprint(helptext())m4exit(0)''''))))dnl +#!/bin/bash +# +# init script for YaCy +# +# Provided by Matthias Kempka, 26.12.2004 +# Updated by Florian Richter, 17.7.2008 +# +ifdef(`Fedora', ` +# chkconfig: - 20 80 +# description: Distributed web search engine +')dnl +### BEGIN INIT INFO +# Provides: yacy +# Required-Start: $network +# Required-Stop: $network +# Default-Start: 3 5 +# Default-Stop: +# Short-Description: Distributed web search engine +# Description: yacy is a distributed search engine +# config-file is /etc/yacy/yacy.conf +### END INIT INFO + +NAME="yacy" +DESC="YaCy P2P Web Search" +YACY_HOME="/usr/share/yacy" +DATA_HOME="/var/lib/yacy" +PID_FILE="/var/run/yacy.pid" +USER=yacy + + +# Set this to the maximum number of seconds the script should try to shutdown +# yacy. You might want to increase this on slower peers or for bigger +# databases. +SHUTDOWN_TIMEOUT=50 + +# Default niceness if not set in config file +NICE_VAL=0 + +ifdef(`openSUSE', `dnl +. /etc/rc.status +rc_reset + +')dnl +ifdef(`ArchLinux', `dnl +[ -f /etc/profile.d/jre.sh ] && . /etc/profile.d/jre.sh + +[ -f /etc/conf.d/yacy ] && . /etc/conf.d/yacy + +. /etc/rc.conf +. /etc/rc.d/functions + +')dnl +ifdef(`Fedora', `dnl +# Source function library. +. /etc/rc.d/init.d/functions + +[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME +')dnl +if [ "$(id -u)" != "0" ] ; then + echo "please run this script as root!" + exit 4 +fi + +JAVA=$(which java 2> /dev/null) +if [ ! -x "$JAVA" ]; then + echo "The 'java' command is not executable." + echo "Either you have not installed java or it is not in your PATH" + if [ $1 == "stop" -a $2 == "--force" ]; then exit 0; else exit 1; fi +fi + +cd $YACY_HOME + +JAVA_ARGS="-Djava.awt.headless=true" +#get javastart args +if [ -f DATA/SETTINGS/yacy.conf ] +then + # startup memory + for i in Xmx Xms; do + j=$(grep javastart_$i DATA/SETTINGS/yacy.conf | sed 's/^[^=]*=//'); + if [ -n $j ]; then JAVA_ARGS="-$j $JAVA_ARGS"; fi; + done + + # Priority + j=$(grep javastart_priority DATA/SETTINGS/yacy.conf | sed 's/^[^=]*=//'); + + if [ ! -z "$j" ];then + if [ -n $j ]; then NICE_VAL=$j; fi; + fi + +fi + +# generating the proper classpath +CP=/usr/share/java/yacy.jar:$YACY_HOME/htroot +for name in /usr/share/java/yacy/*.jar; do + CP=$CP:$name +done +ifdef(`Debian', ` +#CP="$CP:/usr/share/java/javatar.jar" +#CP="$CP:/usr/share/java/commons-httpclient.jar" +#CP="$CP:/usr/share/java/commons-logging.jar" +#CP="$CP:/usr/share/java/commons-codec.jar" +#CP="$CP:/usr/share/java/commons-discovery.jar" +#CP="$CP:/usr/share/java/pdfbox.jar" +#CP="$CP:/usr/share/java/jakarta-poi.jar" +#CP="$CP:/usr/share/java/oro.jar" +#CP="$CP:/usr/share/java/xerces.jar" +#CP="$CP:/usr/share/java/jsch.jar" +')dnl +CLASSPATH=$CP + +if [ -f $PID_FILE ]; then + pid=$(cat "$PID_FILE") + pidno=$( ps ax | grep "$pid" | awk '{ print $1 }' | grep "$pid" ) +fi + +RETVAL=0 +case "$1" in + start) + if [ -n "$pidno" ]; then + echo "already running" + exit 0 + fi +ifdef(`openSUSE', ` + echo -n "Starting $DESC. " +')dnl +ifdef(`Debian', ` + echo -n "Starting $DESC: " +')dnl +ifdef(`Fedora', ` + echo -n "Starting $DESC: " +')dnl +ifdef(`ArchLinux', ` + stat_busy "Starting YaCy Daemon" +')dnl + ARGS="$JAVA_ARGS -classpath $CLASSPATH yacy" +define(`START_YACY_WITH_START_STOP_DAEMON',` + start-stop-daemon --start --background --make-pidfile --chuid $USER\ + --pidfile $PID_FILE --chdir $YACY_HOME --startas $JAVA\ + --nicelevel $NICE_VAL\ + -- $ARGS +')dnl +define(`START_YACY_WITH_SUDO', ` + cmdline="$JAVA $ARGS" + nice -$NICE_VAL sudo -u yacy $cmdline &>/dev/null & + echo $! >$PID_FILE +')dnl +ifdef(`ArchLinux', `START_YACY_WITH_SUDO()')dnl +ifdef(`openSUSE', `START_YACY_WITH_SUDO()')dnl +ifdef(`Fedora', `START_YACY_WITH_SUDO()')dnl +ifdef(`Debian', `START_YACY_WITH_START_STOP_DAEMON()')dnl + sleep 1 + ps ax|grep "^ *$(cat $PID_FILE)" > /dev/null + if [ "$?" == "0" ]; then +ifdef(`Debian', ` + echo "$NAME." +')dnl +ifdef(`Fedora', ` + echo +')dnl +ifdef(`openSUSE', ` + rc_status -v +')dnl +ifdef(`ArchLinux', ` + add_daemon yacy + stat_done +')dnl + RETVAL=0 + else +ifdef(`Debian', ` + echo "failed." +')dnl +ifdef(`Fedora', ` + echo +')dnl +ifdef(`openSUSE', ` + rc_failed + rc_status -v +')dnl +ifdef(`ArchLinux', ` + stat_fail +')dnl + RETVAL=1 + fi + ;; + + stop) + if [ -n "$pidno" ]; then +ifdef(`openSUSE', ` + echo -n "Shutting down $DESC: " +')dnl +ifdef(`Debian', ` + echo -n "Stopping $DESC: " +')dnl +ifdef(`Fedora', ` + echo -n "Stopping $DESC: " +')dnl +ifdef(`ArchLinux', ` + stat_busy "Stopping YaCy Daemon" +')dnl + cd $YACY_HOME + cmdline="$JAVA $JAVA_ARGS -cp $CLASSPATH yacy -shutdown" + sudo -u yacy $cmdline &>/dev/null & + shutdown_pid=$! + + timeout=$SHUTDOWN_TIMEOUT + while [ -n "$pidno" ]; do + let timeout=$timeout-1 + if [ $timeout -eq 0 ]; then +define(`KILL_YACY_WITH_START_STOP_DAEMON',`dnl + start-stop-daemon --stop --pidfile $PID_FILE --oknodo +')dnl +define(`KILL_YACY_WITH_SUDO', `dnl + kill -9 $pid &>/dev/null +')dnl +ifdef(`ArchLinux', KILL_YACY_WITH_SUDO())dnl +ifdef(`openSUSE', `KILL_YACY_WITH_SUDO()')dnl +ifdef(`Fedora', `KILL_YACY_WITH_SUDO()')dnl +ifdef(`Debian', `KILL_YACY_WITH_START_STOP_DAEMON()')dnl + # dont forget to kill shutdown process if necessary + shutdown_pid=$( ps ax | grep $shutdown_pid | awk '{ print $1 }' | grep $shutdown_pid ) + if [ -n "$shutdown_pid" ] ; then + kill -9 $shutdown_pid + fi + break + fi + echo -n "." + sleep 1 + pidno=$( ps ax | grep $pid | awk '{ print $1 }' | grep $pid ) + done + rm $PID_FILE + cd - >/dev/null +ifdef(`Debian', ` + echo "$NAME." +')dnl +ifdef(`Fedora', ` + echo +')dnl +ifdef(`openSUSE', ` + rc_status -v +')dnl +ifdef(`ArchLinux', ` + rm_daemon yacy + stat_done +')dnl + exit 0 + fi + echo "not running." + ;; + + restart) + $0 stop + sleep 1 + $0 start + ;; + reload) + $0 restart + ;; + status) + # needed by Fedora + if [ -n "$pidno" ]; then + echo "is running." + exit 0 + else + if [ -f $PID_FILE ]; then + echo "is dead, but pid file exists." + exit 1 + else + echo "is not running." + exit 3 + fi + fi + ;; + *) + echo "Usage: $0 {start|stop|restart}" >&2 + exit 1 + ;; +esac + +exit $RETVAL |
